11# Workflow: Release and publish artifacts to Maven Central
22# Purpose: Builds, signs, and publishes Maven artifacts to Sonatype OSSRH, then tags the released version.
33# Prerequisites: pom.xml must be on a *-SNAPSHOT version; We need to change logic for non-SNAPSHOT versions.
4- # Notes: Adjust version computation logic if patch releases are desired instead of minor bumps (e.g., 1.2.3-SNAPSHOT to 1.3.0-SNAPSHOT).
4+ # Notes:
5+ # - release/* branches: major version increment (e.g., 1.2.3-SNAPSHOT to 2.0.0-SNAPSHOT)
6+ # - hotfix/* branches: minor version increment (e.g., 1.2.3-SNAPSHOT to 1.3.0-SNAPSHOT)
7+ # Adjust version computation logic if patch releases are desired instead of minor bumps (e.g., 1.2.3-SNAPSHOT to 1.3.0-SNAPSHOT).
58
69name : " Release and publish artifacts to Maven Central"
710
1619 push :
1720 branches :
1821 - ' release/*'
22+ - ' hotfix/*'
1923
2024permissions :
2125 contents : write
@@ -28,10 +32,10 @@ jobs:
2832 - name : Checkout repo
2933 uses : actions/checkout@v6
3034 with :
31- token : ${{ secrets.GITHUB_TOKEN }} # or use default GITHUB_TOKEN
32- persist-credentials : true # allow git push from the job
33- fetch-depth : 0 # full history so branch refs exist
34- ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} # checkout the branch (not a detached SHA)
35+ token : ${{ secrets.GITHUB_TOKEN }}
36+ persist-credentials : true
37+ fetch-depth : 0
38+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
3539
3640 - name : Set up JDK
3741 uses : actions/setup-java@v5
@@ -69,11 +73,28 @@ jobs:
6973 TAG="v${releaseVersion}"
7074 echo "TAG=$TAG" >> $GITHUB_ENV
7175
76+ # Extract branch name
77+ BRANCH_NAME="${{ github.ref_name }}"
78+ echo "Branch name: $BRANCH_NAME"
79+
7280 # Extract numeric components for computing next development version
7381 n=${releaseVersion//[!0-9]/ }
7482 a=(${n//\./ })
75- nextMinor=$((${a[1]} + 1))
76- developmentVersion="${a[0]}.${nextMinor}.0-SNAPSHOT"
83+
84+ # Determine version increment based on branch name
85+ if [[ "$BRANCH_NAME" == release/* ]]; then
86+ # Major version increment for release branches
87+ nextMajor=$((${a[0]} + 1))
88+ developmentVersion="${nextMajor}.0.0-SNAPSHOT"
89+ echo "Branch type: Release - Incrementing major version: ${releaseVersion} → ${developmentVersion}"
90+ elif [[ "$BRANCH_NAME" == hotfix/* ]]; then
91+ # Minor version increment for hotfix branches
92+ currentMajor=${a[0]}
93+ nextMinor=$((${a[1]} + 1))
94+ developmentVersion="${currentMajor}.${nextMinor}.0-SNAPSHOT"
95+ echo "Branch type: Hotfix - Incrementing minor version: ${releaseVersion} → ${developmentVersion}"
96+ fi
97+
7798 echo "DEVELOPMENT_VERSION=${developmentVersion}" >> $GITHUB_ENV
7899
79100 - name : Configure GitHub authentication for Maven Release Plugin
0 commit comments