From dea95cdb105b0b1bbfc7be6c71b9ae17a22d12b7 Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 22 May 2024 18:03:11 -0700 Subject: [PATCH 1/4] Add Github Action to bump version at PR merge --- .github/workflows/bump_version.yml | 32 ++++++++++++++++++++++++++++++ .github/workflows/ci.yml | 4 ++-- bump_version_gh_action.sh | 14 +++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/bump_version.yml create mode 100755 bump_version_gh_action.sh diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml new file mode 100644 index 000000000..07aea7404 --- /dev/null +++ b/.github/workflows/bump_version.yml @@ -0,0 +1,32 @@ +name: Bump version on PR merge +on: + pull_request: + branches: + - main + - develop + 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.sh + run: | + bash ./bump_version.sh + - name: Amend the last commit + run: | + git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" + git config --global user.name "git bot" + git commit -a --amend --no-edit + git push --force-with-lease + echo "Complete" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c44991181..6771876f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 diff --git a/bump_version_gh_action.sh b/bump_version_gh_action.sh new file mode 100755 index 000000000..069819e32 --- /dev/null +++ b/bump_version_gh_action.sh @@ -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 From 8b7af10d6b0753c65143412081ac546dcf64041e Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 22 May 2024 18:04:37 -0700 Subject: [PATCH 2/4] Clean up --- .github/workflows/bump_version.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index 07aea7404..30d548623 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -3,7 +3,6 @@ on: pull_request: branches: - main - - develop types: closed permissions: From 8ea46d0e4225916648045ebc535f1f28a0775e7e Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 22 May 2024 18:08:43 -0700 Subject: [PATCH 3/4] Clean up --- .github/workflows/bump_version.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index 30d548623..0c4671c46 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -25,7 +25,7 @@ jobs: - name: Amend the last commit run: | git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" - git config --global user.name "git bot" + git config --global user.name "${GITHUB_ACTOR}" git commit -a --amend --no-edit git push --force-with-lease echo "Complete" From a2afb6c2c722d28891bacd4353ec5ba058cc17ba Mon Sep 17 00:00:00 2001 From: Rui Date: Wed, 22 May 2024 18:09:56 -0700 Subject: [PATCH 4/4] Clean up --- .github/workflows/bump_version.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/bump_version.yml b/.github/workflows/bump_version.yml index 0c4671c46..f73020cf9 100644 --- a/.github/workflows/bump_version.yml +++ b/.github/workflows/bump_version.yml @@ -19,9 +19,9 @@ jobs: # Fetch full depth, otherwise the last step overwrites the last commit's parent, essentially removing the graph. fetch-depth: 0 - - name: Run bump_version.sh + - name: Run bump_version_gh_action.sh run: | - bash ./bump_version.sh + bash ./bump_version_gh_action.sh - name: Amend the last commit run: | git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com"