Skip to content

ci: let a release pin the exact commit it ships - #432

Merged
somanshreddy merged 2 commits into
mainfrom
10-07-release_pin_commit
Oct 8, 2026
Merged

somanshreddy merged 2 commits into
mainfrom
10-07-release_pin_commit

Conversation

@somanshreddy

Copy link
Copy Markdown
Collaborator

Scope

Surfaces: Release workflows and docs | Module: Build / release pipeline

Summary

Both release workflows released whatever main was when their job started. A merge between someone approving a release and the job starting would ship a commit nobody checked, and the /release-cli skill could only notice afterwards. Releases can now be pinned to the exact commit that was reviewed.

How it works

Both workflows take an optional commit input:

commit What gets released
a full SHA on main exactly that commit, even if main has moved since
empty main as it is when the job starts (today's behaviour)
anything else nothing: the run stops before tagging

The workflow checks out the commit, then refuses to go on unless it is a full 40-character SHA that main contains. That check runs before any code from the checkout executes and before any tag is pushed, so a bad value leaves nothing behind. An older commit on main is allowed on purpose: it is how you release a reviewed commit after newer work has merged.

Design decisions

Optional, not required. Releasing from the Actions UI keeps working without a SHA. RELEASE.md's commands and /release-cli always pass one, and the skill dispatches with the commit the user approved.

Re-dispatches keep the pin. RELEASE.md's recovery steps now say to dispatch again with the failed run's commit; without it, a retry would release main as it is then.

Also in the skill, from the release-cli review: fetch the tag before comparing its commit, a dev release counts as stop point 4, and "pushing any branch or tag" is a stop.

Testing

  • The validation logic, run locally against real commits: origin/main and an older commit on main are accepted; a short SHA and a commit from an unmerged branch are rejected.
  • actionlint and make lint are clean.

🤖 Generated with Claude Code

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving at ab4bbf3d. The pin does what it says, and nothing from the pinned checkout runs before it is validated. One gap is worth closing in a follow-up: a pin can go backwards past the last stable release.

The four things Somansh asked about

Check Result
Anything runs from the unvalidated commit before the check No. Validate commit is the step right after actions/checkout in both workflows. Checkout itself runs no repo code: no submodules, no LFS, and git hooks aren't cloned. setup-go, make test, install-goreleaser.sh and everything else come after it. A failed validation stops the job before the tag step, so tag_push_attempted is never set and the cleanup job doesn't run.
merge-base --is-ancestor against a fresh origin/main Yes. fetch-depth: 0 fetches every branch in the same job, seconds before the check. main only moves forward, so a commit that is on an older origin/main is still on main.
Short or ambiguous SHAs refused Yes. ^[0-9a-f]{40}$ refuses short and uppercase input before git sees it. The input reaches the shell through env, not ${{ }}, so it can't inject.
Tag on the validated SHA, not HEAD They are the same commit. git tag -a tags HEAD, and HEAD is the commit checkout was given, because checkout treats a 40-hex ref as a commit. Cleanup reads commit back from git rev-parse HEAD, so its "pointing at " check matches too.

I ran the validate step on a fresh clone with all branches and tags fetched:

Input Result
origin/main (819a38b) accepted
v0.9.0's commit (c505305, an older commit on main) accepted
12-character prefix refused, "must be a full 40-character SHA"
uppercase full SHA refused, same message
this PR's head ab4bbf3 (not on main) refused, "is not on main"
40 zeros refused, "is not on main"
empty the step is skipped, so main is released as before

Should fix (non-blocking): a pin can go behind the last stable release

"Anything on main" includes commits older than the current stable tag. A stable release pinned to one of them would ship older code under a newer version. publish-cdn would then point the stable pointer at it, and the update notice from #424 would offer that older code as an upgrade. Before this PR that couldn't happen, because main at job start always contains the last tag.

There is a second effect of pinning an old commit. The workflow file comes from main, but every script it runs comes from the pinned commit, so the two can disagree. Today exactly one commit shows this: 4fb2037 (#426). It has install-goreleaser.sh, so it gets past tagging. But its .goreleaser.yaml has no draft: true, so GoReleaser would publish the release directly. It also has no find-run-draft.sh or cleanup-failed-release.sh, so the release job fails and cleanup can't run. The result is a published, stranded release with the CDN never updated. Every earlier commit fails at "Install GoReleaser" before any tag, which is safe.

A floor in Validate commit closes the first case. For a stable release, refuse a commit that doesn't contain the previous stable tag:

prev="$(git tag --list 'v*' --sort=-v:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)"
if [[ -n "$prev" ]] && ! git merge-base --is-ancestor "$prev" "$COMMIT"; then
  echo "commit $COMMIT is older than $prev" >&2
  exit 1
fi

That floor doesn't exclude 4fb2037, because it is newer than v0.9.0. The next stable release moves the floor past it. It's worth keeping in mind whenever a script's interface changes, since an older pinned commit runs the older script under the newer workflow.

Nits

  1. Add a defensive check after the ancestry test: [[ "$(git rev-parse HEAD)" == "$COMMIT" ]]. It holds today because of how checkout resolves a 40-hex ref. One line would keep it true if the checkout step changes.
  2. RELEASE.md uses -f commit="$(git rev-parse origin/main)" at trigger time. That is only the checked commit if nothing ran git fetch after the checklist's first fetch, and steps 5 and 7 run skills that may fetch. Capturing RELEASE_COMMIT=$(git rev-parse origin/main) next to LAST_STABLE would remove that doubt. The skill already dispatches with the commit the user approved, so this only affects the manual path.

My three #429 nits are all in: the tag is fetched before rev-parse <version>^{commit}, the dev release is stop point 4, and "pushing any branch or tag" is a stop.

— Rames

@terencechotai2-commits terencechotai2-commits left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at ab4bbf3. Validation order, quoting and tag placement are right. There is one real gap: an older pinned commit runs its own release scripts and GoReleaser config under today's workflow.

What checks out:

  • Nothing from the checked-out tree runs before Validate commit.
    • actions/checkout is a SHA-pinned marketplace action. Git hooks don't come from the tree, and LFS isn't enabled.
    • merge-base and the regex run inline in the workflow file.
    • make test, install-goreleaser.sh, GoReleaser and find-run-draft.sh all come after the check, so a rejected value stops before any of them and before the tag push. tag_push_attempted stays unset, so cleanup doesn't run either.
  • No injection.
    • checkout gets the input via with: ref:, which is not a shell.
    • The script reads it from env: COMMIT.
    • Neither if: interpolates it into a shell.
  • The on-main check:
    • fetch-depth: 0 brings origin/main with full history, so --is-ancestor has no shallow-clone false results.
    • The ^[0-9a-f]{40}$ regex rejects short SHAs, tags, branch names and uppercase before the ancestry test.
    • A branch name that checkout resolves is still refused by the regex.
    • Empty input falls back to main, and the validate step is skipped.
    • main HEAD itself passes, because --is-ancestor is reflexive.
  • No TOCTOU. The job runs on a detached checkout of the SHA, and "Create git tag" tags HEAD and records git rev-parse HEAD. Main moving afterwards can't change what's tagged.

Medium: version skew between the workflow and an older pinned commit.

The workflow comes from the dispatch ref (main), but several steps execute files from the pinned tree:

  • .github/scripts/install-goreleaser.sh
  • .goreleaser.yaml
  • .github/scripts/find-run-draft.sh
  • the cleanup job's cleanup-failed-release.sh, which checks out needs.release.outputs.commit

The description says older commits are allowed on purpose. Concretely, 4fb2037 (#426) passes validation: it's on main and after v0.9.0. Pinning it on a stable run would:

  1. GoReleaser: use its .goreleaser.yaml, which has no draft: true and no release-run header (checked with git show 4fb2037:.goreleaser.yaml), so it creates a published release straight away.
  2. "Record this run's draft release": run .github/scripts/find-run-draft.sh, which doesn't exist at 4fb2037 → release fails.
  3. cleanup-failed-release: check out 4fb2037 and run .github/scripts/cleanup-failed-release.sh, which doesn't exist there either → cleanup fails.

The result is a public release plus its tag, no CDN publish, and no automatic recovery. That is exactly the state #427 exists to prevent.

  • Pinning 3485904 or earlier fails at "Install GoReleaser", before the tag, so it's harmless.
  • The same skew returns whenever .github/scripts or .goreleaser.yaml change on main after the pinned commit. Today the window is one commit, but it will come back.

Inline suggestion: refuse a pin whose release machinery differs from the workflow's own commit ($GITHUB_SHA). The alternative is to run the scripts from a second checkout of github.workflow_sha. That's more robust, but a bigger change.

Low (stable only): an "on main" pin can predate the last stable tag.

Nothing stops version=v0.9.1 with a commit from before v0.9.0. That ships older code as a newer version, and heygen update would roll users back. A stable run could also require git merge-base --is-ancestor "$LAST_STABLE" "$COMMIT", using the same tag filter the "Resolve previous stable tag" step uses.

Nits:

  • RELEASE.md dev section: -f commit="$(git rev-parse origin/main)" has no git fetch before it, unlike the stable checklist. A stale clone pins an old main, which is the skew case above.
  • The Actions-UI instruction ("enter the version tag, and click Run workflow") doesn't mention the new commit field, so UI releases will usually go unpinned.
  • Skill changes: they address my three #429 notes (fetch the tag before comparing, dev counts as stop 4, "pushing any branch or tag").

No API surface change, so the caller-impact rule doesn't apply.

— tai2

Comment on lines +52 to +55
if ! git merge-base --is-ancestor "$COMMIT" origin/main; then
echo "commit $COMMIT is not on main" >&2
exit 1
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium: refuse a pin whose release machinery differs from this workflow's. The steps below run this commit's install-goreleaser.sh, .goreleaser.yaml and find-run-draft.sh, and the cleanup job runs its cleanup-failed-release.sh. At 4fb2037 (on main) the GoReleaser config has no draft: true and the two #427 scripts don't exist. A failed run there leaves a published release and its tag with no working cleanup. See the review body for the walkthrough.

Suggested change
if ! git merge-base --is-ancestor "$COMMIT" origin/main; then
echo "commit $COMMIT is not on main" >&2
exit 1
fi
if ! git merge-base --is-ancestor "$COMMIT" origin/main; then
echo "commit $COMMIT is not on main" >&2
exit 1
fi
# The steps below and the cleanup job run this commit's release scripts and
# GoReleaser config under this workflow, so they must be the same files.
if ! git diff --quiet "$COMMIT" "$GITHUB_SHA" -- .github/scripts .goreleaser.yaml; then
echo "commit $COMMIT has different release scripts or GoReleaser config than this workflow ($GITHUB_SHA); release a newer commit" >&2
exit 1
fi

$GITHUB_SHA is the dispatch ref's tip, which fetch-depth: 0 has already fetched. The same change applies to dev-release.yml:51-54.

Comment thread RELEASE.md

```bash
gh workflow run dev-release.yml
gh workflow run dev-release.yml -f commit="$(git rev-parse origin/main)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: without a git fetch origin first, this pins whatever origin/main the local clone last saw. On a stale clone that's an older commit, which is the skew case in the review body. Suggest git fetch origin && gh workflow run dev-release.yml -f commit="$(git rev-parse origin/main)".

somanshreddy and others added 2 commits October 8, 2026 00:49
… release scripts

A pinned commit runs its own .github/scripts and .goreleaser.yaml under the
workflow file from main, so a commit whose copies differ could publish
directly or leave nothing to clean up a failed run. A pin older than the last
stable release would ship older code under a newer version. Both are now
refused, along with a checkout that did not land on the pinned commit.
RELEASE.md captures the release commit once at the start of the checklist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@somanshreddy
somanshreddy force-pushed the 10-07-release_pin_commit branch from ab4bbf3 to 4ba9d20 Compare October 8, 2026 00:57

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-approving at 4ba9d20. Both findings from my last review are fixed.

Scope of this round. range-diff: ab4bbf3 = 344a5e1, so the pin commit is unchanged. All new behaviour is in 4ba9d20, and it touches only the two workflows, RELEASE.md and the release skill. .github/scripts and .goreleaser.yaml are untouched.

Simulation. I extracted the new Validate commit step from release-stable.yml and ran it against a fresh clone, with GITHUB_SHA set to this head:

Pin Result
origin/main (v0.9.0-12) passes
v0.8.1 refused: older than the last stable release v0.9.0
4fb2037 (#426, the stranding case) refused: different release scripts
v0.9.0's own commit refused: different release scripts (#427 and #430 changed them later)
checkout HEAD ≠ COMMIT exit 1

So the earliest commit you can pin today is 819a38b (#430), the last commit to touch the release scripts. That's the right floor in practice: the script-diff guard is the stricter check and the tag floor backs it up.

The dev floor (your "hardest look"). I agree it belongs in dev-release.yml too. Compute dev version derives v<last stable patch+1>-dev.<ts> from the same git tag --list in the same fetch-depth: 0 checkout. Without the floor, a pre-v0.9.0 commit would ship as v0.9.1-dev.* with older code, which is the same failure as on stable. The two steps read one tag list, so they can't disagree.

RELEASE.md and the skill. RELEASE_COMMIT is set once after git fetch. Every check, the E2E checkout, release-surface.sh and the dispatch now use it. The changelog step asks you to confirm origin/main hasn't moved, which is right because /changelog-cli reads origin/main.

Nit (no change needed). If a stable tag is ever cut off a branch that isn't an ancestor of main, every pinned release fails the floor until the next tag. Unpinned releases skip the step entirely, so it can't wedge a release. I'm noting it only so the error isn't a surprise.

— Rames

@terencechotai2-commits terencechotai2-commits left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 4ba9d20. No findings. Both earlier findings and both nits are resolved.

The pin commit is unchanged by the rebase: 344a5e1 has the same git patch-id as ab4bbf3.

Version skew (was Medium): resolved.
I extracted the stable workflow's Validate commit step and ran it on real commits, with GITHUB_SHA and origin/main set to this head to stand in for post-merge main:

Pinned commit Result
4ba9d20 (this head), 4b05ac8 (main), 819a38b (#430) passes
6d5b647 (pre-#430 cleanup script) refused: different release scripts
4fb2037 (#426, my earlier example) refused: different release scripts
c505305 (the v0.9.0 commit) refused: different release scripts
aeaeac0 (v0.9.0~1) refused: older than v0.9.0

So a pin can only run release machinery that is identical to the workflow's own. Draft, find-run-draft, publish-by-ID and cleanup all hold.

Stable floor (was Low): resolved.

  • All 30 existing stable tags are ancestors of main, so the floor can't wedge on an off-main tag today.
  • Both workflows now also check HEAD == COMMIT.

Dev floor (the point you asked about): agreed.

  • The floor and Compute dev version run in the same job, on the same fetch-depth: 0 checkout.
  • Nothing in between fetches: setup-go, make test and the Makefile don't touch tags.
  • So a concurrent stable release pushing a new tag can't make them disagree. Both see the pre-push tag list.
  • Unpinned runs skip the step, and main is always at or past the last stable tag, so nothing changes for them.

Docs: accurate.

  • RELEASE_COMMIT is set once and used in steps 1, 3 and 4, the E2E checkout, both release-surface.sh calls and the trigger.
  • The step 7 guard is correct: /changelog-cli reads origin/main and doesn't fetch on its own, so checking that origin/main still equals RELEASE_COMMIT is the right guard.
  • The dev command now fetches first, and the UI step names the commit field.
  • The skill still has exactly six stop points; only stop 4's wording changed.

Optional nit: --is-ancestor is reflexive. A stable pin of exactly the last stable commit therefore passes and ships the same code under a new version. It's harmless and visible in step 1's empty git log, so I'm noting it only.

CI: 10/10 checks pass.

— tai2

@somanshreddy
somanshreddy merged commit fb1ac0c into main Oct 8, 2026
10 checks passed
@somanshreddy
somanshreddy deleted the 10-07-release_pin_commit branch October 8, 2026 01:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants