Currently, I'm trying to automate the bump versions for the applications as part of the PR Merge using the GitHub Actions. There is a custom script that would identify the current version of the application and the label attached with the PR and bump the major|minor|patch version accordingly on the file where the version numbers are stored. It is important that the version bump happens only at the time when PR is merged and as part of GitHub Actions because it helps in avoiding the merge conflict in the version file and takes away the manual way of bumping the version.
The GitHub Actions code snippet is given below.
jobs:
release:
# Skip on Pull Request Close event.
if: "!(github.event_name == 'pull_request' && !github.event.pull_request.merged)"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- id: bumpversion
if: github.event.pull_request.merged
env:
PR_LABELS: ${{ toJson(github.event.pull_request.labels) }}
run: bash .github/scripts/bump_version.sh -l "${PR_LABELS}"
The bump_version.sh
script has a function given below that makes the version changes and then pushes them to the main
branch.
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
echo "commiting the version bump changes..."
git add .
git commit -m "Bump Version v${current_version} -> v${incremented_version}"
echo "pushing the version bump changes..."
git push origin dev
This runs fine but the problem is that it makes 2 commits on the main
branch when a PR is merged to it. There is a CI/CD pipeline that listens to this main
branch for changes and it gets triggered when there is a new commit to it. Since this PR merge makes 2 commits, it is triggered twice.
2 commits for single PR merge image
The question: Is it possible to update files as part of a merge via GitHub Actions without creating a second commit? Is there any other way to achieve a solution to this problem that will help me to bump the version as part of the PR Merge?