Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,19 @@ jobs:
- name: Build
run: docker build --quiet --tag tests .github/docker/alpine

# Into the tree, so the cache keeps it and the container of the test copies it.
# On the runner, because the image has no gh to check the attestation. Into the tree, so the
# cache keeps it and the container of the test copies it.
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
coverage: none
tools: none

- name: Install FrankenPHP
env:
GITHUB_TOKEN: ${{ github.token }}
run: docker run --rm --env GITHUB_TOKEN --volume "$PWD:/src" --workdir /src --entrypoint php tests tests/FrankenPhp/install-frankenphp.php
run: php tests/FrankenPhp/install-frankenphp.php && test -f .frankenphp/ATTESTED

- name: Test
run: |
Expand Down Expand Up @@ -284,11 +292,19 @@ jobs:
- name: Build
run: docker build --quiet --tag tests .github/docker/debian

# Into the tree, so the cache keeps it and the container of the test copies it.
# On the runner, because the image has no gh to check the attestation. Into the tree, so the
# cache keeps it and the container of the test copies it.
- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
coverage: none
tools: none

- name: Install FrankenPHP
env:
GITHUB_TOKEN: ${{ github.token }}
run: docker run --rm --env GITHUB_TOKEN --volume "$PWD:/src" --workdir /src --entrypoint php tests tests/FrankenPhp/install-frankenphp.php
run: php tests/FrankenPhp/install-frankenphp.php && test -f .frankenphp/ATTESTED

- name: Test
run: |
Expand Down
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ composer test # Pint and Rector dry runs, PHPStan, 100% type cove
(see [Before you open a pull request](#before-you-open-a-pull-request)).
- Where `gh` has a login or a token, `frankenphp:install` also uses `gh attestation verify` to
check that FrankenPHP's workflow built the binary. A binary that fails the check is deleted.
Where `gh` has neither, the binary runs unchecked, as in the Docker jobs.
The check comes before the binary first runs. Where `gh` has neither, as in a Docker image, the
binary runs unchecked; so in CI, a Docker job installs the binary on the runner, which has `gh`.

## Reporting a bug

Expand Down
23 changes: 14 additions & 9 deletions tests/FrankenPhp/install-frankenphp.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
}

// Upstream rebuilds a release, so release.lock pins no SHA-256; the attestation shows who built the
// binary of today. Where gh cannot check, as in the Docker jobs, the binary runs unchecked until an
// install where it can; on CI, linux-arm64 runs only in Docker and stays unchecked.
// binary of today. Where gh cannot check, as in a Docker image, the binary runs unchecked until an
// install where it can; in CI, a Docker job installs it on the runner, which has gh.
$canAttest = Release::canAttest();

if ($installed && ! $canAttest) {
Expand All @@ -55,15 +55,9 @@
echo 'Download FrankenPHP '.$tag.' for '.$system.PHP_EOL;
$sha256 = Release::digests($tag)[$asset] ?? throw new RuntimeException('FrankenPHP '.$tag.' has no '.$asset.'.');
Release::download($tag, $asset, $sha256, $directory.'/frankenphp', 'the API of GitHub');
$found = Release::versionOf($directory.'/frankenphp');

if ($found !== $version) {
unlink($directory.'/frankenphp');

throw new RuntimeException('The binary of FrankenPHP '.$tag.' names '.$found.', release.lock '.$version.'. Upstream built it again with other versions: run composer frankenphp:lock.');
}
}

// The check comes before the binary runs for its versions.
if ($canAttest) {
try {
Release::attest($directory.'/frankenphp', $asset);
Expand All @@ -79,6 +73,17 @@
} else {
echo 'No gh with a login or a token: the attestation is not checked.'.PHP_EOL;
}

if (! $installed) {
$found = Release::versionOf($directory.'/frankenphp');

if ($found !== $version) {
@unlink($directory.'/ATTESTED');
unlink($directory.'/frankenphp');

throw new RuntimeException('The binary of FrankenPHP '.$tag.' names '.$found.', release.lock '.$version.'. Upstream built it again with other versions: run composer frankenphp:lock.');
}
}
} catch (RuntimeException|JsonException $exception) {
fwrite(STDERR, $exception->getMessage().PHP_EOL);

Expand Down
Loading