Fork from anothrNick/github-tag-action, make it generic and focus to generate the next tag name only.
This docker image can be used in any git projects, whatever it is github, gitlab, bitbucket, azure devops, and so on.
$ docker build -t git-tag .
$ cd <git_project>
# get the next tag name
$ docker run -ti --rm -v $(pwd):/workspace -w /workspace git-tag
generate_tag:
stage: tag
image: alpine/git-tag:latest
rules:
- if: $CI_COMMIT_TAG
when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when commits are pushed or merged to the default branch
script:
- echo "create tag for branch $CI_DEFAULT_BRANCH"
- /entrypoint.sh
- cat build.env
- echo "CI_COMMIT_REF_NAME is ${CI_COMMIT_REF_NAME}"
artifacts:
reports:
dotenv: build.env
release_job:
stage: tag
image: registry.gitlab.com/gitlab-org/release-cli:latest
needs: ["generate_tag"]
rules:
- if: $CI_COMMIT_TAG
when: never # Do not run this job when a tag is created manually
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH # Run this job when commits are pushed or merged to the default branch
script:
- echo "running release_job for $tagName"
- echo "CI_COMMIT_REF_NAME is ${CI_COMMIT_REF_NAME}"
release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties
tag_name: '$tagName'
description: '$tagName'
ref: '$CI_COMMIT_SHA' # The tag is created from the pipeline SHA.
Environment Variables
- 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). - INITIAL_VERSION (optional) - Set initial version before bump. Default
0.0.0
. - TAG_CONTEXT (optional) - Set the context of the previous tag. Possible values are
repo
(default) orbranch
. - PRERELEASE_SUFFIX (optional) - Suffix for your prerelease versions,
beta
by default. Note this will only be used if a prerelease branch. - VERBOSE (optional) - Print git logs. For some projects these logs may be very large. Possible values are
true
(default) andfalse
.
- new_tag - The value of the newly created tag.
- tag - The value of the latest tag after running this action.
- part - The part of version which was bumped.
Note: This action creates a lightweight tag.
Manual Bumping: Any commit message that includes #major
, #minor
, #patch
, or #none
will trigger the respective version bump. If two or more are present, the highest-ranking one will take precedence.
If #none
is contained in the commit message, it will skip bumping regardless DEFAULT_BUMP
.
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). Disable this by setting DEFAULT_BUMP
to none
.
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), the action will:
- Get latest tag
- Bump tag with minor version unless any commit message contains
#major
or#patch
- Pushes tag to github
- If triggered on your repo's default branch (
master
ormain
if unchanged), the bump version will be a release tag. - If triggered on any other branch, a prerelease will be generated, depending on the bump, starting with
*-<PRERELEASE_SUFFIX>.1
,*-<PRERELEASE_SUFFIX>.2
, ...
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.