99 version_branch :
1010 type : string
1111 required : true
12+ release_tag :
13+ type : string
14+ required : true
1215
1316env :
14- # set the target pom to use the input directory as root
17+ # set the target pom to use the input directory as root
1518 MAVEN_ARGS : -V -ntp -e -f ${{ inputs.project_dir }}/pom.xml
1619
1720jobs :
1821 publish :
1922 runs-on : ubuntu-latest
23+ outputs :
24+ release_sha : ${{ steps.resolve-sha.outputs.commit }}
2025 steps :
21- - name : Checkout "${{inputs.version_branch}}" branch
26+ - name : Checkout "${{ inputs.version_branch }}" branch
2227 uses : actions/checkout@v7
2328 with :
24- ref : " ${{inputs.version_branch}}"
29+ ref : " ${{ inputs.version_branch }}"
30+
31+ - name : Resolve checked-out commit
32+ id : resolve-sha
33+ run : echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
2534
2635 - name : Set up Java and Maven
2736 uses : actions/setup-java@v6
@@ -36,11 +45,11 @@ jobs:
3645 gpg-passphrase : MAVEN_GPG_PASSPHRASE
3746
3847 - name : Change version to release version
39- # Assume that RELEASE_VERSION will have form like: "v1.0.1". So we cut the "v"
40- run : |
41- ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit -DprocessAllModules
4248 env :
43- RELEASE_VERSION : ${{ github.event.release.tag_name }}
49+ RELEASE_TAG : ${{ inputs.release_tag }}
50+ run : |
51+ RELEASE_VERSION="${RELEASE_TAG#v}"
52+ ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION}" versions:commit -DprocessAllModules
4453
4554 - name : Publish to Apache Maven Central
4655 run : ./mvnw package deploy -Prelease
@@ -49,16 +58,64 @@ jobs:
4958 MAVEN_CENTRAL_TOKEN : ${{ secrets.NEXUS_PASSWORD }}
5059 MAVEN_GPG_PASSPHRASE : ${{ secrets.GPG_PASSPHRASE }}
5160
52- # This is separate job because there were issues with git after release step, was not able to commit changes.
53- update-working-version :
61+ finalize-release :
5462 runs-on : ubuntu-latest
5563 needs : publish
56- if : " !contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
64+ permissions :
65+ contents : write
66+ steps :
67+ - name : Checkout exact published commit
68+ uses : actions/checkout@v4
69+ with :
70+ ref : " ${{ needs.publish.outputs.release_sha }}"
71+ fetch-depth : 0
72+
73+ - name : Set up Java and Maven
74+ uses : actions/setup-java@v4
75+ with :
76+ java-version : 17
77+ distribution : temurin
78+ cache : ' maven'
79+
80+ - name : Change version to release version
81+ env :
82+ RELEASE_TAG : ${{ inputs.release_tag }}
83+ run : |
84+ RELEASE_VERSION="${RELEASE_TAG#v}"
85+ ./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION}" versions:commit -DprocessAllModules
86+
87+ - name : Commit and push release version
88+ env :
89+ TARGET_BRANCH : ${{ inputs.version_branch }}
90+ RELEASE_TAG : ${{ inputs.release_tag }}
91+ run : |
92+ git config --local user.email "action@github.com"
93+ git config --local user.name "GitHub Action"
94+ if git diff --quiet; then
95+ echo "No version changes to commit."
96+ else
97+ git commit -am "Release ${RELEASE_TAG}"
98+ git push origin HEAD:"${TARGET_BRANCH}"
99+ fi
100+
101+ - name : Override release tag to point to release commit
102+ env :
103+ RELEASE_TAG : ${{ inputs.release_tag }}
104+ run : |
105+ git tag -f -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}"
106+ git push -f origin "refs/tags/${RELEASE_TAG}"
107+
108+ update-working-version :
109+ runs-on : ubuntu-latest
110+ needs : finalize-release
111+ permissions :
112+ contents : write
113+ if : " !contains(inputs.release_tag, 'RC')"
57114 steps :
58- - name : Checkout "${{inputs.version_branch}}" branch
115+ - name : Checkout "${{ inputs.version_branch }}" branch
59116 uses : actions/checkout@v7
60117 with :
61- ref : " ${{inputs.version_branch}}"
118+ ref : " ${{ inputs.version_branch }}"
62119
63120 - name : Set up Java and Maven
64121 uses : actions/setup-java@v6
@@ -73,11 +130,9 @@ jobs:
73130 git config --local user.email "action@github.com"
74131 git config --local user.name "GitHub Action"
75132 git commit -m "Set new SNAPSHOT version into pom files." -a
76- env :
77- RELEASE_VERSION : ${{ github.event.release.tag_name }}
78133
79134 - name : Push changes to branch
80- uses : ad-m/github-push-action@master
135+ uses : ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v0.8.0
81136 with :
82- branch : " ${{inputs.version_branch}}"
83- github_token : ${{ secrets.GITHUB_TOKEN }}
137+ branch : " ${{ inputs.version_branch }}"
138+ github_token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments