From 54c70d4844a9d8a286a07880df911c9c4be9c8a3 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 28 Oct 2026 16:44:47 +0800 Subject: [PATCH] chore: automate the GitHub release notes and credit all contributors --- admin/README.md | 3 + admin/RELEASE.md | 25 +++---- admin/create-release.php | 148 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 16 deletions(-) create mode 100644 admin/create-release.php diff --git a/admin/README.md b/admin/README.md index a4048bf59152..aa81a25da794 100644 --- a/admin/README.md +++ b/admin/README.md @@ -54,6 +54,9 @@ are used as part of that process: version references in the framework source, the user guide, and the distribution build script. Usage: `php admin/prepare-release.php 4.x.x` +- **create-release.php** publishes the GitHub release for a new version, + crediting every PR author since the previous release except bots. + Usage: `php admin/create-release.php 4.x.x [--previous=v4.x.w] [--dry-run]` - **create-new-changelog.php** creates the changelog and upgrade guide stubs for the next version and adds them to their index files. Usage: `php admin/create-new-changelog.php ` diff --git a/admin/RELEASE.md b/admin/RELEASE.md index 75f2a0fbf35a..8be9798b3ae8 100644 --- a/admin/RELEASE.md +++ b/admin/RELEASE.md @@ -150,22 +150,15 @@ existing content. * Title: `4.x.x Ready code` * Description: blank * [ ] Merge the PR and wait for all tests. -* [ ] Create a new Release: - * Choose a tag: `v4.x.x` (Create new tag: v4.x.x on publish) - * Target: `master` - * Title: `CodeIgniter 4.x.x` - * Description: - ``` - CodeIgniter 4.x.x release. - - See the changelog: https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md - - ## New Contributors - * - - **Full Changelog**: https://github.com/codeigniter4/CodeIgniter4/compare/v4.x.w...v4.x.x - ``` - Click the "Generate release notes" button, and get the "New Contributors". +* [ ] Create the new Release: + * Run `php admin/create-release.php 4.x.x --dry-run` and check the output. + * Run `php admin/create-release.php 4.x.x` to publish it. + * The above command does the following: + * Fetch GitHub's auto-generated release notes for `master` since the latest + release (override with `--previous=v4.x.w`) + * Credit every PR author except bots, marking first-time contributors + * Publish the release `CodeIgniter 4.x.x` with the tag `v4.x.x` on `master`, + linking to **CHANGELOG.md** and the full comparison * [ ] Watch the "[Verify Release](https://github.com/codeigniter4/CodeIgniter4/actions/workflows/verify-release.yml)" workflow and make sure it passes. It does the following: * Wait for the "[Deploy Distributable Repos](https://github.com/codeigniter4/CodeIgniter4/actions/workflows/deploy-distributables.yml)" diff --git a/admin/create-release.php b/admin/create-release.php new file mode 100644 index 000000000000..efb08d208404 --- /dev/null +++ b/admin/create-release.php @@ -0,0 +1,148 @@ + [--previous=] [--dry-run] + */ +chdir(__DIR__ . '/..'); + +$args = array_slice($argv, 1); +$options = array_values(array_filter($args, static fn (string $arg): bool => str_starts_with($arg, '--'))); +$params = array_values(array_diff($args, $options)); + +if (count($params) !== 1 || preg_match('/\Av?(\d+\.\d+\.\d+)\z/', $params[0], $matches) !== 1) { + echo sprintf("Usage: php %s [--previous=] [--dry-run]\n", $argv[0]); + echo sprintf("E.g.,: php %s 4.7.6\n", $argv[0]); + + exit(1); +} + +$version = $matches[1]; +$tag = sprintf('v%s', $version); +$dryRun = in_array('--dry-run', $options, true); +$repo = 'codeigniter4/CodeIgniter4'; + +exec(sprintf('gh release view %s --repo %s 2>&1', escapeshellarg($tag), $repo), $output, $exitCode); + +if ($exitCode === 0) { + echo sprintf("The release %s already exists.\n", $tag); + + exit(1); +} + +$previousTag = null; + +foreach ($options as $option) { + if (str_starts_with($option, '--previous=')) { + $previousTag = sprintf('v%s', ltrim(substr($option, strlen('--previous=')), 'v')); + } +} + +if ($previousTag === null) { + $output = []; + exec(sprintf('gh release view --repo %s --json tagName --jq .tagName 2>&1', $repo), $output, $exitCode); + + if ($exitCode !== 0) { + echo "Failed to fetch the latest release from GitHub:\n"; + echo implode("\n", $output) . "\n"; + + exit(1); + } + + $previousTag = trim(implode('', $output)); +} + +$output = []; +exec(sprintf( + 'gh api repos/%s/releases/generate-notes -f tag_name=%s -f target_commitish=master -f previous_tag_name=%s 2>&1', + $repo, + escapeshellarg($tag), + escapeshellarg($previousTag), +), $output, $exitCode); + +if ($exitCode !== 0) { + echo "Failed to fetch the release notes from GitHub:\n"; + echo implode("\n", $output) . "\n"; + + exit(1); +} + +$notes = json_decode(implode("\n", $output), true)['body'] ?? ''; + +$contributors = []; +$firstPulls = []; +$fullChangelog = null; + +foreach (preg_split('/\R/', $notes) as $line) { + if (preg_match('~ by @(\S+) in https://github\.com/\S+/pull/\d+$~', $line, $matches) === 1) { + $contributors[$matches[1]] = true; + + continue; + } + + if (preg_match('~^\* @(\S+) made their first contribution in (\S+)$~', $line, $matches) === 1) { + $firstPulls[$matches[1]] = $matches[2]; + + continue; + } + + if (str_starts_with($line, '**Full Changelog**: ')) { + $fullChangelog = $line; + } +} + +if ($fullChangelog === null) { + echo "Could not find the Full Changelog link in the release notes.\n"; + + exit(1); +} + +$contributors = array_filter( + array_keys($contributors), + static fn (string $login): bool => ! str_ends_with($login, '[bot]'), +); +natcasesort($contributors); + +$credits = array_map( + static fn (string $login): string => isset($firstPulls[$login]) + ? sprintf('* @%s made their first contribution in %s', $login, $firstPulls[$login]) + : sprintf('* @%s', $login), + $contributors, +); + +$body = sprintf("CodeIgniter %s release.\n\n", $version); +$body .= sprintf("See the changelog: https://github.com/%s/blob/develop/CHANGELOG.md\n\n", $repo); + +if ($credits !== []) { + $body .= sprintf("## Contributors\n\n%s\n\n", implode("\n", $credits)); +} + +$body .= $fullChangelog . "\n"; + +if ($dryRun) { + echo $body; + + exit(0); +} + +$notesFile = tempnam(sys_get_temp_dir(), 'ci4-release-'); +file_put_contents($notesFile, $body); + +passthru(sprintf( + 'gh release create %s --repo %s --target master --title %s --notes-file %s', + escapeshellarg($tag), + $repo, + escapeshellarg(sprintf('CodeIgniter %s', $version)), + escapeshellarg($notesFile), +), $exitCode); + +unlink($notesFile); + +exit($exitCode);