Skip to content

Commit d2f4763

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 d2f4763

2 files changed

Lines changed: 83 additions & 27 deletions

File tree

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

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,25 @@ 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
2023
steps:
21-
- name: Checkout "${{inputs.version_branch}}" branch
22-
uses: actions/checkout@v7
24+
- name: Checkout "${{ inputs.version_branch }}" branch
25+
uses: actions/checkout@v4
2326
with:
24-
ref: "${{inputs.version_branch}}"
27+
ref: "${{ inputs.version_branch }}"
2528

2629
- name: Set up Java and Maven
27-
uses: actions/setup-java@v6
30+
uses: actions/setup-java@v4
2831
with:
2932
java-version: 17
3033
distribution: temurin
@@ -36,11 +39,11 @@ jobs:
3639
gpg-passphrase: MAVEN_GPG_PASSPHRASE
3740

3841
- 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
4242
env:
43-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
43+
RELEASE_TAG: ${{ inputs.release_tag }}
44+
run: |
45+
RELEASE_VERSION="${RELEASE_TAG#v}"
46+
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION}" versions:commit -DprocessAllModules
4447
4548
- name: Publish to Apache Maven Central
4649
run: ./mvnw package deploy -Prelease
@@ -49,19 +52,67 @@ jobs:
4952
MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }}
5053
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
5154

52-
# This is separate job because there were issues with git after release step, was not able to commit changes.
53-
update-working-version:
55+
finalize-release:
5456
runs-on: ubuntu-latest
5557
needs: publish
56-
if: "!contains(github.event.release.tag_name, 'RC')" # not sure we should keep this the RC part
58+
permissions:
59+
contents: write
5760
steps:
58-
- name: Checkout "${{inputs.version_branch}}" branch
59-
uses: actions/checkout@v7
61+
- name: Checkout "${{ inputs.version_branch }}" branch
62+
uses: actions/checkout@v4
6063
with:
61-
ref: "${{inputs.version_branch}}"
64+
ref: "${{ inputs.version_branch }}"
65+
fetch-depth: 0
6266

6367
- name: Set up Java and Maven
64-
uses: actions/setup-java@v6
68+
uses: actions/setup-java@v4
69+
with:
70+
java-version: 17
71+
distribution: temurin
72+
cache: 'maven'
73+
74+
- name: Change version to release version
75+
env:
76+
RELEASE_TAG: ${{ inputs.release_tag }}
77+
run: |
78+
RELEASE_VERSION="${RELEASE_TAG#v}"
79+
./mvnw ${MAVEN_ARGS} versions:set -DnewVersion="${RELEASE_VERSION}" versions:commit -DprocessAllModules
80+
81+
- name: Commit and push release version
82+
env:
83+
TARGET_BRANCH: ${{ inputs.version_branch }}
84+
RELEASE_TAG: ${{ inputs.release_tag }}
85+
run: |
86+
git config --local user.email "action@github.com"
87+
git config --local user.name "GitHub Action"
88+
if git diff --quiet; then
89+
echo "No version changes to commit."
90+
else
91+
git commit -am "Release ${RELEASE_TAG}"
92+
git push origin HEAD:"${TARGET_BRANCH}"
93+
fi
94+
95+
- name: Override release tag to point to release commit
96+
env:
97+
RELEASE_TAG: ${{ inputs.release_tag }}
98+
run: |
99+
git tag -f -a "${RELEASE_TAG}" -m "Release ${RELEASE_TAG}"
100+
git push -f origin "refs/tags/${RELEASE_TAG}"
101+
102+
update-working-version:
103+
runs-on: ubuntu-latest
104+
needs: finalize-release
105+
permissions:
106+
contents: write
107+
if: "!contains(inputs.release_tag, 'RC')"
108+
steps:
109+
- name: Checkout "${{ inputs.version_branch }}" branch
110+
uses: actions/checkout@v4
111+
with:
112+
ref: "${{ inputs.version_branch }}"
113+
114+
- name: Set up Java and Maven
115+
uses: actions/setup-java@v4
65116
with:
66117
java-version: 17
67118
distribution: temurin
@@ -73,11 +124,9 @@ jobs:
73124
git config --local user.email "action@github.com"
74125
git config --local user.name "GitHub Action"
75126
git commit -m "Set new SNAPSHOT version into pom files." -a
76-
env:
77-
RELEASE_VERSION: ${{ github.event.release.tag_name }}
78127
79128
- name: Push changes to branch
80-
uses: ad-m/github-push-action@master
129+
uses: ad-m/github-push-action@881a6320fdb16eb5318c5054f31c218aec2b324c # v0.8.0
81130
with:
82-
branch: "${{inputs.version_branch}}"
83-
github_token: ${{ secrets.GITHUB_TOKEN }}
131+
branch: "${{ inputs.version_branch }}"
132+
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)