diff --git a/.github/workflows/version.yml b/.github/workflows/version.yml new file mode 100644 index 0000000..c2323f4 --- /dev/null +++ b/.github/workflows/version.yml @@ -0,0 +1,39 @@ +name: Version + +# Keeps Http::VERSION in step with the release tags (scripts/check-version.php). On a pull request or a +# push it must not be older than the latest release; on a published release it must equal the release's tag. + +on: + push: + branches: [master] + pull_request: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + version: + name: Http::VERSION + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@v4 + with: + # All tags, to find the latest release. + fetch-depth: 0 + + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.4' + coverage: none + + - name: Check against the latest release + if: github.event_name != 'release' + run: php scripts/check-version.php + + - name: Check against this release + if: github.event_name == 'release' + run: php scripts/check-version.php "${{ github.event.release.tag_name }}" diff --git a/scripts/check-version.php b/scripts/check-version.php new file mode 100644 index 0000000..f191f82 --- /dev/null +++ b/scripts/check-version.php @@ -0,0 +1,58 @@ + + * + * This file is subject to the MIT license that is bundled + * with this source code in the LICENSE file. + */ + +// Checks that Http::VERSION, which bots log at startup and quote in bug reports, keeps up with the +// release tags. +// +// php scripts/check-version.php VERSION must not be older than the newest v* tag. +// php scripts/check-version.php v10.9.9 VERSION must be exactly this tag (run when it is released). +// +// Exits 0 when it holds and 1 when it does not. It needs the repository's tags, so a CI checkout +// fetches them (fetch-depth: 0). + +const FILE = __DIR__.'/../src/Discord/Http.php'; + +if (1 !== preg_match("/public const VERSION = '(v[^']+)';/", (string) file_get_contents(FILE), $match)) { + fwrite(STDERR, 'Could not find VERSION in '.FILE.PHP_EOL); + exit(2); +} +$version = $match[1]; + +if (isset($argv[1])) { + if ($version !== $argv[1]) { + echo "Http::VERSION is {$version}, but this release is {$argv[1]}. Set VERSION to {$argv[1]}.".PHP_EOL; + exit(1); + } + echo "Http::VERSION matches the release, {$version}.".PHP_EOL; + exit(0); +} + +exec("git tag --list 'v*'", $tags, $status); +if (0 !== $status) { + fwrite(STDERR, 'Could not list the git tags.'.PHP_EOL); + exit(2); +} +// Pre-release tags (v8.0.0-RC.1) never count as the newest release. +$tags = array_filter($tags, fn (string $tag) => 1 === preg_match('/^v\d+\.\d+\.\d+$/', $tag)); +if ([] === $tags) { + echo "No release tags to compare Http::VERSION ({$version}) with.".PHP_EOL; + exit(0); +} +usort($tags, 'version_compare'); +$latest = end($tags); + +if (version_compare($version, $latest, '<')) { + echo "Http::VERSION is {$version}, older than the latest release, {$latest}. Set it to {$latest} or the version about to be released.".PHP_EOL; + exit(1); +} +echo "Http::VERSION, {$version}, is not older than the latest release, {$latest}.".PHP_EOL; diff --git a/src/Discord/Http.php b/src/Discord/Http.php index 2cff10e..af06f04 100644 --- a/src/Discord/Http.php +++ b/src/Discord/Http.php @@ -31,7 +31,7 @@ class Http implements HttpInterface * * @var string */ - public const VERSION = 'v10.9.4'; + public const VERSION = 'v10.9.8'; /** * Current Discord HTTP API version.