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
1720 push :
1821 branches :
1922 - ' release/*'
23+ - ' hotfix/*'
2024
2125permissions :
2226 contents : write
@@ -29,13 +33,11 @@ jobs:
2933 steps :
3034 - name : Checkout repo
3135 uses : actions/checkout@v4
32- # added with option due to runner checking out a detached HEAD state in prepare step
33- # TODO: need to check if its happening as workflow is triggered from PR or even with workflow dispatch in main branch
3436 with :
35- token : ${{ secrets.GITHUB_TOKEN }} # or use default GITHUB_TOKEN
36- persist-credentials : true # allow git push from the job
37- fetch-depth : 0 # full history so branch refs exist
38- ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }} # checkout the branch (not a detached SHA)
37+ token : ${{ secrets.GITHUB_TOKEN }}
38+ persist-credentials : true
39+ fetch-depth : 0
40+ ref : ${{ github.event_name == 'pull_request' && github.head_ref || github.ref_name }}
3941
4042 - name : Set up JDK
4143 uses : actions/setup-java@v4
@@ -70,12 +72,29 @@ jobs:
7072 TAG="v${releaseVersion}"
7173 echo "TAG=$TAG" >> $GITHUB_ENV
7274
75+ # Extract branch name
76+ BRANCH_NAME="${{ github.ref_name }}"
77+ echo "Branch name: $BRANCH_NAME"
78+
7379 # Extract numeric components for computing next development version
7480 n=${releaseVersion//[!0-9]/ }
7581 a=(${n//\./ })
76- nextMinor=$((${a[1]} + 1))
77- developmentVersion="${a[0]}.${nextMinor}.0-SNAPSHOT"
78- echo "DEVELOPMENT_VERSION=${developmentVersion}" >> $GITHUB_ENV
82+
83+ # Determine version increment based on branch name
84+ if [[ "$BRANCH_NAME" == release/* ]]; then
85+ # Major version increment for release branches
86+ nextMajor=$((${a[0]} + 1))
87+ developmentVersion="${nextMajor}.0.0-SNAPSHOT"
88+ echo "Branch type: Release - Incrementing major version: ${releaseVersion} → ${developmentVersion}"
89+ elif [[ "$BRANCH_NAME" == hotfix/* ]]; then
90+ # Minor version increment for hotfix branches
91+ currentMajor=${a[0]}
92+ nextMinor=$((${a[1]} + 1))
93+ developmentVersion="${currentMajor}.${nextMinor}.0-SNAPSHOT"
94+ echo "Branch type: Hotfix - Incrementing minor version: ${releaseVersion} → ${developmentVersion}"
95+ fi
96+
97+ echo "DEVELOPMENT_VERSION=${developmentVersion}" >> $GITHUB_ENV
7998
8099 - name : Configure GitHub authentication for Maven Release Plugin
81100 run : |
0 commit comments