Skip to content

Commit ff7b322

Browse files
authored
fix: ensure release tag points to non-snapshot release commit (#3582)
Signed-off-by: Lavanya N M <lavanyanm75@gmail.com>
1 parent baf7787 commit ff7b322

2 files changed

Lines changed: 81 additions & 20 deletions

File tree

‎.github/workflows/release-project-in-dir.yml‎

Lines changed: 72 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,28 @@ on:
99
version_branch:
1010
type: string
1111
required: true
12+
release_tag:
13+
type: string
14+
required: true
1215

1316
env:
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

1720
jobs:
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 }}

‎.github/workflows/release.yml‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ jobs:
1515
timeout-minutes: 10
1616
env:
1717
tmp_version_branch: ''
18+
RAW_TAG: ${{ github.event.release.tag_name }}
1819
outputs:
1920
version_branch: ${{ steps.set-version-branch.outputs.version_branch }}
21+
release_tag: ${{ steps.set-release-tag.outputs.release_tag }}
2022
steps:
2123
- if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
2224
run: |
@@ -98,7 +100,10 @@ jobs:
98100
exit 1
99101
- id: set-version-branch
100102
name: Set version_branch if matched
101-
run: echo "version_branch=${{env.tmp_version_branch}}" >> $GITHUB_OUTPUT
103+
run: echo "version_branch=${{ env.tmp_version_branch }}" >> "$GITHUB_OUTPUT"
104+
- id: set-release-tag
105+
name: Pass release tag
106+
run: echo "release_tag=${RAW_TAG}" >> "$GITHUB_OUTPUT"
102107

103108
release-sdk:
104109
needs: prepare-release
@@ -108,5 +113,6 @@ jobs:
108113
uses: ./.github/workflows/release-project-in-dir.yml
109114
secrets: inherit
110115
with:
111-
version_branch: ${{needs.prepare-release.outputs.version_branch}}
112-
project_dir: '.'
116+
version_branch: ${{ needs.prepare-release.outputs.version_branch }}
117+
release_tag: ${{ needs.prepare-release.outputs.release_tag }}
118+
project_dir: '.'

0 commit comments

Comments
 (0)