Skip to content

Commit 9e0bad2

Browse files
committed
ci: updated GitHub Actions workflow to bump jar version
1 parent 402e5fa commit 9e0bad2

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

.github/workflows/release-main.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release Project
2+
3+
on:
4+
# Allows you to run this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
7+
# Sets permissions of the GITHUB_TOKEN to allow bump_version
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
env:
13+
POM_PATH: ${{ github.workspace }}
14+
15+
jobs:
16+
# check: https://dev.to/shayki5/github-action-for-building-maven-project-with-docker-and-push-it-docker-hub-3c3k
17+
release:
18+
runs-on: ubuntu-latest
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0 # Disable shallow clones for better analysis relevance
25+
26+
- name: Bump jar version
27+
id: bump
28+
run: |
29+
# Commit the changes
30+
git config user.email "actions@github.com"
31+
git config user.name "GitHub Actions"
32+
33+
OLD_VERSION=$(cd $POM_PATH && mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
34+
35+
# Extracting major, minor, and build versions
36+
IFS='.' read -ra parts <<< "$OLD_VERSION"
37+
major="${parts[0]}"
38+
minor="${parts[1]}"
39+
build_version=$((parts[2] + 1))
40+
41+
NEW_VERSION="${major}.${minor}.${build_version}"
42+
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
43+
44+
echo "Updating pom.xml at $POM_PATH from $OLD_VERSION to $NEW_VERSION" for the production branch
45+
git fetch
46+
git checkout production
47+
# Bump the version in the pom.xml file for the next release in production
48+
mvn -q versions:set -DnewVersion="${NEW_VERSION}" --file $POM_PATH/pom.xml
49+
git add $POM_PATH/pom.xml
50+
git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION"
51+
git push origin HEAD:production
52+
53+
- name: Create Pull Request
54+
run: |
55+
NEW_VERSION=${{ env.NEW_VERSION }}
56+
git fetch
57+
git checkout -b bump-version-${NEW_VERSION}-SNAPSHOT
58+
mvn -q versions:set -DnewVersion="${NEW_VERSION}-SNAPSHOT" --file $POM_PATH/pom.xml
59+
git add $POM_PATH/pom.xml
60+
git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION-SNAPSHOT"
61+
git push origin bump-version-${NEW_VERSION}-SNAPSHOT
62+
PR_URL=$(gh pr create --title "Bump version to $NEW_VERSION-SNAPSHOT" --body "" --base main )
63+
gh pr review $PR_URL --approve -b "I'm **approving** this pull request because **it includes a version bump for the jar file**"
64+
gh pr merge --auto --merge "$PR_URL"
65+
env:
66+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release Project 2
2+
3+
on:
4+
# Allows you to run this workflow manually from the Actions tab
5+
workflow_dispatch:
6+
7+
# Sets permissions of the GITHUB_TOKEN to allow bump_version
8+
permissions:
9+
contents: write
10+
11+
env:
12+
POM_PATH: ${{ github.workspace }}
13+
14+
jobs:
15+
# check: https://dev.to/shayki5/github-action-for-building-maven-project-with-docker-and-push-it-docker-hub-3c3k
16+
bump_version:
17+
runs-on: ubuntu-latest
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
with:
23+
fetch-depth: 0 # Disable shallow clones for better analysis relevance
24+
25+
- name: Bump jar version
26+
id: bump
27+
run: |
28+
OLD_VERSION=$(cd $POM_PATH && mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
29+
30+
# Extracting major, minor, and build versions
31+
IFS='.' read -ra parts <<< "$OLD_VERSION"
32+
major="${parts[0]}"
33+
minor="${parts[1]}"
34+
build_version=$((parts[2] + 1))
35+
36+
NEW_VERSION="${major}.${minor}.${build_version}"
37+
38+
echo "Updating pom.xml at $POM_PATH from $OLD_VERSION to $NEW_VERSION"
39+
40+
# Bump the version in the pom.xml file
41+
mvn -q versions:set -DnewVersion="${NEW_VERSION}" --file $POM_PATH/pom.xml
42+
43+
# Commit the changes
44+
git config user.email "actions@github.com"
45+
git config user.name "GitHub Actions"
46+
47+
git add $POM_PATH/pom.xml
48+
git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION"
49+
git push origin HEAD:production
50+
51+
52+
echo "Updating pom.xml at $POM_PATH from $OLD_VERSION to $NEW_VERSION-SNAPSHOT" for the main branch
53+
git fetch
54+
git checkout main
55+
# Bump the version in the pom.xml file for the next release in main
56+
mvn -q versions:set -DnewVersion="${NEW_VERSION}-SNAPSHOT" --file $POM_PATH/pom.xml
57+
git add $POM_PATH/pom.xml
58+
git commit -m "chore: bump jar version from $OLD_VERSION to $NEW_VERSION-SNAPSHOT"
59+
git push -f origin main

0 commit comments

Comments
 (0)