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
Monitoring GitHub Actions Workflows
CICube is a GitHub Actions monitoring tool that provides you with detailed insights into your workflows to further optimize your CI/CD pipeline. With CICube, you will be able to track your workflow runs, understand where the bottlenecks are, and tease out the best from your build times. Go to cicube.io now and create a free account to better optimize your GitHub Actions workflows!