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
You can find the configuration option in
Settings -> Actions -> Workflow permissions
.
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
You can also run the action by depending on another workflow. In that case the commits messages will be extracted from the completed
webhook event:
[...]
on:
workflow_run:
workflows: ['my-other-workflow']
types:
- completed
jobs:
version-bump:
name: π Version bump
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
[...]
- name: β« Bump package version
id: bumping-version
uses: jpb06/bump-package@latest
Path location of the package to bump. Useful for monorepos.
Default value: .
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
Debug mode. Will display event github event data.
Default value: false
true
if version has been bumped in package.json.
The resolved new version. For example, if initial version is 1.1.1
and bump type is patch
, then new-version
will be 1.1.2
.
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 version bump
on: [push]
jobs:
bump:
name: π Version bump
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v4
[...]
- 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 version bump
on: [push]
jobs:
bump:
name: π Version version bump
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v4
[...]
- 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 version bump
on: [push]
jobs:
bump:
name: π Version bump
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v4
[...]
- 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 version bump
on: [push]
jobs:
bump:
name: π Version bump
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v4
[...]
- 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 }}
You can also get the new version using new-version
output:
- name: Display action output
run: |
echo "New version: ${{ steps.bumping-version.outputs.new-version }}"
You can use the input cwd
to perform a bump for a monorepo app or package. The following job would bump the package.json file located at ./libs/my-package/package.json
:
name: β‘ Package version bump
on: [push]
jobs:
bump:
name: π Version bump
runs-on: ubuntu-latest
steps:
- name: β¬οΈ Checkout repo
uses: actions/checkout@v4
[...]
- name: β« Bumping version
uses: jpb06/bump-package@latest
with:
cwd: ./libs/my-package
Example:
Eexample:
chore(my-package): bump version to v2.3.0