@@ -168,10 +168,9 @@ jobs:
168168 echo "That should not happen on the default branch with an explicit bump." >&2
169169 exit 1
170170 fi
171- # A courtesy check, not the guard. It turns a name that is already
172- # taken into a readable error rather than a raw API failure. Claiming
173- # the ref below is what actually settles the name. The call stays out
174- # of an `if` so that a failure of the check itself stops the run.
171+ # A courtesy check, not the guard: claiming the ref below settles
172+ # the name. Kept out of an `if` so a failure of the check itself
173+ # stops the run.
175174 matches=$(gh api "repos/${GITHUB_REPOSITORY}/git/matching-refs/tags/${TAG}" \
176175 --jq '[.[] | select(.ref == "refs/tags/" + env.TAG)] | length')
177176 if [ "${matches}" != "0" ]; then
@@ -184,42 +183,33 @@ jobs:
184183 # taken, the release call publishes against whatever commit that tag
185184 # points at, and immutability makes that permanent.
186185 #
187- # Claiming first leaves the tag briefly unlocked, and one left
188- # behind makes the next dispatch skip this version number. So the
189- # cleanup is armed before the claim, and acts only on a claim that
190- # returned. Ownership is recorded rather than read back off the tag,
191- # because a tag that beat us to the name is almost always at this
192- # same commit: every run targets the default-branch tip.
186+ # Claiming first leaves the tag briefly unlocked, so a run that stops
187+ # in between has to remove it, or the next dispatch skips this
188+ # version number. Three things decide whether removing it is safe,
189+ # and dropping any one of them deletes a tag this run does not own:
193190 #
194- # What is left is the one statement between the claim landing and
195- # `claimed=1`, and it fails the safe way. A stray tag costs a version
196- # number, a wrong delete costs a release.
191+ # claimed this run created the tag. The commit cannot say so,
192+ # because a tag that beat us to the name is almost
193+ # always at this same default-branch tip.
194+ # unmoved nobody re-pointed it since. `claimed` cannot say so.
195+ # no release absence confirmed by a listing that succeeded, not
196+ # inferred from a lookup that failed. The release call
197+ # can land while this run dies, so the tag may already
198+ # be locked.
197199 #
198- # An EXIT trap covers a cancelled job as well as a failed command,
199- # though not a SIGKILL.
200+ # The trap is armed before the claim, leaving one statement in which
201+ # a kill strands the tag. That is the safe direction: a stray tag
202+ # costs a version number, a wrong delete costs a release. An EXIT
203+ # trap covers a cancelled job, though not a SIGKILL.
200204 claimed=0
201205 cleanup() {
202206 [ "${claimed}" = 1 ] || return 0
203207 local ref_sha releases
204- # Both conditions are load-bearing and neither replaces the other.
205- # `claimed` answers whether this run created the tag, which the
206- # commit cannot: a tag that beat us to the name is almost always
207- # at this same commit. The commit answers whether anyone has moved
208- # the tag since, which `claimed` cannot. Dropping either one makes
209- # this destroy a tag it does not own.
210208 ref_sha=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG}" --jq .object.sha 2>/dev/null) || return 0
211209 if [ "${ref_sha}" != "${COMMIT}" ]; then
212210 return 0
213211 fi
214- # The release call can land while this run dies before clearing
215- # the trap, so a tag of ours can already be locked. Listing
216- # answers "no release" with an empty result and a success, which
217- # tells a confirmed absence apart from a lookup that failed.
218- # Asking for the release by tag reports both the same way, and
219- # deleting on an unconfirmed absence would strip the tag off a
220- # release that did publish. One page is enough, newest first, and
221- # it keeps this to a bounded number of calls inside whatever
222- # grace period a cancelled job gets.
212+ # Newest first, so a release made seconds ago is on the first page.
223213 releases=$(gh api "repos/${GITHUB_REPOSITORY}/releases?per_page=100" \
224214 --jq '.[] | select(.tag_name == env.TAG) | .id') || return 0
225215 if [ -n "${releases}" ]; then
0 commit comments