gh-action-bump-version icon indicating copy to clipboard operation
gh-action-bump-version copied to clipboard

Skip version bump when not using conventional commit message

Open eric-personal opened this issue 3 years ago • 2 comments

When I don't use a conventional commit message like 'feat:' or 'fix: ...' I still get a bump in version. It seems to default to a patch number.

Example commit message: 'pushing branch without conventional message'
Result: This will still run the bumpversion. 
Expected result: **should not run the bumpversion.** 

Another example using conventional commit message which works as intended :

Example commit message: 'feat: pushing branch without version bump'
Result: This will still run the bumpversion. 

How would one go about skipping bump version all together ? Here is what I have in my workflow:

    steps:
      - name: Checkout repository
        uses: actions/checkout@v3

      - name: "Bump package version"
        id: bumpVersion
        uses: "phips28/gh-action-bump-version@master"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PACKAGEJSON_DIR: "./client"
          tag-prefix: ${{env.TAG_PREXIX}}
          major-wording: "MAJOR,BREAKING CHANGE"
          minor-wording: "feat"
          patch-wording: "patch,fix,bugfix,chore"

eric-personal avatar Oct 25 '22 02:10 eric-personal

Yes, it's true that running the action always bumps the version. If not specified it will increment the patch version.

You could create an if condition for the workflow (or even just the Bump package version step). For example, to base the condition on having a certain string in the commit message you can use a condition like this.

jobs:
  version-bump:
    if: "startsWith(github.event.head_commit.message, 'VERSION BUMP:')"

If you more frequently wish to bump the version than not bump the version, you could invert the condition to prevent it.

jobs:
  version-bump:
    if: "!startsWith(github.event.head_commit.message, 'NO BUMP:')"

These conditions are just examples.

As a real world example, our workflow creates an rc version bump by default, not a patch. To achieve that we used the following settings.

...
with:
  # These words need to be part of a commit to trigger
  # They are purposefully complex to avoid accidental triggers
  major-wording: 'major-bb-protected'
  minor-wording: 'minor-bb-protected'
  patch-wording: 'patch-bb-protected'
  # needs to be empty for all pushes to be prerelease
  rc-wording: ''

  # defaulting to bump prerelease version--default is patch
  default: prerelease
  preid: 'rc'

  tag-prefix: 'v'

  target-branch: 'main'
  commit-message: 'CI: bumps version to {{version}}'

nickbeaulieu avatar Nov 10 '22 16:11 nickbeaulieu

Another option is to include [ci skip] in the commit message, from Github Docs. Note that this will skip all action workflows that would otherwise be triggered by the commit.

a-Leong avatar Dec 07 '22 00:12 a-Leong

I think the formatting of the if statement may have changed; in my shared workflow definition, I had to format the if statement like:

    if: ${{ ! startsWith(github.event.head_commit.message, '[skip-version]') }}

Just in case anyone else stumbles along here!

thekevinscott avatar May 09 '24 11:05 thekevinscott