Skip to content

Commit 2dd46d3

Browse files
committed
Enable release automation to handle pre-releases
1 parent 4f3400b commit 2dd46d3

File tree

3 files changed

+93
-29
lines changed

3 files changed

+93
-29
lines changed

.github/workflows/release.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
workflow_dispatch:
66
inputs:
77
version:
8-
description: "The version to be released. This is checked for consistency with the branch name and configuration"
8+
description: "The version to be released in PECL format (e.g. 1.19.1, 1.20.0beta1)"
99
required: true
1010
type: "string"
1111
jira-version-number:
@@ -76,31 +76,12 @@ jobs:
7676
with:
7777
php-version: "${{ matrix.php-version }}"
7878

79-
- name: "Update version information to stable release"
80-
run: ./bin/update-release-version.php to-stable
81-
82-
- name: "Read current package version"
83-
run: echo "PACKAGE_VERSION=$(./bin/update-release-version.php get-version)" >> "$GITHUB_ENV"
84-
85-
# Sanity check - the version from the input and the one determined by phongo_version.h need to be the same
86-
- name: "Check version for consistency"
87-
if: ${{ inputs.version != env.PACKAGE_VERSION }}
88-
# We exit with an error to abort the workflow. This is only run if the versions don't match
89-
run: |
90-
echo '❌ Release failed due to version mismatch: expected ${{ inputs.version }}, got ${{ env.PACKAGE_VERSION }} from code' >> $GITHUB_STEP_SUMMARY
91-
exit 1
92-
93-
#
94-
# Preliminary checks done - commence the release process
95-
#
96-
9779
- name: "Create package commit"
9880
uses: mongodb-labs/drivers-github-tools/bump-version@v2
9981
with:
10082
version: ${{ inputs.version }}
101-
# Use get-version as a dummy as a version_bump_script is required
102-
# We run the bump script manually earlier so we can sanity-check the version number and print nice output
103-
version_bump_script: "./bin/update-release-version.php get-version"
83+
# Note: this script will fail and abort if the requested version can't be released
84+
version_bump_script: "./bin/update-release-version.php release"
10485
commit_template: 'Package ${VERSION}'
10586
# Don't push changes as we're creating a second commit later
10687
push_commit: false
@@ -117,7 +98,7 @@ jobs:
11798
uses: mongodb-labs/drivers-github-tools/bump-version@v2
11899
with:
119100
version: ${{ inputs.version }}
120-
version_bump_script: "./bin/update-release-version.php to-next-patch-dev"
101+
version_bump_script: "./bin/update-release-version.php to-next-dev"
121102
commit_template: 'Back to -dev'
122103
# Don't push commit, we still need to merge up
123104
push_commit: false
@@ -155,7 +136,11 @@ jobs:
155136
EOL
156137
157138
- name: "Create draft release"
158-
run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV"
139+
run: |
140+
if [[ "${{ inputs.version }}" =~ (alpha|beta) ]]; then
141+
PRERELEASE="--prerelease --latest=false"
142+
fi
143+
echo "RELEASE_URL=$(gh release create ${{ inputs.version }} ${PRERELEASE} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV"
159144
160145
- name: "Set summary"
161146
run: |

