From 47244f0cce3d0e3280f30b4e0afc079ec9178423 Mon Sep 17 00:00:00 2001 From: stefansorge <3419073+sorge-it@users.noreply.github.com> Date: Sat, 21 Nov 2026 17:56:57 +0100 Subject: [PATCH] test: compare with the newest release of FrankenPHP, not its newest tag Upstream tagged v1.14.0 hours before its release. The checks took the tag, found no release for it and failed, so the badge on main turned red. They now take the tag of the newest release from the API. --- .github/CONTRIBUTING.md | 6 ++++-- .github/workflows/caddy.yml | 2 ++ tests/Caddy/check-caddy.php | 7 ++++--- tests/FrankenPhp/Release.php | 25 +++++++++++++++++++++++-- tests/FrankenPhp/check-frankenphp.php | 4 ++-- tests/FrankenPhp/lock-frankenphp.php | 2 +- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 1ea6c93..330b58c 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -134,8 +134,10 @@ composer frankenphp:lock # new FrankenPHP versions into release.lock, needs gh ``` - The `check:` commands need `composer install`, git and the network, but no token. `check:go` first - runs `frankenphp:install`, as the suites do. `check:go`, `check:frankenphp` and `frankenphp:lock` - also need PHP's curl extension. + runs `frankenphp:install`, as the suites do. Each `check:` command and `frankenphp:lock` also + needs PHP's curl extension. +- The newest FrankenPHP is its newest release, not its newest tag: upstream tags a version and + publishes the release hours later. - `check:frankenphp` downloads the newest FrankenPHP binary into `.frankenphp/newest` and runs it. When it finds new versions, run `composer frankenphp:lock`. It writes the versions of the newest binary into `release.lock` after `gh attestation verify` shows that FrankenPHP's workflow built diff --git a/.github/workflows/caddy.yml b/.github/workflows/caddy.yml index b6271f5..f2cd790 100644 --- a/.github/workflows/caddy.yml +++ b/.github/workflows/caddy.yml @@ -50,4 +50,6 @@ jobs: run: composer install --no-interaction --prefer-dist - name: Compare with caddy.lock and frankenphp.lock + env: + GITHUB_TOKEN: ${{ github.token }} run: composer check:caddy diff --git a/tests/Caddy/check-caddy.php b/tests/Caddy/check-caddy.php index 1adb806..69ed40f 100644 --- a/tests/Caddy/check-caddy.php +++ b/tests/Caddy/check-caddy.php @@ -3,9 +3,10 @@ declare(strict_types=1); // composer check:caddy compares caddy.lock with the newest release of Caddy, and frankenphp.lock of -// the layer of Caddy with that of FrankenPHP: a tag vX.Y.Z, without beta or rc. Another blob fails -// the check, but does not stop the next comparison. +// the layer of Caddy with that of the newest release of FrankenPHP. For Caddy, that is the newest tag +// vX.Y.Z, without beta or rc. Another blob fails the check, but does not stop the next comparison. +use SorgeIt\HttpServer\Tests\FrankenPhp\Release; use SorgeIt\HttpServer\Tests\Upstream; require __DIR__.'/../../vendor/autoload.php'; @@ -14,7 +15,7 @@ const FRANKENPHP = 'https://github.com/php/frankenphp.git'; $caddy = Upstream::newestTag(CADDY, '/^v2\.\d+\.\d+$/'); -$frankenphp = Upstream::newestTag(FRANKENPHP, '/^v1\.\d+\.\d+$/'); +$frankenphp = Release::newest(); echo 'Newest Caddy: '.$caddy.'. Newest FrankenPHP: '.$frankenphp.'.'.PHP_EOL; $same = Upstream::locks(__DIR__.'/../Fixtures/caddy/caddy.lock', CADDY, $caddy); $same = Upstream::locks(__DIR__.'/../Fixtures/caddy/frankenphp.lock', FRANKENPHP, $frankenphp) && $same; diff --git a/tests/FrankenPhp/Release.php b/tests/FrankenPhp/Release.php index 0343cb9..52f2f81 100644 --- a/tests/FrankenPhp/Release.php +++ b/tests/FrankenPhp/Release.php @@ -103,8 +103,7 @@ public static function attest(string $file, string $asset): void */ public static function digests(string $version): array { - $token = getenv('GITHUB_TOKEN'); - $release = json_decode(self::load('https://api.github.com/repos/php/frankenphp/releases/tags/'.$version, ['Accept: application/vnd.github+json', 'User-Agent: sorge-it/http-server', ...(is_string($token) && $token !== '' ? ['Authorization: Bearer '.$token] : [])]), true, flags: JSON_THROW_ON_ERROR); + $release = self::api('releases/tags/'.$version); $sha256 = []; foreach (is_array($release) && is_array($release['assets'] ?? null) ? $release['assets'] : [] as $asset) { @@ -118,6 +117,17 @@ public static function digests(string $version): array return $sha256; } + /** + * The tag of the newest release, such as `v1.13.6`. Not the newest tag: upstream tags a version + * and publishes its release hours later. + */ + public static function newest(): string + { + $release = self::api('releases/latest'); + + return is_array($release) && is_string($release['tag_name'] ?? null) ? $release['tag_name'] : throw new RuntimeException('The API of GitHub names no newest release of FrankenPHP.'); + } + /** * Puts the asset of the release into the file, executable, after a check of its SHA-256. */ @@ -137,6 +147,17 @@ public static function download(string $version, string $asset, string $sha256, rename($part, $file); } + /** + * The JSON of the path below the repository of FrankenPHP in the API of GitHub. A + * `GITHUB_TOKEN` raises the limit of 60 calls in an hour, but no call needs it. + */ + private static function api(string $path): mixed + { + $token = getenv('GITHUB_TOKEN'); + + return json_decode(self::load('https://api.github.com/repos/php/frankenphp/'.$path, ['Accept: application/vnd.github+json', 'User-Agent: sorge-it/http-server', ...(is_string($token) && $token !== '' ? ['Authorization: Bearer '.$token] : [])]), true, flags: JSON_THROW_ON_ERROR); + } + /** * The body of the URL, or with a file, the body in that file. * diff --git a/tests/FrankenPhp/check-frankenphp.php b/tests/FrankenPhp/check-frankenphp.php index 83a1cd2..181ed74 100644 --- a/tests/FrankenPhp/check-frankenphp.php +++ b/tests/FrankenPhp/check-frankenphp.php @@ -3,7 +3,7 @@ declare(strict_types=1); // composer check:frankenphp compares frankenphp.lock, release.lock and php-src.lock with the newest -// FrankenPHP, a tag vX.Y.Z. A difference does not stop the next comparison. Its binary for this +// release of FrankenPHP. A difference does not stop the next comparison. Its binary for this // machine stays in .frankenphp/newest; the output `binary` names it for a workflow. use SorgeIt\HttpServer\Tests\FrankenPhp\Release; @@ -13,7 +13,7 @@ const FRANKENPHP = 'https://github.com/php/frankenphp.git'; -$tag = Upstream::newestTag(FRANKENPHP, '/^v1\.\d+\.\d+$/'); +$tag = Release::newest(); echo 'Newest FrankenPHP: '.$tag.PHP_EOL; $same = Upstream::locks(__DIR__.'/../Fixtures/frankenphp/frankenphp.lock', FRANKENPHP, $tag); diff --git a/tests/FrankenPhp/lock-frankenphp.php b/tests/FrankenPhp/lock-frankenphp.php index f05ce40..21a95e7 100644 --- a/tests/FrankenPhp/lock-frankenphp.php +++ b/tests/FrankenPhp/lock-frankenphp.php @@ -11,7 +11,7 @@ require __DIR__.'/../../vendor/autoload.php'; -$tag = Upstream::newestTag('https://github.com/php/frankenphp.git', '/^v1\.\d+\.\d+$/'); +$tag = Release::newest(); $digests = Release::digests($tag); $assets = array_values(Release::ASSETS); sort($assets);