@@ -46,16 +46,22 @@ jobs:
4646 use-policy-store : true
4747 api-key : ${{ secrets.STEP_SECURITY_API_KEY }} # zizmor: ignore[secrets-outside-env]
4848
49- # An unrecognised bump does not fail the tag action. It falls back to
50- # reading the commit messages and publishes a version nobody asked for.
49+ # The tag action throws on a bump it does not recognise, which is a
50+ # confusing place to find out. Checked in the shell rather than an `if:`
51+ # because workflow expressions compare case-insensitively, so `Major`
52+ # would clear one and then fail inside the action.
5153 - name : Check the requested bump
52- if : ${{ !contains(fromJSON('["patch", "minor", "major"]'), inputs.bump) }}
5354 env :
5455 BUMP : ${{ inputs.bump }}
5556 run : |
56- echo "The bump has to be patch, minor, or major. This run asked for" >&2
57- echo "'${BUMP}'." >&2
58- exit 1
57+ case "${BUMP}" in
58+ patch | minor | major) ;;
59+ *)
60+ echo "The bump has to be patch, minor, or major. This run asked for" >&2
61+ echo "'${BUMP}'." >&2
62+ exit 1
63+ ;;
64+ esac
5965
6066 # A dispatch can target any branch, and a release cut from a topic branch
6167 # names code that never merged. Immutability makes that permanent.
@@ -187,12 +193,19 @@ jobs:
187193 # An EXIT trap covers a cancelled job as well as a failed command,
188194 # though not a SIGKILL.
189195 cleanup() {
190- local ref_sha
196+ local ref_sha releases
191197 ref_sha=$(gh api "repos/${GITHUB_REPOSITORY}/git/ref/tags/${TAG}" --jq .object.sha 2>/dev/null) || return 0
192198 if [ "${ref_sha}" != "${COMMIT}" ]; then
193199 return 0
194200 fi
195- if gh api "repos/${GITHUB_REPOSITORY}/releases/tags/${TAG}" > /dev/null 2>&1; then
201+ # Listing answers "no release" with an empty result and a success,
202+ # which is what tells a confirmed absence apart from a lookup that
203+ # failed. Asking for the release by tag reports both the same way,
204+ # and deleting on an unconfirmed absence would strip the tag off a
205+ # release that did publish.
206+ releases=$(gh api --paginate "repos/${GITHUB_REPOSITORY}/releases" \
207+ --jq '.[] | select(.tag_name == env.TAG) | .id') || return 0
208+ if [ -n "${releases}" ]; then
196209 return 0
197210 fi
198211 gh api -X DELETE "repos/${GITHUB_REPOSITORY}/git/refs/tags/${TAG}" > /dev/null 2>&1 || true
0 commit comments