How can I bump the package.json version and include it as a commit when a merge request is merged in Gitlab?

In my project, we bump the package.json version by patch each time a MR is merged into develop, our default branch.

Currently, we have added a CI/CD job that bumps the version, saves it as a commit and pushes it into the develop branch. This is working and it’s being triggered after a MR is merged.

gitlab-ci.yml

stages:
 - bump_version

bump-version:
  stage: bump_version
  script:
    - echo "Current version:"
    - cat package.json | grep "\"version\""
    - echo "Bumping version..."
    - ./bump_version_script.sh // Bumps version, git add, git commit, git push origin develop
    - echo "New version:"
    - cat package.json | grep "\"version\""

The bad thing about this is that our git history is being “contaminated” with those bump commits like this:

$ git log --oneline

* Bump version v1.0.3
* Merge branch 'C' into 'develop'
* Bump version v1.0.2
* Merge branch 'B' into 'develop'
* Bump version v1.0.1
* Merge branch 'A' into 'develop'
* Project init v1.0.0

Is there a way to bump the version and include it in the Merge commit? Thanks in advance.

Leave a Comment