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
39 changes: 39 additions & 0 deletions .github/workflows/version.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
58 changes: 58 additions & 0 deletions scripts/check-version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP-Http project.
*
* Copyright (c) 2021-present David Cole <david.cole1340@gmail.com>
*
* 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;
2 changes: 1 addition & 1 deletion src/Discord/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading