Skip to content

Commit 315e1da

Browse files
committed
fix: ensure release tag points to non-snapshot release commit
Signed-off-by: Lavanya N M <lavanyanm75@gmail.com>
1 parent 97f296f commit 315e1da

2 files changed

Lines changed: 58 additions & 25 deletions

File tree

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

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +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+
permissions:
24+
contents: write
2025
steps:
21-
- name: Checkout "${{inputs.version_branch}}" branch
22-
uses: actions/checkout@v7
26+
- name: Checkout "${{ inputs.version_branch }}" branch
27+
uses: actions/checkout@v4
2328
with:
24-
ref: "${{inputs.version_branch}}"
29+
ref: "${{ inputs.version_branch }}"
30+
fetch-depth: 0
2531

2632
- name: Set up Java and Maven
27-
uses: actions/setup-java@v6
33+
uses: actions/setup-java@v4
2834
with:
2935
java-version: 17
3036
distribution: temurin
@@ -36,11 +42,11 @@ jobs:
3642
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3743

3844
- 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
4245
env:
43-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
46+
RELEASE_TAG: ${{ inputs.release_tag }}
47+
run: |
48+
RELEASE_VERSION="${RELEASE_TAG#v}"
49+
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION}" versions:commit -DprocessAllModules
4450
4551
- name: Publish to Apache Maven Central
4652
run: ./mvnw package deploy -Prelease
@@ -49,19 +55,41 @@ jobs:
4955
MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }}
5056
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
5157

52-
# This is separate job because there were issues with git after release step, was not able to commit changes.
58+
- name: Commit and push release version
59+
env:
60+
TARGET_BRANCH: ${{ inputs.version_branch }}
61+
RELEASE_TAG: ${{ inputs.release_tag }}
62+
run: |
63+
git config --local user.email "action@github.com"
64+
git config --local user.name "GitHub Action"
65+
if git diff --quiet; then
66+
echo "No version changes to commit."
67+
else
68+
git commit -am "Release ${RELEASE_TAG}"
69+
git push origin HEAD:"${TARGET_BRANCH}"
70+
fi
71+
72+
- name: Override release tag to point to release commit
73+
env:
74+
RELEASE_TAG: ${{ inputs.release_tag }}
75+
run: |
76+
git tag -f -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}"
77+
git push -f origin "refs/tags/${RELEASE_TAG}"
78+
5379
update-working-version:
5480
runs-on: ubuntu-latest
5581
needs: publish
56-
if: "!contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
82+
permissions:
83+
contents: write
84+
if: "!contains(inputs.release_tag, 'RC')"
5785
steps:
58-
- name: Checkout "${{inputs.version_branch}}" branch
59-
uses: actions/checkout@v7
86+
- name: Checkout "${{ inputs.version_branch }}" branch
87+
uses: actions/checkout@v4
6088
with:
61-
ref: "${{inputs.version_branch}}"
89+
ref: "${{ inputs.version_branch }}"
6290

6391
- name: Set up Java and Maven
64-
uses: actions/setup-java@v6
92+
uses: actions/setup-java@v4
6593
with:
6694
java-version: 17
6795
distribution: temurin
@@ -73,11 +101,9 @@ jobs:
73101
git config --local user.email "action@github.com"
74102
git config --local user.name "GitHub Action"
75103
git commit -m "Set new SNAPSHOT version into pom files." -a
76-
env:
77-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
78104
79105
- name: Push changes to branch
80106
uses: ad-m/github-push-action@master
81107
with:
82-
branch: "${{inputs.version_branch}}"
83-
github_token: ${{ secrets.GITHUB_TOKEN }}
108+
branch: "${{ inputs.version_branch }}"
109+
github_token: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 13 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,7 @@ 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+
RELEASE_VERSION="${RAW_TAG#v}"
3637
RELEASE_MAJOR_MINOR=$(echo "$RELEASE_VERSION" | cut -d. -f1-2)
3738
3839
MAIN_POM_VERSION=$(curl -fsSL "https://raw.githubusercontent.com/${{ github.repository }}/main/pom.xml" | yq -p xml '.project.version')
@@ -55,16 +56,22 @@ jobs:
5556
- if: ${{ env.tmp_version_branch == '' }}
5657
name: Fail if version_branch is not set
5758
run: |
58-
echo "Failed to find appropriate branch to release ${{github.event.release.tag_name}} from"
59+
echo "Failed to find appropriate branch to release $RAW_TAG from"
5960
exit 1
6061
- id: set-version-branch
6162
name: Set version_branch if matched
62-
run: echo "version_branch=${{env.tmp_version_branch}}" >> $GITHUB_OUTPUT
63+
run: echo "version_branch=${{ env.tmp_version_branch }}" >> "$GITHUB_OUTPUT"
64+
- id: set-release-tag
65+
name: Pass release tag
66+
run: echo "release_tag=${RAW_TAG}" >> "$GITHUB_OUTPUT"
6367

6468
release-sdk:
6569
needs: prepare-release
70+
permissions:
71+
contents: write
6672
uses: ./.github/workflows/release-project-in-dir.yml
6773
secrets: inherit
6874
with:
69-
version_branch: ${{needs.prepare-release.outputs.version_branch}}
70-
project_dir: '.'
75+
version_branch: ${{ needs.prepare-release.outputs.version_branch }}
76+
release_tag: ${{ needs.prepare-release.outputs.release_tag }}
77+
project_dir: '.'

0 commit comments

Comments
 (0)