name: Bump version
on:
pull_request:
types:
- closed
branches:
- master
jobs:
build:
if: github.event.pull_request.merged == true
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
PRERELEASE: true
Github Tag Action
A GitHub Action to tag a repo on merge.
What is GitHub Tag Action?β
GitHub Tag Action automatically bumps the version and tags the master branch based on semantic versioning (SemVer) formatting. Itβs a helpful tool to keep your repository versions up-to-date with minimal manual input.
How to Use GitHub Tokenβ
The GITHUB_TOKEN is required to give permission to tag the repository. This should be stored securely in your GitHub secrets.
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
How to Set Default Bump Typeβ
The DEFAULT_BUMP determines the default version bump type (e.g., major, minor, or patch) when no specific tag is found in the commit message.
with:
DEFAULT_BUMP: minor
How to Define the Default Branchβ
Use the DEFAULT_BRANCH to specify a branch other than master or main as the default branch for version bumps.
with:
DEFAULT_BRANCH: develop
How to Add "v" Prefix to Version Tagsβ
The WITH_V input lets you prefix your version tags with "v" (e.g., v1.0.0).
with:
WITH_V: true
How to Define Release Branchesβ
The RELEASE_BRANCHES option defines which branches generate release tags. Other branches generate pre-release versions with commit hashes.
with:
RELEASE_BRANCHES: master,release/*
How to Set a Custom Tagβ
The CUSTOM_TAG option lets you define a custom tag, which is useful when you want to set specific versioning strategies, such as when using Docker images.
with:
CUSTOM_TAG: my-custom-tag
How to Operate on a Relative Pathβ
The SOURCE option allows the action to operate on a relative path under $GITHUB_WORKSPACE.
with:
SOURCE: my-subdirectory/
How to Perform a Dry Runβ
The DRY_RUN option simulates the next version bump without actually tagging the branch. Itβs useful for testing your workflow.
with:
DRY_RUN: true
How to Use GitHub API for Taggingβ
You can specify whether to use the GitHub API or git CLI for tagging operations using the GIT_API_TAGGING option. By default, it uses the API.
with:
GIT_API_TAGGING: true
How to Set Initial Versionβ
The INITIAL_VERSION option sets the initial version before the first bump (default: 0.0.0).
with:
INITIAL_VERSION: 1.0.0
How to Specify Tag Contextβ
The TAG_CONTEXT option determines whether to base the version tag on the entire repository (repo) or just the current branch (branch).
with:
TAG_CONTEXT: branch
How to Enable Pre-release Modeβ
The PRERELEASE option enables pre-release mode, which appends a pre-release identifier to the version tag.
with:
PRERELEASE: true
How to Set Pre-release Suffixβ
The PRERELEASE_SUFFIX option allows you to define a custom suffix for pre-releases (default: beta).
with:
PRERELEASE_SUFFIX: alpha
How to Set Verbose Loggingβ
Enable verbose logging by setting the VERBOSE option to true. This will print git logs, which can help with debugging.
with:
VERBOSE: true
How to Customize Commit Message Tagsβ
You can customize the commit message tags used for version bumps (#major, #minor, #patch) using the respective options.
with:
MAJOR_STRING_TOKEN: #breaking-change
MINOR_STRING_TOKEN: #feature
PATCH_STRING_TOKEN: #bugfix





