Skip to content

Commit 81e4084

Browse files
claudeghosthack
authored andcommitted
Release on v#.#.# tag push instead of pom version change
CI detected a release by comparing pom.xml with HEAD~1, which misses version bumps whenever a merge lands more than one commit (as happened with 4.0.0). Publishing is now triggered by pushing a vX.Y.Z tag: the Release workflow checks the tag matches the pom.xml version and is on master, deploys to Maven Central, then creates the GitHub release. CI keeps only the build matrix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TXEoEctMzFSoGuySUsqtBJ
1 parent c14ad94 commit 81e4084

3 files changed

Lines changed: 40 additions & 70 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,3 @@ jobs:
2727
- name: Build and test
2828
run: mvn -B verify
2929

30-
release:
31-
needs: build
32-
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
33-
runs-on: ubuntu-latest
34-
35-
outputs:
36-
changed: ${{ steps.version.outputs.changed }}
37-
38-
steps:
39-
- uses: actions/checkout@v7
40-
with:
41-
fetch-depth: 2
42-
43-
- name: Check for version change
44-
id: version
45-
run: |
46-
CURRENT=$(grep -m1 '<version>' pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
47-
PREVIOUS=$(git show HEAD~1:pom.xml | grep -m1 '<version>' | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
48-
echo "current=$CURRENT" >> "$GITHUB_OUTPUT"
49-
echo "previous=$PREVIOUS" >> "$GITHUB_OUTPUT"
50-
if [ "$CURRENT" != "$PREVIOUS" ] && [[ "$CURRENT" != *SNAPSHOT* ]]; then
51-
echo "changed=true" >> "$GITHUB_OUTPUT"
52-
else
53-
echo "changed=false" >> "$GITHUB_OUTPUT"
54-
fi
55-
56-
- name: Create GitHub release
57-
if: steps.version.outputs.changed == 'true'
58-
env:
59-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
60-
run: |
61-
VERSION=${{ steps.version.outputs.current }}
62-
gh release create "v${VERSION}" \
63-
--target master \
64-
--title "${VERSION}" \
65-
--generate-notes
66-
67-
deploy:
68-
needs: release
69-
if: needs.release.outputs.changed == 'true'
70-
runs-on: ubuntu-latest
71-
72-
steps:
73-
- uses: actions/checkout@v7
74-
75-
- name: Set up JDK 21
76-
uses: actions/setup-java@v6
77-
with:
78-
java-version: 21
79-
distribution: temurin
80-
cache: maven
81-
server-id: central
82-
server-username: MAVEN_CENTRAL_USERNAME
83-
server-password: MAVEN_CENTRAL_PASSWORD
84-
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
85-
gpg-passphrase: GPG_PASSPHRASE
86-
87-
- name: Deploy to Maven Central
88-
run: mvn -B clean deploy -P release
89-
env:
90-
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
91-
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
92-
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

‎.github/workflows/release.yml‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,35 @@
11
name: Release
22

3+
# Publishes to Maven Central when a version tag is pushed:
4+
# git tag v4.0.0 && git push origin v4.0.0
35
on:
4-
release:
5-
types: [ published ]
6-
workflow_dispatch:
6+
push:
7+
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]
8+
9+
permissions:
10+
contents: write
711

812
jobs:
9-
deploy:
13+
release:
1014
runs-on: ubuntu-latest
1115

1216
steps:
1317
- uses: actions/checkout@v7
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Check tag matches pom.xml and is on master
22+
run: |
23+
TAG_VERSION="${GITHUB_REF_NAME#v}"
24+
POM_VERSION=$(grep -m1 '<version>' pom.xml | sed 's/.*<version>\(.*\)<\/version>.*/\1/')
25+
if [ "$TAG_VERSION" != "$POM_VERSION" ]; then
26+
echo "::error::Tag $GITHUB_REF_NAME does not match pom.xml version $POM_VERSION"
27+
exit 1
28+
fi
29+
if ! git merge-base --is-ancestor "$GITHUB_SHA" origin/master; then
30+
echo "::error::Tag $GITHUB_REF_NAME points to a commit that is not on master"
31+
exit 1
32+
fi
1433
1534
- name: Set up JDK 21
1635
uses: actions/setup-java@v6
@@ -30,3 +49,12 @@ jobs:
3049
MAVEN_CENTRAL_USERNAME: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
3150
MAVEN_CENTRAL_PASSWORD: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
3251
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
52+
53+
- name: Create GitHub release
54+
env:
55+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
run: |
57+
gh release create "$GITHUB_REF_NAME" \
58+
--verify-tag \
59+
--title "${GITHUB_REF_NAME#v}" \
60+
--generate-notes

‎README.md‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,14 @@ post("/upload", new Action() {
333333

334334
## Releasing
335335

336-
1. Set the release version in `pom.xml` (remove `-SNAPSHOT`)
337-
2. Commit, push, and merge via PR
338-
3. CI detects the version change, creates a GitHub release, and deploys to Maven Central
336+
1. Set the release version in `pom.xml` (remove `-SNAPSHOT`) and merge it to `master` via PR
337+
2. Tag the merged commit on `master` and push the tag:
338+
```sh
339+
git tag v4.0.0
340+
git push origin v4.0.0
341+
```
342+
3. The Release workflow checks that the tag matches the `pom.xml` version and is on
343+
`master`, deploys to Maven Central, and creates the GitHub release
339344
4. Publish the deployment at https://central.sonatype.com/publishing/deployments
340345

341346
## License

0 commit comments

Comments
 (0)