How to increment version minor/patch based on the branch from which we merge

1.6k Views Asked by At

We have a simple GitHubFlow workflow with feature/* and bug/* branches.

When things are merged to master, then the version gets bumped whatever we specify in the GitVersion.yml file (minor/patch).

mode: Mainline
branches:
  main:
    regex: ^master$
    tag: ''
    # Increment is always the same regardless of the branch from which we are merging
    increment: Minor

  feature:
    regex: ^feature/
    tag: useBranchName
    increment: Minor
    source-branches:
    - main

  bug:
    regex: ^bug/
    tag: useBranchName
    increment: Patch
    source-branches:
    - main

However, I'd like to bump the minor or patch version depending on whether we merged from a feature or bug branch.

I'm using Squashing when merging to master.

Is there a way to do this please?

2

There are 2 best solutions below

1
On

Unfortunately, I was not able to increment the major, minor and patch versions based on the branch (the increment property inside each branch is ignored) so all merges to master increment the same way but with possibility to bump differently based on something added to the message e.g. Add +f (feature) to increment minor versions and +b (bug) to increment patch version.

mode: Mainline
major-version-bump-message: '\+major'
minor-version-bump-message: '\+f'
patch-version-bump-message: '\+b'
branches:
  master:
    regex: ^master$
    tag: ""
    increment: Minor
    is-mainline: true

  feature:
    regex: ^feature/
    tag: useBranchName
    increment: Patch

  bug:
    regex: ^bug/
    tag: useBranchName
    increment: Patch
    source-branches:
      - master
0
On

This worked for me

mode: Mainline
commit-message-incrementing: MergeMessageOnly
branches:
  main:
    regex: ^main$
    tag: ''
  feature:
    regex: ^feature/
    tag: useBranchName
    increment: Minor
  hotfix:
    regex: ^hotfix/
    tag: useBranchName
    increment: Patch

The minor version is incremented when merging from a feature branch.

The patch version is incremented when merging from a feature hotfix.