phips28 / gh-action-bump-version

GitHub Action for automated npm version bump.
MIT License
336 stars 249 forks source link

Skip version bump when not using conventional commit message #188

Closed eric-personal closed 6 months ago

eric-personal commented 1 year ago

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"
nickbeaulieu commented 1 year ago

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}}'
a-Leong commented 1 year ago

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.

thekevinscott commented 4 months ago

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!