This action bumps and commits a node project's version using the Semantic Versioning system. The type of bump is determined by searching a target string with a list of keywords. The npm package semver is used for incrementing and validating the version.
- uses: 'dtgreene/keyword-version-bump@main'
with:
# The target word used for searching for keywords.
search-target: ''
# Case-sensitive, comma-separated list of words that trigger a major version bump.
# Default: ''
keywords-major: ''
# Case-sensitive, comma-separated list of words that trigger a minor version bump.
# Default: ''
keywords-minor: ''
# Case-sensitive, comma-separated list of words that trigger a patch version bump.
# Default: ''
keywords-patch: ''
# The default bump type used when no bump type can be determined by searching.
# If left blank, and no bump type can be determined, the action will exit without bumping.
# Default: ''
default-bump-type: ''
# The commit message to use when bumping the version. {version} will be replaced with the new version.
# https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
# Default: '[skip ci]: Automated version bump {version}'
commit-message: ''
# Path to an external json configuration file
# Default: ''
configuration: ''
The keywords for major
, minor
, and patch
bump types can be configured via the workflow. Additional bump types can be configured when using an external configuration file.
The available bump types are:
major
premajor
minor
preminor
patch
prepatch
prerelease
# The package version after being bumped
- bumped_version: ''
This action relies on actions/checkout for checking out the repo and setting up the environment.
The following is an example of a workflow that bumps a project's version after a pull request is merged into main. It searches for keywords in the pull request's title to determine the bump type.
In this example, changes will be made directly to the main
branch. In most repos that would fail due to branch protection rules. If no branch protection rules are in place, the default secrets.GITHUB_TOKEN
should have enough permissions.
Otherwise, a PAT (personal access token) that belongs to a user with the right permissions should be provided in the @actions/checkout step.
See actions/checkout for more info about the permission options.
name: Bump Version
on:
pull_request:
branches:
- main
types: [closed]
jobs:
bump:
name: Bump
runs-on: ubuntu-latest
if: ${{ github.event.pull_request.merged }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repo
uses: 'actions/checkout@v3'
with:
persist-credentials: true
ref: ${{ github.ref }}
token: ${{ secrets.BUMP_TOKEN }}
- name: Set Author
run: |
git config --local user.name 'Bump and Tag'
git config --local user.email '[email protected]'
- name: Bump Version
id: bump_version
uses: 'dtgreene/keyword-version-bump@main'
with:
search-target: ${{ github.event.pull_request.title }}
configuration: '.github/workflows/bump-version.config.json'
All configuration options aside from the search-target
can be configured through an external json file. Configuration options in the external file override any options provided through the workflow.
- name: Bump Version
uses: 'dtgreene/keyword-version-bump@main'
with:
search-target: ${{ github.event.pull_request.title }}
configuration: '.github/workflows/version-bump.config.json'
{
"bump_types": [
{
"type": "major",
"keywords": [],
},
{
"type": "minor",
"keywords": ["feat"],
},
{
"type": "patch",
"keywords": ["patch", "fix", "bug"],
}
],
"default_bump_type": "patch",
"commit_message": "[skip ci]: Automated version bump {version}"
}