Merge pull request #9211 from Wei-Shaw/fix/release-version-before-tag

fix(release): require the tagged commit to carry the release VERSION
This commit is contained in:
Wesley Liddick authored and GitHub committed 2026-12-02 15:29:07 +08:00
commit edba3eb7eb
4 files changed
+39 -34

No files matched your search

+3 -1
View File
@@ -6,6 +6,8 @@ Each build uses GoReleaser OSS in snapshot mode with the selected release versio
Go caches are isolated by target and refreshed on each source commit, with fallback to the preceding target cache. Save uses the original restore key, even if a build hook changes `go.sum`. Matrix jobs upload uniquely named artifacts. The publishing job extracts only the regular Linux binary from each verified archive and restores its executable permission before constructing Docker contexts. QEMU remains limited to runtime-image instructions. DockerHub images are omitted when its credentials are absent; GHCR is always retained. Simple mode still publishes only the amd64 GHCR image and the simple release description.
A tag push is rejected in `prepare`, before anything is built or published, unless `backend/cmd/server/VERSION` at the tagged commit already equals the tag version: commit the VERSION bump first, then tag that commit. Source builds of the tag (`go build`, GitHub source archives, Docker builds without `.git`) embed that file. To re-release an older tag created before this rule, run the workflow manually with `allow_version_mismatch=true`; it then emits a warning and builds with the tag version.
All build jobs use the commit resolved by `prepare`, including a manual release's selected tag. Helper scripts come from the workflow revision and are passed as a run-local artifact, so older application tags do not need to contain the new scripts. The workflow serializes release runs to prevent simultaneous updates to moving image tags.
## Validate without publication
@@ -17,7 +19,7 @@ gh workflow run release.yml --ref <branch> \
-f tag=<branch> -f dry_run=true -f simple_release=false
```
A dry run builds all selected archives and both runtime images, verifies artifact provenance and produces the final checksum file. It exports images locally as OCI archives instead of pushing them. It skips registry logins, GitHub Release publication, DockerHub description updates, Telegram notifications and VERSION synchronization. Test the simple path separately with `simple_release=true`.
A dry run builds all selected archives and both runtime images, verifies artifact provenance and produces the final checksum file. It exports images locally as OCI archives instead of pushing them. It skips registry logins, GitHub Release publication, DockerHub description updates, and Telegram notifications. Test the simple path separately with `simple_release=true`.
Dry-run artifacts are available in the Actions run, including `release-dry-run-report`. Compare job start/end times, GoReleaser's build duration and cache restore results. Do not present an initial cold-cache run as a warmed-cache benchmark; publishing network time is not measured by dry runs.
+10
View File
@@ -63,6 +63,15 @@ def plan(args):
tagged_sha = subprocess.check_output(['git', 'rev-parse', '--verify', f'refs/tags/{tag}^{{commit}}'], text=True).strip()
if sha != tagged_sha:
raise ValueError('checkout does not match the selected release tag')
committed = VERSION_FILE.read_text().strip()
if committed != version:
# Source builds of the tag (go build, archives, Docker builds without .git)
# embed this file, so the tagged commit itself must carry the new version.
message = (f'{VERSION_FILE} at {tag} is {committed!r}, expected {version!r}; '
'commit the VERSION bump first, then tag that commit')
if not args.allow_version_mismatch:
raise ValueError(message)
print(f'::warning::{message}')
if not VERSION_RE.fullmatch(version):
raise ValueError('invalid VERSION')
VERSION_FILE.write_text(version + '\n')
@@ -161,6 +170,7 @@ def main():
p.add_argument('--ref', required=True)
p.add_argument('--simple', action='store_true')
p.add_argument('--dry-run', action='store_true')
p.add_argument('--allow-version-mismatch', action='store_true')
p.set_defaults(run=plan)
p = commands.add_parser('config')
p.add_argument('mode', choices=['build', 'publish'])
+17 -1
View File
@@ -121,8 +121,24 @@ class ReleaseMatrixTest(unittest.TestCase):
self.assertEqual(binary.read_bytes(), b'fixture')
self.assertEqual(binary.stat().st_mode & 0o777, 0o755)
def test_tag_push_requires_committed_version_to_match_tag(self):
release.VERSION_FILE.write_text('9.8.6\n')
args = argparse.Namespace(ref='v9.8.7', dry_run=False, simple=False, allow_version_mismatch=False)
with patch.object(subprocess, 'check_output', return_value='a' * 40 + '\n'):
with self.assertRaisesRegex(ValueError, "is '9.8.6', expected '9.8.7'"):
release.plan(args)
def test_manual_release_of_older_tag_warns_and_uses_tag_version(self):
release.VERSION_FILE.write_text('9.8.6\n')
args = argparse.Namespace(ref='v9.8.7', dry_run=False, simple=False, allow_version_mismatch=True)
with patch.dict(os.environ, {'GITHUB_OUTPUT': 'outputs'}), patch.object(subprocess, 'check_output', return_value='a' * 40 + '\n'):
release.plan(args)
output = dict(line.split('=', 1) for line in Path('outputs').read_text().splitlines())
self.assertEqual(output['version'], '9.8.7')
self.assertEqual(release.VERSION_FILE.read_text(), '9.8.7\n')
def test_plan_requires_a_tag_for_publication(self):
args = argparse.Namespace(ref='main', dry_run=False, simple=False)
args = argparse.Namespace(ref='main', dry_run=False, simple=False, allow_version_mismatch=False)
with patch.object(subprocess, 'check_output', return_value='a' * 40 + '\n'):
with self.assertRaisesRegex(ValueError, 'version tag'):
release.plan(args)
+9 -32
View File
@@ -20,6 +20,11 @@ on:
required: false
type: boolean
default: false
allow_version_mismatch:
description: 'Re-release an older tag whose committed VERSION predates the tag (builds with the tag version)'
required: false
type: boolean
default: false
concurrency:
group: release-${{ github.repository }}
@@ -64,10 +69,14 @@ jobs:
id: plan
env:
REQUESTED_REF: ${{ inputs.tag || github.ref_name }}
ALLOW_VERSION_MISMATCH: ${{ github.event_name == 'workflow_dispatch' && inputs.allow_version_mismatch == true }}
run: |
args=(--ref "$REQUESTED_REF")
if [[ "$SIMPLE_RELEASE" == true ]]; then args+=(--simple); fi
if [[ "$DRY_RUN" == true ]]; then args+=(--dry-run); fi
# The tagged commit must already carry the release VERSION. Only an explicit
# manual re-release of an older tag may bypass this.
if [[ "$ALLOW_VERSION_MISMATCH" == true ]]; then args+=(--allow-version-mismatch); fi
python "$RUNNER_TEMP/release-tools/release_matrix.py" plan "${args[@]}"
- uses: actions/upload-artifact@v7
with:
@@ -374,35 +383,3 @@ jobs:
parse_mode: "Markdown",
disable_web_page_preview: true
}')"
sync-version-file:
needs: [prepare, release]
if: ${{ needs.release.result == 'success' && needs.prepare.outputs.dry_run != 'true' }}
runs-on: ubuntu-latest
permissions:
contents: write
env:
RELEASE_VERSION: ${{ needs.prepare.outputs.version }}
steps:
- name: Checkout default branch
uses: actions/checkout@v6
with:
ref: ${{ github.event.repository.default_branch }}
- name: Sync VERSION file to released tag
run: |
VERSION="$RELEASE_VERSION"
CURRENT_VERSION=$(tr -d '\r\n' < backend/cmd/server/VERSION || true)
if [ "$CURRENT_VERSION" = "$VERSION" ]; then
echo "VERSION file already matches $VERSION"
exit 0
fi
echo "$VERSION" > backend/cmd/server/VERSION
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add backend/cmd/server/VERSION
git commit -m "chore: sync VERSION to ${VERSION} [skip ci]"
git push origin HEAD:${{ github.event.repository.default_branch }}