Skip to content

ci: recover from a failed release without a stranded tag - #427

Merged
somanshreddy merged 3 commits into
mainfrom
10-07-release_tag_recovery
Oct 7, 2026
Merged

somanshreddy merged 3 commits into
mainfrom
10-07-release_tag_recovery

Conversation

@somanshreddy

@somanshreddy somanshreddy commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

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.

Job Runs when On failure
release dispatched tag, tests, GoReleaser, and recording this run's draft ID; leaves at most a draft
cleanup-failed-release release failed or was cancelled after the tag push deletes this run's draft and tag, so you dispatch again
publish-release release succeeded publishes that exact draft by ID; on failure the draft stays invisible, so re-run the job
publish-cdn (stable) the release is public re-run the job; it re-downloads the release's own assets and verifies them against its checksums.txt before uploading

The cleanup decides from the repository's actual state, and only deletes what it can prove the run created:

  • the tag must be annotated, its message must name this run's ID, and it must point at the commit this run tagged;
  • only drafts carrying this run's marker are deleted; a published release, or a draft from anyone else, stops it for a person;
  • with no tag pushed, it deletes nothing, since GoReleaser only runs after the push;
  • any API answer other than a clear 404 stops it without deleting;
  • the tag is deleted with a leased push, so a tag replaced since the check survives.

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 release has 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-release publishes 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

  • Every non-deleting path of the cleanup script was run against real tags: a never-pushed tag no-ops; our published 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.
  • The leased tag delete was run against a local bare repository: rejected as stale when the tag had been replaced, deleted when it matched.
  • Against the real v0.9.0 release, the CDN job's download fetches exactly the six archives and checksums.txt the old upload used, and all verify.
  • goreleaser check passes with draft: true and the run-marker header; snapshot builds pass with and without GITHUB_RUN_ID. The draft lookup refuses on the real v0.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.
  • actionlint is clean.
  • Not run: the deleting paths of the cleanup script and the draft-to-publish transition on GitHub itself, which would need throwaway releases in this repository. The first real release exercises publish-release and publish-cdn.

🤖 Generated with Claude Code

@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.

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.

  • 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 equal Release ${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-release needs release to 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 before push_attempted is 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 both failure and cancelled. push_attempted is written before git 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-cdn is down to contents: read plus id-token: write.

  • #426's pinned GoReleaser works with draft mode. install-goreleaser.sh pins v2.18.2, and release.draft is a long-standing v2 option. The PR's goreleaser-check CI job passes with draft: true.

  • gh release edit --draft=false finds drafts. FetchRelease falls back to a GraphQL release(tagName:) lookup for drafts.

  • No other consumer. Nothing else in the repo runs goreleaser release or 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

Comment on lines +44 to +53
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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 push failed, 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 fake gh: with tag 404 and drafts 11 (a person's) and 22, 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:

Suggested change
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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@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 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.go renders release.header through tmpl.Apply and puts it first in the body, and envOrDefault is 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-check passes at this head.
  • No new draft-reuse paths. GoReleaser 2.18.2's findRelease uses GetReleaseByTag unless use_existing_draft is 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.sh and cleanup-failed-release.sh against fixture release JSON, using a fake gh that applies the scripts' own --jq filters with real jq, 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=false sends a real boolean, so only the recorded draft can be published, and re-running publish-release on an already-published release is harmless. Assigning release_id before the echo means 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 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 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 gh that applies their own --jq filters, for run 123. Results:
    • find-run-draft.sh returns exactly this run's draft. It ignores drafts from runs 12 and 1234, a null body, 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_TOKEN from deleting the tag, and the unsigned annotated tag the workflow creates is fine.
  • Publishing by PATCH matches what GoReleaser did before. In v2.18.2, PublishRelease sent make_latest only from release.make_latest, which this config doesn't set, plus an explicit "false" for prereleases. The new PATCH sends 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

@somanshreddy
somanshreddy merged commit 39ee311 into main Oct 7, 2026
10 checks passed
@somanshreddy
somanshreddy deleted the 10-07-release_tag_recovery branch October 7, 2026 22:23
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