Skip to content

Commit 9726d41

Browse files
Lavanya-N24csviri
authored andcommitted
fix: ensure release tag points to non-snapshot release commit
Signed-off-by: Lavanya N M <lavanyanm75@gmail.com>
1 parent 6fb7675 commit 9726d41

2 files changed

Lines changed: 70 additions & 19 deletions

File tree

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

Lines changed: 55 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,35 @@ on:
1111
required: true
1212

1313
env:
14-
# set the target pom to use the input directory as root
14+
# set the target pom to use the input directory as root
1515
MAVEN_ARGS: -V -ntp -e -f ${{ inputs.project_dir }}/pom.xml
1616

1717
jobs:
1818
publish:
1919
runs-on: ubuntu-latest
20+
permissions:
21+
contents: write
2022
steps:
2123
- name: Checkout "${{inputs.version_branch}}" branch
22-
uses: actions/checkout@v7
24+
uses: actions/checkout@v4
2325
with:
2426
ref: "${{inputs.version_branch}}"
27+
fetch-depth: 0
28+
29+
- name: Parse release version
30+
id: vars
31+
run: |
32+
RAW_TAG="${{ github.event.release.tag_name }}"
33+
STRIPPED="${RAW_TAG#v}"
34+
FINAL_VERSION="${STRIPPED%-tmp}"
35+
FINAL_TAG="v${FINAL_VERSION}"
36+
37+
echo "raw_tag=${RAW_TAG}" >> "$GITHUB_OUTPUT"
38+
echo "final_version=${FINAL_VERSION}" >> "$GITHUB_OUTPUT"
39+
echo "final_tag=${FINAL_TAG}" >> "$GITHUB_OUTPUT"
2540
2641
- name: Set up Java and Maven
27-
uses: actions/setup-java@v6
42+
uses: actions/setup-java@v4
2843
with:
2944
java-version: 17
3045
distribution: temurin
@@ -36,11 +51,39 @@ jobs:
3651
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3752

3853
- name: Change version to release version
39-
# Assume that RELEASE_VERSION will have form like: "v1.0.1". So we cut the "v"
4054
run: |
41-
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION:1}" versions:commit -DprocessAllModules
55+
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${{ steps.vars.outputs.final_version }}" versions:commit -DprocessAllModules
56+
57+
- name: Commit and push release version
58+
run: |
59+
git config --local user.email "action@github.com"
60+
git config --local user.name "GitHub Action"
61+
if git diff --quiet; then
62+
echo "No version changes to commit."
63+
else
64+
git commit -am "Release ${{ steps.vars.outputs.final_tag }}"
65+
git push origin HEAD:${{ inputs.version_branch }}
66+
fi
67+
68+
- name: Re-tag commit and update GitHub Release
4269
env:
43-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
70+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71+
GH_REPO: ${{ github.repository }}
72+
run: |
73+
RAW_TAG="${{ steps.vars.outputs.raw_tag }}"
74+
FINAL_TAG="${{ steps.vars.outputs.final_tag }}"
75+
76+
if [ "$RAW_TAG" != "$FINAL_TAG" ]; then
77+
echo "Creating final release tag: ${FINAL_TAG}"
78+
git tag -a "${FINAL_TAG}" -m "Release ${FINAL_TAG}"
79+
git push origin "${FINAL_TAG}"
80+
81+
echo "Pointing GitHub release to final tag ${FINAL_TAG}"
82+
gh release edit "${RAW_TAG}" --tag "${FINAL_TAG}"
83+
84+
echo "Deleting temporary tag ${RAW_TAG}"
85+
git push origin --delete "${RAW_TAG}" || true
86+
fi
4487
4588
- name: Publish to Apache Maven Central
4689
run: ./mvnw package deploy -Prelease
@@ -49,19 +92,20 @@ jobs:
4992
MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }}
5093
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
5194

52-
# This is separate job because there were issues with git after release step, was not able to commit changes.
5395
update-working-version:
5496
runs-on: ubuntu-latest
5597
needs: publish
56-
if: "!contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
98+
permissions:
99+
contents: write
100+
if: "!contains(github.event.release.tag_name, 'RC')"
57101
steps:
58102
- name: Checkout "${{inputs.version_branch}}" branch
59-
uses: actions/checkout@v7
103+
uses: actions/checkout@v4
60104
with:
61105
ref: "${{inputs.version_branch}}"
62106

63107
- name: Set up Java and Maven
64-
uses: actions/setup-java@v6
108+
uses: actions/setup-java@v4
65109
with:
66110
java-version: 17
67111
distribution: temurin
@@ -73,11 +117,9 @@ jobs:
73117
git config --local user.email "action@github.com"
74118
git config --local user.name "GitHub Action"
75119
git commit -m "Set new SNAPSHOT version into pom files." -a
76-
env:
77-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
78120
79121
- name: Push changes to branch
80122
uses: ad-m/github-push-action@master
81123
with:
82124
branch: "${{inputs.version_branch}}"
83-
github_token: ${{ secrets.GITHUB_TOKEN }}
125+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
env:
1212
tmp_version_branch: ''
13+
RAW_TAG: ${{ github.event.release.tag_name }}
1314
outputs:
1415
version_branch: ${{ steps.set-version-branch.outputs.version_branch }}
16+
release_tag: ${{ steps.set-release-tag.outputs.release_tag }}
1517
steps:
1618
- if: ${{ startsWith(github.event.release.tag_name, 'v1.' ) }}
1719
run: |
@@ -31,8 +33,9 @@ jobs:
3133
echo "tmp_version_branch=v4" >> "$GITHUB_ENV"
3234
- if: ${{ startsWith(github.event.release.tag_name, 'v5.' ) }}
3335
run: |
34-
RELEASE_VERSION="${{ github.event.release.tag_name }}"
35-
RELEASE_VERSION="${RELEASE_VERSION#v}"
36+
# Strip 'v' prefix and optional '-tmp' suffix
37+
RELEASE_VERSION="${RAW_TAG#v}"
38+
RELEASE_VERSION="${RELEASE_VERSION%-tmp}"
3639
RELEASE_MAJOR_MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f1-2)
3740
3841
MAIN_POM_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/${{ github.repository }}/main/pom.xml" | yq -p xml '.project.version')
@@ -55,16 +58,22 @@ jobs:
5558
- if: ${{ env.tmp_version_branch == '' }}
5659
name: Fail if version_branch is not set
5760
run: |
58-
echo "Failed to find appropriate branch to release ${{github.event.release.tag_name}} from"
61+
echo "Failed to find appropriate branch to release $RAW_TAG from"
5962
exit 1
6063
- id: set-version-branch
6164
name: Set version_branch if matched
62-
run: echo "version_branch=${{env.tmp_version_branch}}" >> $GITHUB_OUTPUT
65+
run: echo "version_branch=${{ env.tmp_version_branch }}" >> "$GITHUB_OUTPUT"
66+
- id: set-release-tag
67+
name: Pass release tag
68+
run: echo "release_tag=${RAW_TAG}" >> "$GITHUB_OUTPUT"
6369

6470
release-sdk:
6571
needs: prepare-release
72+
permissions:
73+
contents: write
6674
uses: ./.github/workflows/release-project-in-dir.yml
6775
secrets: inherit
6876
with:
69-
version_branch: ${{needs.prepare-release.outputs.version_branch}}
70-
project_dir: '.'
77+
version_branch: ${{ needs.prepare-release.outputs.version_branch }}
78+
release_tag: ${{ needs.prepare-release.outputs.release_tag }}
79+
project_dir: '.'

0 commit comments

Comments
 (0)