GitHub Action
Bump package version
A github action bumping the version of a package and pushing the version bump to the repo.
This github action bumps package.json version after a commit is pushed or a pull request is merged to the repo master branch. The updated package.json file is then pushed to master and a tag is created.
⚠️ This action requires the checkout action to work
If you push directly to default branch, then only the pushed commit message will be scanned to define if a bump should be performed.
In the case of a pull request, the action will adapt to the merging strategy chosen.
If the PR is merged using the merge commit strategy, then all the messages of all the commits in the branch will be scanned.
If the PR is merged using the squash merging strategy, all the commits will be squashed into one. Github typically joins the messages of all the squashed commits into the single commit that will be written to the target branch. This message typically looks like this from the squash of 3 commits:
Doing cool stuff (#3)
* feat: my cool feature
* chore: fixing stuff
* yolo
In that case, this message will be scanned to define whether a bump should be performed. In this example, it would result in a minor bump with the following config:
# [...]
- name: Bumping version
uses: jpb06/bump-package@latest
with:
major-keywords: BREAKING CHANGE
minor-keywords: feat,minor
patch-keywords: fix,chore
Commits messages starting with these keywords will trigger a major bump. Commas may be used to specify more than one keyword
Default value: [Major]:
Commits messages starting with these keywords will trigger a minor bump. Commas may be used to specify more than one keyword
Default value: [Minor]:
Commits messages starting with these keywords will trigger a patch bump. Commas may be used to specify more than one keyword
Default value: [Patch]:
If no keywords are present in branch commits, bump anyway by doing a patch.
Default value: false
Customizing the name of the user committing generated badges (optional).
Default value: <context.actor>
Customizing the email of the user committing generated badges (optional).
Default value: <context.actor>@users.noreply.github.com
true
if version has been bumped in package.json.
If the action runs on a commit whose message starts with either [Major]:
, [Minor]:
or [Patch]:
, the version will be bumped and a tag will be created.
name: package bump
on: [push]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
[...]
- name: Bumping version
uses: jpb06/bump-package@latest
The action will bump the package depending on commits present in the pull request when it is merged to the master branch. By priority order:
- if any commit message contains
BREAKING CHANGE
, then there will be a major bump. - if any commit message contains
feat
orminor
but none of the above, then there will be a minor bump. - if any commit message contains
fix
orchore
but none of the above, then there will be a patch bump.
A tag will also be created by the action.
name: package bump
on: [push]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
[...]
- name: Bumping version
uses: jpb06/bump-package@latest
with:
major-keywords: BREAKING CHANGE
minor-keywords: feat,minor
patch-keywords: fix,chore
You may want to bump the package version even if no keywords were present in the commits list (if merging a PR) or in the last commit (if pushing to master branch).
By setting should-default-to-patch
to true
you can trigger this behavior. Here is an example:
name: package bump
on: [push]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
[...]
- name: Bumping version
uses: jpb06/bump-package@latest
with:
major-keywords: BREAKING CHANGE
minor-keywords: feat,minor
patch-keywords: fix,chore
should-default-to-patch: true
Now let's imagine I'm running this action when merging a PR with the following commits:
- cool
- obnoxios commit message
- hey
Since no keywords were detected, the action will bump the package version with a patch: 1.0.0
-> 1.0.1
.
We may want to perform an action if package.json has been bumped. We can use bump-performed
output for this:
name: package bump
on: [push]
jobs:
bump:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
[...]
- name: Bumping version
id: bumping-version
uses: jpb06/bump-package@latest
- name: Publishing package
if: steps.bumping-version.outputs.bump-performed == 'true'
run: |
cd dist
yarn publish --non-interactive
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}