ci(release): make a tag the single source of truth for releases - #6
Closed
LeadcodeDev wants to merge 2 commits into
Closed
ci(release): make a tag the single source of truth for releases#6LeadcodeDev wants to merge 2 commits into
LeadcodeDev wants to merge 2 commits into
Conversation
The version rewrite now runs twice — once on the tagged checkout before publishing, once on main afterwards — so it moves into a versioned script instead of being duplicated across two YAML steps. The commit-back deliberately runs last: a commit on main must never announce a release that failed to publish. The script also asserts the internal sqlx-gen-macros requirement, not just the package versions. Cargo already refuses to resolve a pin that falls outside its caret range, but a pin left at ^0.5.9 while releasing 0.5.10 resolves fine and would ship silently drifted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Releasing 0.5.9 failed: the tag was pushed before
Cargo.tomlwas bumped, and the workflow's guard rejected the mismatch. The bump and the tag were two manual steps that could desynchronize — this closes that failure mode rather than the instance.Releasing is now a single action: push a
X.Y.Ztag.What
The tag becomes the single source of truth. The step that used to verify the manifest against the tag now applies the tag version to it, and the release is recorded back on
mainonce it has actually shipped.[workspace.package] versionis rewritten from the tag; both crates inherit it viaversion.workspace = true.sqlx-gen-macrospin moves in lockstep — otherwisesqlx-genwould ship requiring a macros version that was never published.Cargo.lockis refreshed withcargo update --workspace.cargo publishgains--allow-dirty: the version is applied in the runner and is not committed until the release succeeds.mainasdeploy: release X.Y.Z, pushed asgithub-actions[bot].The rewrite runs at two call sites, so it lives in
.github/scripts/set-workspace-version.shrather than being duplicated across two YAML steps — which also makes it directly testable.Ordering and safety
The commit-back runs last, after both
cargo publishcalls. A commit onmainmust never announce a release that failed to publish.The job now needs
permissions: contents: write, andfetch-depth: 0somainis available from a tag checkout. Pushes made withGITHUB_TOKENdo not trigger further workflow runs, so the commit cannot loop back into a publish.Re-running a release is safe: if
mainalready records the version, the step exits without creating an empty commit.Guards
Neither
sedfails loudly if its pattern stops matching, so the script asserts on the resolvedcargo metadata:cargo update(exit 101)reqassertion (exit 1)The second row is the one that matters in practice: a pin left at
^0.5.9while releasing0.5.10resolves perfectly well, both package versions read correct, and the drift would ship unnoticed. Cargo does not catch it.Verification
Run locally against the real manifest, restoring it afterwards:
bash -npasses on the script and on the commit-back step, extracted from the committed YAML.cargo metadata.sedmiss. Releasing0.5.10then exits 1 on thereqassertion.sed > tmp && mvis used rather thansed -i, whose syntax differs between GNU and BSD, so the command exercised locally is the one that runs on the runner.Known trade-off
The tagged commit does not contain the version bump — the bump lands on
mainas a separate commit created afterwards. Checking out tagX.Y.Ztherefore shows the previous version inCargo.toml, while the published crate carriesX.Y.Z. Moving the tag onto the bump commit was rejected: force-updating a tag from the workflow that the tag itself triggered would re-enter the publish job.