-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Github Action to automatically bump version at PR merge (#378)
- Loading branch information
Showing
3 changed files
with
47 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |