A Github Action to automatically bump and tag master, on merge, with the latest SemVer formatted version.
Medium Post: Creating A Github Action to Tag Commits
name: Bump version
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
fetch-depth: '0'
- name: Bump version and push tag
uses: anothrNick/github-tag-action@1.17.2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
WITH_V: true
NOTE: set the fetch-depth for actions/checkout@master
to be sure you retrieve all commits to look for the semver commit message.
Environment Variables
- GITHUB_TOKEN (required) - Required for permission to tag the repo.
- DEFAULT_BUMP (optional) - Which type of bump to use when none explicitly provided (default:
minor
). - WITH_V (optional) - Tag version with
v
character. - RELEASE_BRANCHES (optional) - Comma separated list of branches (bash reg exp accepted) that will generate the release tags. Other branches and pull-requests generate versions postfixed with the commit hash and do not generate any tag. Examples:
master
or.*
orrelease.*,hotfix.*,master
... - CUSTOM_TAG (optional) - Set a custom tag, useful when generating tag based on f.ex FROM image in a docker image. Setting this tag will invalidate any other settings set!
- SOURCE (optional) - Operate on a relative path under $GITHUB_WORKSPACE.
- DRY_RUN (optional) - Determine the next version without tagging the branch. The workflow can use the outputs
new_tag
andtag
in subsequent steps. Possible values aretrue
andfalse
(default).
- new_tag - The value of the newly created tag.
- tag - The value of the latest tag after running this action.
Note: This action creates a lightweight tag.
Manual Bumping: Any commit message that includes #major
, #minor
, or #patch
will trigger the respective version bump. If two or more are present, the highest-ranking one will take precedence.
Automatic Bumping: If no #major
, #minor
or #patch
tag is contained in the commit messages, it will bump whichever DEFAULT_BUMP
is set to (which is minor
by default).
Note: This action will not bump the tag if the
HEAD
commit has already been tagged.
- Add this action to your repo
- Commit some changes
- Either push to master or open a PR
- On push (or merge) to
master
, the action will:- Get latest tag
- Bump tag with minor version unless any commit message contains
#major
or#patch
- Pushes tag to github
A list of projects using github-tag-action for reference.
-
another/github-tag-action (uses itself to create tags)
-
Access JSON structure with HTTP path parameters as keys/indices to the JSON.