Repository navigation
ci: cleanup exits cleanly when the tag was never pushed - #430
Conversation
55a202c to
6b2d874
Compare
terencechotai2-commits
left a comment
There was a problem hiding this comment.
Reviewed at 6b2d874. No blocking findings. The 404 handling fails closed everywhere I could reach.
Order of checks. The tag ref is read first. Only a tag answer containing HTTP 404 goes on to the repo probe, and only a successful probe exits 0. Every other answer, from either call, lands in the else and exits 1 without deleting anything. Both calls sit inside the elif condition, so set -e can't cut that short.
Run read-only against the real API. I wrapped gh so it refuses -X, -f, -F and --input, and replaced git with a stub that refuses everything:
| case | result |
|---|---|
heygen-com/heygen-cli, tag never pushed |
exit 0, "nothing to delete" |
heygen-com/no-such-repo-xyz (a repo the token can't see) |
exit 1, "could not tell whether … exists" |
| repo in another org the token can't see | exit 1 |
existing lightweight v0.9.0 |
exit 1, not annotated |
renamed repo (docker/docker → moby/moby), missing tag |
exit 0. gh follows the 301 on both calls, and an existing tag also resolves through the redirect |
case-mismatched HeyGen-Com/HeyGen-CLI |
exit 0 |
Simulated failures. A fake gh returned a chosen status for each call. These all exit 1:
- Tag call: 401; 403 rate limit; 403 "Resource not accessible by integration"; 429 secondary rate limit; 502; a network error. In every case the repo probe answered 200.
- Repo probe, after a tag 404: 404, 401, 403 (both kinds), 429, 502, and a network error.
So a forbidden or unreachable repo, a token missing a scope, and rate limits all fail closed.
Mutation. Dropping the && gh api "repos/${repo}" probe makes the nonexistent-repo case exit 0 again. That's the regression your description mentions, and it confirms the probe is what prevents it.
Unchanged behaviour on the tag-404 path. Both before and after this PR, the tag-404 path ends before the delete loop. So the only change is that a foreign or published release for the version no longer turns the job red when there's no tag. The release job is already red in that case, so no signal is lost.
Notes, none blocking:
- Unverified: the repo probe proves the repo is visible, not that the token can read refs. A token with metadata-only access could, in principle, get a 404 on the ref while the repo answers. That can't happen here: both workflows give this job
contents: write. - Nit: there's no automated test for the script, so the tag-404 vs repo-404 split is covered only by the manual runs in the description. Your stub-
ghpattern is small enough to put in CI: a fakeghonPATHreturning a chosen status per endpoint, asserting the exit code. It would lock in the probe the mutation shows matters. - Nit: when the repo probe fails, the log shows the probe's own error and then the tag's 404 output. "could not tell whether … exists" is still correct, but "the repository did not answer" would point at the cause faster.
No API surface change, so the caller-impact rule doesn't apply here.
— tai2
jrusso1020
left a comment
There was a problem hiding this comment.
Approving at 6b2d874a. tai2 already covered the check order, set -e inside the elif, the per-status failure table and the mutation, so I won't repeat them. My additions: a side-by-side of the old and new scripts, and one stale comment.
Old vs new, same fixtures. I ran origin/main's script and this head through one fake-gh matrix: 15 cases, each script. The fake answers a chosen status per endpoint, and every -X DELETE or git push is logged. Only two rows change, and both are intended:
| Case | main |
this PR |
|---|---|---|
| tag 404, repo answers, published or foreign draft for the version | exit 1 | exit 0, no deletes (the fix) |
| tag 404, repo 404 / 401 / 403 / network error | exit 0 | exit 1, no deletes (the guard) |
| tag 404, repo answers, our draft or no release | exit 0, no deletes | same |
| tag 401 / 403 / 500 / network error | exit 1, repo never probed | same |
| our annotated tag + our draft | exit 0, 2 deletes (draft, leased tag push) | same |
| our tag + published release; lightweight tag | exit 1, no deletes | same |
No TOCTOU on the no-tag path. It only reads: one GET for the ref and one for the repo, then exit 0 before the release listing. It can't reach a delete, so a tag that appears after the check is left alone, not removed. The tag-present path is unchanged and still leased (--force-with-lease=refs/tags/<tag>:<object>). Both workflows call this one script (release-stable.yml:151, dev-release.yml:111) with contents: write. The repo is public, so tai2's metadata-only case can't come up.
Nit (non-blocking): the header at lines 11-12 still says "Any API answer other than a clear 404 stops it too". Now a 404 also needs the repository to answer. Something like "other than a 404 for the tag in a repository that answers" would keep the comment in line with the guard.
+1 to tai2's suggestion to put the stub-gh matrix in CI. The two changed rows above are exactly what it would pin.
— Rames
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
6b2d874 to
a884e83
Compare
jrusso1020
left a comment
There was a problem hiding this comment.
Re-approving at a884e835. My earlier approval was at 6b2d874a.
Rebase. git range-diff shows 6b2d874 and ebbdb1c are the same patch. The only other base change is the AGENTS.md move (#368), which doesn't touch this script.
The new commit only changes text. I diffed the script against the version I tested last round. Two things changed:
- Header, lines 11-12: fixed. It no longer says a bare 404 is enough. "A missing tag means nothing to do" matches the code: the 404 path exits 0 only after the repository probe answers.
- Error message, line 44. It now names both causes, and those are exactly the two ways into the
elsebranch: the tag lookup failed with something other than a 404, or it got a 404 and the repository probe failed.
No code changed, the workflows weren't touched, and bash -n passes. So the 15-case old-vs-new matrix from my last review still holds.
— Rames
Scope
Surfaces: Release workflows | Module: Build / release pipeline
Summary
When a release failed before its tag was pushed, and some other draft or published release existed for that version, the cleanup job from #427 went red with "leaving it and the tag in place" even though there was no tag and nothing to clean up. It now exits cleanly in that case. Both reviewers of #427 raised it as a nit.
Fix
The cleanup checks the tag first. If the tag does not exist, nothing for that version can be this run's (GoReleaser only runs after the push), so it now stops there with "nothing to delete" instead of going on to judge other releases for the version. Nothing is deleted on this path, before or after the change.
One guard came with it: GitHub also returns 404 for a repository the token cannot see, so a 404 counts as "no tag" only once the repository itself answers. Otherwise the script still exits 1 without deleting, as before.
Testing
Against the real repository: a never-pushed tag exits 0; the existing lightweight
v0.9.0is still refused; a nonexistent repository still fails ("could not tell whether ... exists") rather than reporting success. That last case regressed to exit 0 in the first version of this change, which is why the repository check exists.bash -n, actionlint andmake lintpass.🤖 Generated with Claude Code