Skip to content

Commit f8a3503

Browse files
jeffjensenclaude
andcommitted
ci(release): Refuse to publish a tag whose commit is not on main
The release workflow triggers on any pushed v* tag, but a tag carries no branch association, so tagging any commit on any branch published to Maven Central. Check out full history and fail the release job unless the tagged commit is an ancestor of origin/main. The guard runs before jdk-setup, so no GPG key or Central credentials are imported for a rejected tag, and because github-release needs the release job, a rejected tag also creates no GitHub Release. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016phSDvM51hkfSYdjcGQrwz
1 parent 6fc6beb commit f8a3503

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,25 @@ jobs:
2525
steps:
2626
- uses: actions/checkout@v7
2727
with:
28+
# Full history so the guard below can test whether the tagged commit is on main.
29+
fetch-depth: 0
2830
persist-credentials: false
2931

32+
# A tag can be pushed from any branch, but only commits on main are released.
33+
# Without this guard, tagging any commit on any branch publishes to Maven
34+
# Central. Runs before jdk-setup so no GPG key or Central credentials are in
35+
# scope if the check fails.
36+
- name: Verify tag is on main
37+
env:
38+
SHA: ${{ github.sha }}
39+
run: |
40+
if git merge-base --is-ancestor "$SHA" origin/main; then
41+
echo "Tagged commit $SHA is on main."
42+
else
43+
echo "::error::Tagged commit $SHA is not on main. Refusing to release."
44+
exit 1
45+
fi
46+
3047
- uses: ./.github/actions/jdk-setup
3148
with:
3249
server-id: central-publish

0 commit comments

Comments
 (0)