Repository navigation
ci: recover from a failed release without a stranded tag - #427
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
terencechotai2-commits
left a comment
There was a problem hiding this comment.
Looks good, with one Low finding inline. The draft boundary is the right spine, and the tag-ownership checks hold up.
Verified
-
The leased delete is real. It uses
--force-with-lease=refs/tags/X:<tag object sha>with an explicit expected value, on a delete refspec. I checked it against a local bare repo, from a shallow clone at the commit that never fetched the tag object (as in the cleanup job's checkout):- Tag replaced after the check:
! [rejected] (delete) -> v1.0.0 (stale info), and the replacement survives. - Lease with the peeled commit sha instead of the tag object: rejected.
- Matching lease: deleted.
- Re-run after the tag is gone: the push would be rejected, but the script's 404 branch never reaches it.
The lease value comes from
git/ref/tags/X's.object.sha, which is the tag object, so the comparison is against the right thing. - Tag replaced after the check:
-
The annotation check reads the tag object. A lightweight tag gives
object.type == "commit"and is refused. The target is checked against the commit, and the message must equalRelease ${tag} by GitHub Actions run ${run_id}exactly, with no parsing involved. Only someone with push access could forge that string, and they could delete the tag anyway. -
Draft vs published is race-free inside the pipeline.
publish-releaseneedsreleaseto succeed, and cleanup needs it not to, so the two can't both run in one attempt. On a re-run, the needs outputs are re-evaluated from that attempt. A failed "Re-run failed jobs" stops at the tag-exists validation beforepush_attemptedis set, so cleanup is skipped rather than run against an older tag. The only remaining window is a person publishing by hand between the list and the DELETE, which is negligible. -
The
if:conditions are right.always() && result != 'success'covers bothfailureandcancelled.push_attemptedis written beforegit push, so a push that landed but reported an error is still cleaned up. A push rejected because someone else's tag already exists reaches the ownership check, is refused, and nothing is deleted. -
Orphans between draft and tag can't happen. The tag is pushed before GoReleaser runs, so a draft can't exist without this run's tag; the leftover is only ever tag-only or tag-plus-draft.
-
Token permissions are fine. Cleanup and publish need
contents: write.publish-cdnis down tocontents: readplusid-token: write. -
#426's pinned GoReleaser works with draft mode.
install-goreleaser.shpins v2.18.2, andrelease.draftis a long-standing v2 option. The PR'sgoreleaser-checkCI job passes withdraft: true. -
gh release edit --draft=falsefinds drafts.FetchReleasefalls back to a GraphQLrelease(tagName:)lookup for drafts. -
No other consumer. Nothing else in the repo runs
goreleaser releaseor reads GitHub releases; the CLI's update check reads the CDN pointer.
Caller impact: none. This is CI/release-only, with no API or CLI surface change.
— tai2
| releases="$(gh api --paginate "repos/${repo}/releases" \ | ||
| --jq ".[] | select(.tag_name == \"${tag}\") | \"\(.id) \(.draft)\"")" | ||
|
|
||
| while read -r id draft; do | ||
| [[ -z "$id" ]] && continue | ||
| if [[ "$draft" != "true" ]]; then | ||
| echo "::error::${tag} already has a published release; leaving it and the tag in place. See RELEASE.md, 'If the release fails'." | ||
| exit 1 | ||
| fi | ||
| done <<<"$releases" |
There was a problem hiding this comment.
Low: draft deletion has no provenance check. The tag gets three ownership checks, but every draft whose tag_name matches is deleted, whoever made it. GoReleaser's draft is always authored by github-actions[bot] (as are all five latest releases here), so a draft by anyone else can't be this run's.
Two ways this deletes a person's work:
- The tag-never-pushed path still deletes drafts. If
git pushfailed, GoReleaser never ran, so any draft for that version (for example hand-written notes prepared ahead of the dispatch) belongs to someone else. I ran the script against a fakegh: with tag 404 and drafts11(a person's) and22, it deletes both and exits 0 ("tag v1.2.3 was never pushed; nothing to delete"). - The happy path also deletes a person's draft, alongside this run's.
This also leaves publish-release able to publish the wrong draft. gh release edit resolves a draft through GraphQL release(tagName:), which returns a single release (cli/cli pkg/cmd/release/shared/fetch.go). If two drafts share the tag, which one wins is GitHub's pick; I haven't verified which.
Suggested fix: refuse, like the published case, when a draft wasn't made by the workflow. With the fake gh, this version stops without deleting anything when a person's draft is present, still deletes a workflow-only draft and then the tag, and still refuses on a published release:
| releases="$(gh api --paginate "repos/${repo}/releases" \ | |
| --jq ".[] | select(.tag_name == \"${tag}\") | \"\(.id) \(.draft)\"")" | |
| while read -r id draft; do | |
| [[ -z "$id" ]] && continue | |
| if [[ "$draft" != "true" ]]; then | |
| echo "::error::${tag} already has a published release; leaving it and the tag in place. See RELEASE.md, 'If the release fails'." | |
| exit 1 | |
| fi | |
| done <<<"$releases" | |
| releases="$(gh api --paginate "repos/${repo}/releases" \ | |
| --jq ".[] | select(.tag_name == \"${tag}\") | \"\(.id) \(.draft) \(.author.login)\"")" | |
| while read -r id draft author; do | |
| [[ -z "$id" ]] && continue | |
| if [[ "$draft" != "true" ]]; then | |
| echo "::error::${tag} already has a published release; leaving it and the tag in place. See RELEASE.md, 'If the release fails'." | |
| exit 1 | |
| fi | |
| if [[ "$author" != "github-actions[bot]" ]]; then | |
| echo "::error::draft release ${id} for ${tag} was made by ${author}, not a workflow; leaving it and the tag in place" | |
| exit 1 | |
| fi | |
| done <<<"$releases" |
The delete loop below (while read -r id _) works unchanged with the third field.
There was a problem hiding this comment.
Took this further than the author check. Each draft now carries this run's ID in its body (GoReleaser release.header), the release job records that draft's ID, publish-release publishes by that ID instead of by tag, and cleanup deletes only drafts with this run's marker. Any other release for the tag stops it, and with no tag pushed it deletes nothing. In c350ac6 and c8bea45.
…ever pushed Co-Authored-By: Claude Opus 5.5 <[email protected]>
…draft Co-Authored-By: Claude Opus 5.5 <[email protected]>
terencechotai2-commits
left a comment
There was a problem hiding this comment.
Re-review at c8bea45 (the two commits since 221356e). My earlier Low is resolved, and the marker design holds up. No findings beyond one nit.
Verified
- The marker reaches the draft with the pinned GoReleaser. In v2.18.2,
internal/pipe/release/body.gorendersrelease.headerthroughtmpl.Applyand puts it first in the body, andenvOrDefaultis a registered template func (internal/tmpl/tmpl.go:301). Body truncation (client.go:180) cuts from the end, so the header at the top survives long changelogs.goreleaser-checkpasses at this head. - No new draft-reuse paths. GoReleaser 2.18.2's
findReleaseusesGetReleaseByTagunlessuse_existing_draftis set, and that endpoint can't see drafts, so every run creates its own draft and never adopts another run's. - I walked
find-run-draft.shandcleanup-failed-release.shagainst fixture release JSON, using a fakeghthat applies the scripts' own--jqfilters with realjq, for run 123:
| Releases for the tag | find-run-draft | cleanup |
|---|---|---|
| this run's draft only | 1 |
deletes 1, then the leased tag push |
this run's + drafts from runs 12 and 1234 |
1 (no prefix/suffix confusion; the closing --> anchors it) |
refuses, deletes nothing |
| this run's + a draft for a different tag | 1 |
deletes only 1 |
draft without the marker / with a null body |
fails "found: none" | refuses |
| two drafts carrying this run's marker (re-run attempt) | fails | deletes both, then the tag (self-heals) |
| this run's release already published | fails | refuses |
| tag never pushed, no releases | n/a | deletes nothing, exit 0 |
- Publishing by ID is right.
PATCH releases/{id}with-F draft=falsesends a real boolean, so only the recorded draft can be published, and re-runningpublish-releaseon an already-published release is harmless. Assigningrelease_idbefore theechomeans a failed lookup fails the step, which then sends the run to cleanup. Cleanup deletes this run's draft by marker, so the case where GoReleaser succeeded but the lookup failed also unwinds cleanly.
Nit (non-blocking): with the tag never pushed and someone else's draft for the version present, cleanup now exits 1 with "leaving it and the tag in place". There is no tag, and nothing was this run's to clean. Checking tag_exists before the foreign-draft refusal (cleanup-failed-release.sh:56) would let that case exit 0 the way the "never pushed" branch intends. The current behaviour is safe either way; it only turns the cleanup job red.
Caller impact: none. This is CI/release-only.
— tai2
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at c8bea458. find-run-draft.sh and the marker check in cleanup-failed-release.sh hold up. tai2's re-review already covers the lease, the GoReleaser header and the draft-reuse path, so this adds only what I checked separately.
Reproduced on my side
- Both scripts against fixture releases. I ran them through a fake
ghthat applies their own--jqfilters, for run 123. Results:find-run-draft.shreturns exactly this run's draft. It ignores drafts from runs12and1234, anullbody, and the same marker on another tag. It fails with no match, with two matches, or when the only marked release is already published.- Cleanup deletes only this run's drafts and then the tag. It refuses a published release, another run's draft, a draft with no marker, a lightweight tag, a wrong run ID and a wrong commit, and it exits 0 when no tag was pushed.
- It deletes drafts before the tag. A cleanup that stops partway therefore leaves the tag in place, which blocks a fresh dispatch, while a re-run of the cleanup itself is safe.
- The leased tag delete, with real git. I pushed from a clone that had neither the commit nor the tag object. A lease naming the commit sha was rejected as stale and the tag survived. A lease naming the tag object deleted it. Git doesn't need the object locally to compare the lease.
Additive
- No tag rule blocks the cleanup's delete. The only ruleset on the repo is the org-wide "Enforce Signed Commits", which targets branches. So nothing stops
GITHUB_TOKENfrom deleting the tag, and the unsigned annotated tag the workflow creates is fine. - Publishing by
PATCHmatches what GoReleaser did before. In v2.18.2,PublishReleasesentmake_latestonly fromrelease.make_latest, which this config doesn't set, plus an explicit"false"for prereleases. The newPATCHsends neither. Stable releases get GitHub's default, as before. GitHub can't mark a prerelease as latest anyway, so dev builds don't change either. The name and prerelease flag are set when the draft is created.
Nit: +1 to tai2's. When no tag was pushed and another run's draft exists, cleanup exits red with nothing to clean. My fixture run shows the same.
— Rames
Scope
Surfaces: Release workflows | Module: Build / release pipeline
Summary
A stable or dev release that failed after pushing its tag left the tag behind, and sometimes a half-made GitHub release, so the next dispatch stopped at "tag already exists" until someone deleted things by hand. Releases now recover on their own: a failed build is cleaned up automatically, and a failure after the release is public is retried, never deleted.
How it works
The spine is a draft boundary. GoReleaser now always creates the GitHub release as a draft, and a separate job publishes it. Everything before publication can be undone safely; nothing after it is ever undone.
releasecleanup-failed-releasereleasefailed or was cancelled after the tag pushpublish-releasereleasesucceededpublish-cdn(stable)checksums.txtbefore uploadingThe cleanup decides from the repository's actual state, and only deletes what it can prove the run created:
Design decisions
A job, not a step, does the cleanup. A cancelled job skips its remaining steps, but a dependent job with
always()still runs, and it still receives the cancelled job's outputs. Both were checked on GitHub with throwaway workflows: a cancelled job's output reached the cleanup job, and re-running only the cleanup job reused the original run's outputs.Drafts, so cleanup never races a publish. Without them the cleanup could find a release that GoReleaser was in the middle of publishing and delete a release users could already see. With them, nothing in the pipeline publishes until
releasehas succeeded, and cleanup only runs when it has not.Drafts carry provenance too. GoReleaser writes
<!-- release-run: <run id> -->at the top of every draft's notes. The release job looks up the one draft carrying it and records its ID;publish-releasepublishes by that ID rather than by tag, and cleanup deletes only drafts carrying it. Replacing the notes after publishing drops the marker, which no longer matters by then.Annotated tags carry provenance. A commit match alone could not tell this run's tag from one someone else pushed at the same commit in the same window. The run ID in the tag message can.
Stable releases run one at a time. Workflow-level concurrency keeps a failed run's cleanup from overlapping another run. GitHub keeps only the newest waiting run, so dispatching twice while one is running drops the middle one.
A published release is never deleted automatically. If one exists when cleanup runs, someone published it by hand, and only a person should decide what happens to it. RELEASE.md says how. One residual is accepted: GitHub cannot delete a release only if it is still a draft, so a person publishing a failed run's draft in the seconds between cleanup's check and its delete would lose it. Nobody publishes these drafts by hand.
Testing
v0.9.0(a lightweight tag) is refused; an annotated tag with the wrong run ID or the wrong commit is refused; an API error stops it.v0.9.0release, the CDN job's download fetches exactly the six archives andchecksums.txtthe old upload used, and all verify.goreleaser checkpasses withdraft: trueand the run-marker header; snapshot builds pass with and withoutGITHUB_RUN_ID. The draft lookup refuses on the realv0.9.0(no draft), and the marker filter matches run 42 exactly, not 421.dist/is now in.gitignore, since a local GoReleaser run writes it.publish-releaseandpublish-cdn.🤖 Generated with Claude Code