This GitHub Action automatically bumps the project version based on pull request (PR) labels and creates a PR. Once the version bump PR is merged, it automatically creates a new tag and a release (optional) for the bumped version.
This action follows the principles of semantic versioning, incrementing the version number based on the labels applied to the PR.
- Automatically determines the version bump type based on PR labels.
- Uses bump-my-version to increment the version according to semantic versioning.
- Creates a new branch and a PR for the version bump.
- Generates a corresponding Git tag once the version bump PR is merged.
- Optionally creates a GitHub Release for the new tag.
Below are example workflows you can add to your repository to automatically bump the version when a PR is merged.
You can save them in a file such as .github/workflows/bump-version.yaml.
Make sure your workflow includes the following:
- The
on: pull_request: types: [closed]trigger to run the workflow whenever a PR is closed. - The condition
if: github.event.pull_request.merged == trueto ensure the workflow only proceeds if the PR was merged. - The
permissions:section to allow the workflow to update repository contents and PRs.
name: Bump Version
on:
pull_request:
types: [closed]
jobs:
bump-version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Bump Version
uses: conjikidow/[email protected]
with:
label-major: 'major update'
label-minor: 'minor update'
label-patch: 'patch update'
labels-to-add: 'automated,version-bump'
create-release: 'true'You can also integrate this action with external tools or actions by using the outputs provided.
The following example uses softprops/action-gh-release to create a GitHub Release when the version has actually been bumped:
name: Bump Version with External Release
on:
pull_request:
types: [closed]
jobs:
bump-version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Bump Version
id: bump-version
uses: conjikidow/[email protected]
# This step is just a placeholder. You can replace it with your own script or external tools.
- name: Create Release Notes
if: steps.bump-version.outputs.version-bumped == 'true'
run: |
cat <<EOF > custom-release-notes.md
## What's Changed
...
EOF
- name: Create GitHub Release
if: steps.bump-version.outputs.version-bumped == 'true'
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.bump-version.outputs.new-version }}
body_path: custom-release-notes.md| Name | Description | Required | Default |
|---|---|---|---|
github-token |
The GitHub token for authentication. | No | ${{ github.token }} |
version-of-bump-my-version |
The version of bump-my-version to use. |
No | 'latest' |
label-major |
The label used to trigger a major version bump. | No | 'major' |
label-minor |
The label used to trigger a minor version bump. | No | 'minor' |
label-patch |
The label used to trigger a patch version bump. | No | 'patch' |
branch-prefix |
The prefix for the version bump branch name. | No | 'workflow' |
labels-to-add |
Comma-separated string of labels to add to the PR for version bumping. | No | '' |
create-release |
Whether to create a GitHub Release for the new tag. | No | 'false' |
Tip
Set any of label-major, label-minor, or label-patch to an empty string ('') if you want to disable that bump type.
Warning
Any labels specified in labels-to-add must already exist in your repository. If they do not, create them in advance to avoid errors.
| Name | Description |
|---|---|
version-bumped |
true if the version was bumped and a new tag was created; otherwise, false. |
new-version |
The new version number (e.g., 1.2.4). This is empty when version-bumped is false. |
To use this action, ensure that your project is configured to work with bump-my-version.
Below is an example .bumpversion.toml configuration file:
[tool.bumpversion]
current_version = "0.1.0"
commit = false
tag = false
[[tool.bumpversion.files]]
filename = "pyproject.toml"
search = 'version = "{current_version}"'
replace = 'version = "{new_version}"'
[[tool.bumpversion.files]]
filename = "CMakeLists.txt"
search = "VERSION {current_version}"
replace = "VERSION {new_version}"Important
commit and tag should be set to false because this action handles these tasks automatically.
To generate a default configuration file, run the following command:
uvx bump-my-version sample-config --no-prompt --destination .bumpversion.tomlFor more details, refer to the official bump-my-version documentation.
To enable GitHub Actions to run properly in your repository, you need to adjust the default permissions granted to the GITHUB_TOKEN.
Follow these steps to configure the permissions:
- Go to the Settings tab of your repository.
- On the left-hand menu, select Actions/General.
- Under the Workflow permissions section, ensure the following options are selected:
Read and write permissions: This grants read and write access to the repository for all scopes.Allow GitHub Actions to create and approve PRs: This allows GitHub Actions to create PRs.
- Save the changes.
-
Checks if the PR is merged
- If not merged, the action skips execution.
-
Determines the bump type
- Extracts PR labels and determines whether a major, minor, or patch bump is required, in accordance with semantic versioning.
- If no matching labels are found, the process stops.
-
Runs
bump-my-versionto bump the version- Uses
bump-my-version@latest(or specified version). - Checks if the version was actually updated.
- Uses
-
Creates a new branch and PR for the version bump
- If the version is updated, a new branch (
${branch-prefix}/bump-version-from-X.Y.W-to-X.Y.Z) is created. - A PR is automatically opened to merge the version bump.
- If the version is updated, a new branch (
-
After merging, creates a Git tag
- The branch name is parsed to extract the new version number.
- A Git tag (
vX.Y.Z) is pushed to mark the new release.
-
Optionally creates a GitHub Release
- If
create-releaseis set totrue, a GitHub Release is created for the new tag, with automatically generated release notes.
- If
In addition to the full version tag (vX.Y.Z), this action updates existing major (vX) and minor (vX.Y) tags based on the following rules:
- If
vX.Yexists → update tovX.Y.Z. - If
vX.Ydoes not exist but a previous minor tag (vX.Ybefore the update) exists → createvX.Yand set it tovX.Y.Z. - If
vXexists → update tovX.Y.Z. - If
vXdoes not exist but a previous major tag (vXbefore the update) exists → createvXand set it tovX.Y.Z. - If neither
vXnorvX.Yexist, they are not created.
v1.2.3 → v1.2.4: Updatev1.2andv1if they exist.v1.2.3 → v1.3.0: Createv1.3ifv1.2exists, updatev1if it exists.v1.2.3 → v2.0.0: Createv2.0ifv1.2exists, createv2ifv1exists.
Contributions, bug reports, and feedback are always welcome! Thank you for helping improve this project for everyone!
