Skip to content

Commit d81b758

Browse files
author
bcode
committed
ci(release): resolve tag SHA explicitly for workflow_dispatch correctness
Cubic review on PR #40: \GITHUB_SHA\ is the SHA of the ref that triggered the workflow, not necessarily the selected tag's commit. For push: tags they're equivalent, but for workflow_dispatch with inputs.tag, GITHUB_SHA is the dispatch ref's HEAD (typically main) — letting any feature-branch tag pass the ancestry check trivially. Fix: resolve refs/tags/\^{commit} via git rev-parse and ancestry- check that. Fails loudly with an actionable message if the tag doesn't exist yet (the workflow_dispatch path's failure mode for a fresh tag should be 'create the tag deliberately first', not 'silently tag at checkout HEAD').
1 parent 6ce5840 commit d81b758

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,22 @@ jobs:
6969
# (not into main); main moved on without it and the bcode-laminar
7070
# package had to be re-landed in PR #39. This guard fails the release
7171
# before any binaries are uploaded.
72+
#
73+
# Resolves the tag name to a commit SHA via `git rev-parse` rather than
74+
# using `$GITHUB_SHA`. For `push: tags` the two are equivalent, but for
75+
# `workflow_dispatch` with `inputs.tag` `$GITHUB_SHA` is the dispatch
76+
# ref's HEAD (typically main), not the selected tag's commit — using it
77+
# would let a feature-branch tag pass the check trivially.
78+
env:
79+
TAG: ${{ steps.ver.outputs.tag }}
7280
run: |
7381
git fetch origin main --depth=1
74-
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/main; then
75-
echo "::error::Tag ${GITHUB_REF#refs/tags/} points at $GITHUB_SHA which is not reachable from origin/main. Release tags must be cut from main."
82+
TAG_SHA=$(git rev-parse -q --verify "refs/tags/${TAG}^{commit}") || {
83+
echo "::error::Tag ${TAG} does not exist locally. Create the tag on a main commit first (e.g. \`gh release create ${TAG} --target main\`), then re-run."
84+
exit 1
85+
}
86+
if ! git merge-base --is-ancestor "$TAG_SHA" origin/main; then
87+
echo "::error::Tag ${TAG} points at $TAG_SHA which is not reachable from origin/main. Release tags must be cut from main."
7688
exit 1
7789
fi
7890

0 commit comments

Comments
 (0)