55 types :
66 - published
77
8+ permissions :
9+ contents : write
10+ pull-requests : write
11+
812jobs :
913 sonar :
1014 if : " !contains(github.event.head_commit.message, '[version bump]')"
@@ -49,21 +53,23 @@ jobs:
4953 git config user.email "actions@github.com"
5054 git config user.name "GitHub Actions"
5155
52- - name : Get version from POM without SNAPSHOT
56+ - name : Setup release version from tag
5357 run : |
54- VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n"))
55- echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV
56- echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV
57- echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV
58+ RELEASE_TAG="${{ github.event.release.tag_name }}"
59+ NEW_VERSION="${RELEASE_TAG#v}"
60+ echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
5861
59- - name : Setup release version
62+ - name : Validate POM version matches release tag
6063 run : |
61- NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH))"
62- echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
64+ POM_BASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1)
65+ if [ "${POM_BASE_VERSION}" != "${NEW_VERSION}" ]; then
66+ echo "::error::GitHub release tag v${NEW_VERSION} does not match POM version ${POM_BASE_VERSION}-SNAPSHOT. Bump the POM before publishing."
67+ exit 1
68+ fi
6369
6470 - name : Update POM Version
6571 run : |
66- echo "New version is: $NEW_VERSION"
72+ echo "New version is: $NEW_VERSION"
6773 mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false -B
6874
6975 - name : Build and Publish
@@ -90,10 +96,17 @@ jobs:
9096 runs-on : ubuntu-latest
9197 needs : [ publish ]
9298 steps :
99+ - name : Resolve base branch
100+ id : base
101+ run : |
102+ REF="${{ github.event.release.target_commitish }}"
103+ REF="${REF#refs/heads/}"
104+ echo "branch=${REF}" >> $GITHUB_OUTPUT
105+
93106 - name : Checkout Branch
94107 uses : actions/checkout@v6
95108 with :
96- ref : ${{ github.event.release.target_commitish }}
109+ ref : ${{ steps.base.outputs.branch }}
97110
98111 - name : Setup Java
99112 uses : actions/setup-java@v5
@@ -107,17 +120,13 @@ jobs:
107120 git config user.email "actions@github.com"
108121 git config user.name "GitHub Actions"
109122
110- - name : Get version from POM without SNAPSHOT
111- run : |
112- VERSION_PARTS=($(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1 | tr "." "\n"))
113- echo "MAJOR=${VERSION_PARTS[0]}" >> $GITHUB_ENV
114- echo "MINOR=${VERSION_PARTS[1]}" >> $GITHUB_ENV
115- echo "PATCH=${VERSION_PARTS[2]}" >> $GITHUB_ENV
116-
117123 - name : Bump And Update POM Version to new Development version
118124 id : bump_version
119125 run : |
120- NEW_VERSION="$((MAJOR)).$((MINOR)).$((PATCH+1))-SNAPSHOT"
126+ RELEASE_VERSION="${{ github.event.release.tag_name }}"
127+ RELEASE_VERSION="${RELEASE_VERSION#v}"
128+ VERSION_PARTS=($(echo "$RELEASE_VERSION" | tr "." "\n"))
129+ NEW_VERSION="${VERSION_PARTS[0]}.${VERSION_PARTS[1]}.$((VERSION_PARTS[2]+1))-SNAPSHOT"
121130 echo "New development version is: $NEW_VERSION"
122131 mvn versions:set -DnewVersion=${NEW_VERSION} -DgenerateBackupPoms=false
123132 echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
@@ -129,5 +138,5 @@ jobs:
129138 title : " chore: bump version to ${{ steps.bump_version.outputs.new_version }}"
130139 body : " Bumps the version to the next development version."
131140 branch : " chore/bump-version-${{ steps.bump_version.outputs.new_version }}"
132- base : ${{ github.event.release.target_commitish || 'main' }}
141+ base : ${{ steps.base.outputs.branch }}
133142 labels : automerge
0 commit comments