Skip to content

Commit

Permalink
Add Github Action to automatically bump version at PR merge (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored May 23, 2024
1 parent 5241760 commit 5a2023e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/bump_version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Bump version on PR merge
on:
pull_request:
branches:
- main
types: closed

permissions:
contents: write

jobs:
update_version:
if: github.event.pull_request.merged == true
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
# Fetch full depth, otherwise the last step overwrites the last commit's parent, essentially removing the graph.
fetch-depth: 0

- name: Run bump_version_gh_action.sh
run: |
bash ./bump_version_gh_action.sh
- name: Amend the last commit
run: |
git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"
git config --global user.name "${GITHUB_ACTOR}"
git commit -a --amend --no-edit
git push --force-with-lease
echo "Complete"
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand All @@ -25,7 +25,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
Expand Down
14 changes: 14 additions & 0 deletions bump_version_gh_action.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# search for the first line that starts with "version" in build.gradle.kts
# get the value in the quotes
VERSION=$(grep "^version = " build.gradle.kts | sed -n 's/version = "\(.*\)"/\1/p')

# increment the version number
NEW_VERSION=$(echo $VERSION | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')

#if NEW_VERSION is not empty, replace the version in build.gradle.kts
if [ -n "$NEW_VERSION" ]; then
sed -i '' "s/version = \"$VERSION\"/version = \"$NEW_VERSION\"/" build.gradle.kts
echo "Version bumped to $NEW_VERSION"
fi

0 comments on commit 5a2023e

Please sign in to comment.