RELEASING.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,17 @@ enter the version number and the corresponding JIRA version ID for the release.
4646
This version ID can be obtained from a link in the "Version" column on the
4747
[PHPC releases page](https://jira.mongodb.org/projects/PHPC?selectedItem=com.atlassian.jira.jira-projects-plugin%3Arelease-page&status=unreleased).
4848

49-
The automation will then create and push the necessary commits and tag, create a
50-
draft release, and trigger the packaging builds for the newly created tag. The
51-
release is created in a draft state and can be published once the release notes
52-
have been updated.
49+
The automation will create and push the necessary commits and tag, create a
50+
draft release, trigger the packaging builds for the newly created tag, and
51+
publish all required SSDLC assets. The release is created in a draft state and
52+
can be published once the release notes have been updated.
53+
54+
Pre-releases (e.g. alpha and beta stability) can be released using the
55+
automation as well. When entering a pre-release version number, make sure to not
56+
include a dash before the stability, e.g. `1.20.0beta1` not `1.20.0-beta1`. PECL
57+
versions do not include a dash before the stability. GitHub Releases for
58+
pre-release versions will be marked as such and will not be marked as "latest"
59+
release.
5360

5461
Alternatively, you may follow the [manual release process](#manual-release-process)
5562
before continuing with the next section.

bin/update-release-version.php

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ function usage()
99

1010
echo <<<EOT
1111
Usage:
12-
{$argv[0]} <command>
12+
{$argv[0]} <command> [<version>]
1313
1414
Commands:
15+
release: Release the given version (requires second argument)
16+
to-next-dev: Update to the next version following the current version
1517
to-stable: Mark the current version as stable
1618
to-next-patch-dev: Update to the next patch development version
1719
to-next-minor-dev: Update to the next minor development version
@@ -50,6 +52,25 @@ function read_release_version(string $filename): array
5052
return $versions;
5153
}
5254

55+
function parse_release_version(string $version): array
56+
{
57+
// Regex copied from https://github.com/pear/pear-core/blob/6f4c3a0b134626d238d75a44af01a2f7c4e688d9/PEAR/Common.php#L32
58+
if (! preg_match('#^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)(?:(?<stability>(?:alpha|beta))(?<prereleasenum>\d+))?$#', $version, $matches)) {
59+
throw new Exception(sprintf('Given version "%s" is not in the PEAR version format'));
60+
}
61+
62+
return [
63+
'version' => $version,
64+
'stability' => $matches['stability'] ?? 'stable',
65+
'versionComponents' => [
66+
$matches['major'],
67+
$matches['minor'],
68+
$matches['patch'],
69+
0,
70+
],
71+
];
72+
}
73+
5374
function write_release_version(string $filename, array $version): void
5475
{
5576
if (! is_file($filename)) {
@@ -140,6 +161,45 @@ function get_next_minor_version(array $versions): array
140161
];
141162
}
142163

164+
function get_next_release_version(array $versions, string $releaseVersion): array
165+
{
166+
$releaseVersion = parse_release_version($releaseVersion);
167+
168+
// When bumping to the specified release version, check if the major, minor, and patch versions match what's currently in the file
169+
if (array_slice($versions['versionComponents'], 0, 3) !== array_slice($releaseVersion['versionComponents'], 0, 3)) {
170+
throw new Exception(sprintf('Cannot bump version "%s" to version "%s".', $versions['version'], $releaseVersion['version']));
171+
}
172+
173+
// Now, re-use the existing version components to copy over the previous build number used for DLLs
174+
$releaseVersion['versionComponents'] = $versions['versionComponents'];
175+
176+
return $releaseVersion;
177+
}
178+
179+
function get_next_dev_version(array $versions): array
180+
{
181+
$versionComponents = $versions['versionComponents'];
182+
183+
// We're dealing with a pre-release. The next version is a devel version of the corresponding stable release
184+
// Examples:
185+
// 1.19.1snapshot => 1.19.1dev
186+
// 1.20.0alpha1 => 1.20.0dev
187+
// 1.20.0beta1 => 1.20.0dev
188+
if ($versions['stability'] != 'stable') {
189+
// Increase the build number for unique DLL versions
190+
$versionComponents[3]++;
191+
192+
return [
193+
'version' => get_version_string_from_components($versionComponents) . 'dev',
194+
'stability' => 'devel',
195+
'versionComponents' => $versionComponents,
196+
];
197+
}
198+
199+
// For all other releases, return the next patch version
200+
return get_next_patch_version($versions);
201+
}
202+
143203
// Allow 2 arguments as the bump-version action always passes a version number, even when not needed
144204
if (! in_array($argc, [2, 3])) {
145205
usage();
@@ -153,6 +213,18 @@ function get_next_minor_version(array $versions): array
153213

154214
exit(0);
155215

216+
case 'release':
217+
if ($argc !== 3) {
218+
usage();
219+
}
220+
221+
$newVersion = get_next_release_version($currentVersion, $argv[2]);
222+
break;
223+
224+
case 'to-next-dev':
225+
$newVersion = get_next_dev_version($currentVersion);
226+
break;
227+
156228
case 'to-stable':
157229
$newVersion = get_stable_version($currentVersion);
158230
break;

0 commit comments

Comments
 (0)