1+ name : Hotfix Finish (Gitflow)
2+
3+ on :
4+ workflow_call :
5+ inputs :
6+ hotfix_branch :
7+ description : ' Hotfix branch to finish (e.g., hotfix/2.0.16.1)'
8+ required : true
9+ type : string
10+ merge_to_main :
11+ description : ' Cherry-pick hotfix commits to base branch'
12+ required : false
13+ type : boolean
14+ default : true
15+ runner :
16+ description : ' Runner to use for jobs'
17+ required : false
18+ type : string
19+ default : " ubuntu-24.04"
20+ java_version :
21+ description : ' Java version to use'
22+ required : false
23+ type : number
24+ default : 21
25+ java_distribution :
26+ description : ' Java distribution to use'
27+ required : false
28+ type : string
29+ default : " liberica"
30+ version_tag_prefix :
31+ description : ' Prefix for version tags'
32+ required : false
33+ type : string
34+ default : " v"
35+ artifact_group_id :
36+ description : ' Maven group ID for summary links (e.g., io.entur)'
37+ required : false
38+ type : string
39+ default : " "
40+ artifact_ids :
41+ description : ' Comma-separated artifact IDs for summary links (e.g., my-library,my-cli)'
42+ required : false
43+ type : string
44+ default : " "
45+ base_branch :
46+ description : ' Base branch to cherry-pick changes to (e.g., main, master, develop)'
47+ required : false
48+ type : string
49+ default : " main"
50+ secrets :
51+ SONATYPE_AUTH_USER :
52+ required : true
53+ SONATYPE_AUTH_TOKEN :
54+ required : true
55+ SONATYPE_GPG_KEY_PUBLIC :
56+ required : true
57+ SONATYPE_GPG_KEY :
58+ required : true
59+ SONATYPE_GPG_KEY_PASSWORD :
60+ required : true
61+
62+ jobs :
63+ get-hotfix-version :
64+ runs-on : ${{ inputs.runner || 'ubuntu-24.04' }}
65+ outputs :
66+ version : ${{ steps.get_version.outputs.version }}
67+ steps :
68+ - uses : actions/checkout@v4
69+ with :
70+ ref : ${{ inputs.hotfix_branch }}
71+ fetch-depth : 0
72+
73+ - uses : actions/setup-java@v4
74+ with :
75+ java-version : ${{ inputs.java_version || 21 }}
76+ distribution : ${{ inputs.java_distribution || 'liberica' }}
77+
78+ - name : Get hotfix version
79+ id : get_version
80+ run : |
81+ VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
82+ # Remove -SNAPSHOT if present
83+ VERSION="${VERSION%-SNAPSHOT}"
84+ echo "version=$VERSION" >> $GITHUB_OUTPUT
85+ echo "Hotfix version: $VERSION"
86+
87+ create-tag :
88+ name : Create hotfix tag
89+ needs : get-hotfix-version
90+ runs-on : ${{ inputs.runner || 'ubuntu-24.04' }}
91+ steps :
92+ - uses : actions/checkout@v4
93+ with :
94+ ref : ${{ inputs.hotfix_branch }}
95+ fetch-depth : 0
96+ token : ${{ secrets.GITHUB_TOKEN }}
97+
98+ - name : Configure Git
99+ run : |
100+ git config user.name "github-actions[bot]"
101+ git config user.email "github-actions[bot]@users.noreply.github.com"
102+
103+ - name : Create and push tag
104+ run : |
105+ VERSION="${{ needs.get-hotfix-version.outputs.version }}"
106+ TAG="${{ inputs.version_tag_prefix || 'v' }}${VERSION}"
107+
108+ echo "Creating tag: $TAG from branch ${{ inputs.hotfix_branch }}"
109+ git tag -a "$TAG" -m "Hotfix $VERSION"
110+ git push origin "$TAG"
111+
112+ publish-hotfix :
113+ name : Publish to Maven Central
114+ needs : [get-hotfix-version, create-tag]
115+ runs-on : ${{ inputs.runner || 'ubuntu-24.04' }}
116+ env :
117+ JRELEASER_MAVENCENTRAL_URL : " https://central.sonatype.com/api/v1/publisher"
118+ JRELEASER_DEPLOY_MAVEN_MAVENCENTRAL_ACTIVE : " RELEASE"
119+ JRELEASER_DEPLOY_MAVEN_NEXUS2_ACTIVE : " SNAPSHOT"
120+ JRELEASER_NEXUS2_URL : " https://ossrh-staging-api.central.sonatype.com/service/local"
121+ JRELEASER_NEXUS2_SNAPSHOT_URL : " https://central.sonatype.com/repository/maven-snapshots"
122+ JRELEASER_OVERWRITE : true
123+ JRELEASER_UPDATE : true
124+ JRELEASER_GIT_ROOT_SEARCH : true
125+ steps :
126+ - uses : actions/checkout@v4
127+ with :
128+ ref : ${{ inputs.version_tag_prefix || 'v' }}${{ needs.get-hotfix-version.outputs.version }}
129+ fetch-depth : 0
130+
131+ - uses : actions/setup-java@v4
132+ with :
133+ java-version : ${{ inputs.java_version || 21 }}
134+ distribution : ${{ inputs.java_distribution || 'liberica' }}
135+ cache : maven
136+
137+ - name : Install xmlstarlet
138+ run : |
139+ sudo rm -rf /var/lib/apt/lists/*
140+ sudo apt-get update
141+ sudo apt-get -y install xmlstarlet
142+
143+ - name : JReleaser Release to Maven Central
144+ uses : entur/gha-maven-central/.github/actions/jreleaser-release@v1
145+ with :
146+ version : ${{ needs.get-hotfix-version.outputs.version }}
147+ version_tag_prefix : ${{ inputs.version_tag_prefix || 'v' }}
148+ github_token : ${{ secrets.GITHUB_TOKEN }}
149+ sonatype_username : ${{ secrets.SONATYPE_AUTH_USER }}
150+ sonatype_password : ${{ secrets.SONATYPE_AUTH_TOKEN }}
151+ gpg_public_key : ${{ secrets.SONATYPE_GPG_KEY_PUBLIC }}
152+ gpg_secret_key : ${{ secrets.SONATYPE_GPG_KEY }}
153+ gpg_passphrase : ${{ secrets.SONATYPE_GPG_KEY_PASSWORD }}
154+ artifactory_user : ${{ secrets.ARTIFACTORY_AUTH_USER }}
155+ artifactory_token : ${{ secrets.ARTIFACTORY_AUTH_TOKEN }}
156+
157+ - name : Upload Build Reports
158+ if : failure()
159+ uses : actions/upload-artifact@v4
160+ with :
161+ name : jreleaser-reports
162+ path : |
163+ **/target/site
164+ **/target/reports/
165+ **/target/surefire-reports
166+
167+ merge-to-base-branch :
168+ name : Cherry-pick hotfix to base branch
169+ needs : [get-hotfix-version, publish-hotfix]
170+ if : inputs.merge_to_main == true
171+ runs-on : ${{ inputs.runner || 'ubuntu-24.04' }}
172+ steps :
173+ - uses : actions/checkout@v4
174+ with :
175+ ref : ${{ inputs.base_branch || 'main' }}
176+ fetch-depth : 0
177+ token : ${{ secrets.GITHUB_TOKEN }}
178+
179+ - name : Configure Git
180+ run : |
181+ git config user.name "github-actions[bot]"
182+ git config user.email "github-actions[bot]@users.noreply.github.com"
183+
184+ - name : Cherry-pick hotfix commits
185+ run : |
186+ HOTFIX_BRANCH="${{ inputs.hotfix_branch }}"
187+ BASE_BRANCH="${{ inputs.base_branch || 'main' }}"
188+ echo "Cherry-picking commits from $HOTFIX_BRANCH to $BASE_BRANCH"
189+
190+ # Get the base commit (where hotfix branched from)
191+ git fetch origin "$HOTFIX_BRANCH"
192+
193+ # Find all commits in the hotfix branch
194+ HOTFIX_COMMITS=$(git log --reverse --pretty=format:"%H" origin/$HOTFIX_BRANCH --not $(git merge-base origin/$BASE_BRANCH origin/$HOTFIX_BRANCH))
195+
196+ # Cherry-pick each commit
197+ for commit in $HOTFIX_COMMITS; do
198+ echo "Cherry-picking commit: $commit"
199+ git cherry-pick "$commit" || {
200+ echo "::warning::Cherry-pick conflict on commit $commit. Resolve manually."
201+ git cherry-pick --abort
202+ exit 1
203+ }
204+ done
205+
206+ - name : Push to base branch
207+ run : |
208+ BASE_BRANCH="${{ inputs.base_branch || 'main' }}"
209+ git push origin "$BASE_BRANCH"
210+
211+ - name : Delete hotfix branch
212+ continue-on-error : true
213+ run : |
214+ HOTFIX_BRANCH="${{ inputs.hotfix_branch }}"
215+ echo "Deleting hotfix branch: $HOTFIX_BRANCH"
216+ git push origin --delete "$HOTFIX_BRANCH" || echo "Branch already deleted"
217+
218+ - name : Create summary
219+ run : |
220+ VERSION="${{ needs.get-hotfix-version.outputs.version }}"
221+ TAG_PREFIX="${{ inputs.version_tag_prefix || 'v' }}"
222+ GROUP_ID="${{ inputs.artifact_group_id }}"
223+ ARTIFACT_IDS="${{ inputs.artifact_ids }}"
224+
225+ cat >> $GITHUB_STEP_SUMMARY <<EOF
226+ ## Hotfix Released
227+
228+ - **Hotfix Version:** $VERSION
229+ - **Git Tag:** \`${TAG_PREFIX}${VERSION}\`
230+ EOF
231+
232+ # Add Maven Central links if artifact details are provided
233+ if [ -n "$GROUP_ID" ] && [ -n "$ARTIFACT_IDS" ]; then
234+ IFS=',' read -ra ARTIFACTS <<< "$ARTIFACT_IDS"
235+ for ARTIFACT_ID in "${ARTIFACTS[@]}"; do
236+ ARTIFACT_ID=$(echo "$ARTIFACT_ID" | xargs) # Trim whitespace
237+ echo "- **Maven Central ($ARTIFACT_ID):** https://central.sonatype.com/artifact/${GROUP_ID}/${ARTIFACT_ID}/${VERSION}" >> $GITHUB_STEP_SUMMARY
238+ done
239+ fi
240+
241+ BASE_BRANCH="${{ inputs.base_branch || 'main' }}"
242+
243+ cat >> $GITHUB_STEP_SUMMARY <<EOF
244+ - **Hotfix Branch:** Deleted
245+ - **Merged to $BASE_BRANCH:** ${{ inputs.merge_to_main }}
246+
247+ The hotfix has been published to Maven Central.
248+ EOF
0 commit comments