Bump the semver for a Gitlab CI project based on merge request labels
3.1K
Bump the semver for a Gitlab CI project based on merge request labels.
If no current command was used nor any of bump command then labels of the
Merge Requests are taken either from $CI_MERGE_REQUEST_LABELS environment
variable or from details of the Merge Requests pointed by the commit message
from $CI_COMMIT_MESSAGE environment variable.
Commit message should contain the string See merge request PROJECT!NUMBER.
To fetch the details of the Merge Request the tool needs the Gitlab API token
with the read_api scope. The token is taken from the $GITLAB_TOKEN
environment variable by default.
Versions printed by this tool are normalized. It means that v prefix is
always trimmed from the output.
The best result is when merge trains are enabled in the merge options for the project. In this case, it is possible to verify the bumped version before the actual merge is done.
gitlab-ci-semver-labels [command] [flags]
bump Bump version
current Show current version
help Help about any command
initial Set to initial version without checking labels
major Bump major version without checking labels
minor Bump minor version without checking labels
patch Bump patch version without checking labels
prelease Bump prelease version without checking labels
--commit-message-regexp REGEXP REGEXP for commit message after merged MR (default "(?s)(?:^|\\n)See merge request (?:\\w[\\w.+/-]*)?!(\\d+)")
-d, --dotenv-file FILE write dotenv format to FILE
-D, --dotenv-var NAME variable NAME in dotenv file (default "VERSION")
-f, --fail fail if merge request are not matched
-T, --fetch-tags fetch tags from git repo (default true)
-t, --gitlab-token-env VAR name for environment VAR with Gitlab token (default "GITLAB_TOKEN")
-g, --gitlab-url URL URL of the Gitlab instance (default "https://gitlab.com")
-h, --help help for gitlab-ci-semver-labels
--initial-label-regexp REGEXP REGEXP for initial release label (default "(?i)initial.release|semver(.|::)initial")
-V --initial-version VERSION initial VERSION for initial release (default "0.0.0")
--major-label-regexp REGEXP REGEXP for major (breaking) release label (default "(?i)(major|breaking).release|semver(.|::)(major|breaking)")
--minor-label-regexp REGEXP REGEXP for minor (feature) release label (default "(?i)(minor|feature).release|semver(.|::)(minor|feature)")
--patch-label-regexp REGEXP REGEXP for patch (fix) release label (default "(?i)(patch|fix).release|semver(.|::)(patch|fix)")
--prerelease-label-regexp REGEXP REGEXP for prerelease label (default "(?i)pre.?release")
-p, --project PROJECT PROJECT id or name (default $CI_PROJECT_ID)
-r, --remote-name NAME NAME of git remote (default "origin")
-v, --version VERSION for gitlab-ci-semver-labels
-C, --work-tree DIR DIR to be used for git operations (default ".")
Some options can be read from the configuration file
.gitlab-ci-semver-labels.yml:
commit-message-regexp: (?s)(?:^|\n)See merge request (?:\w[\w.+/-]*)?!(\d+)
dotenv-file: ""
dotenv-var: VERSION
fail: false
fetch-tags: true
gitlab-token-env: GITLAB_TOKEN
gitlab-url: https://gitlab.com
initial-label-regexp: (?i)initial.release|semver(.|::)initial
initial-version: 0.0.0
major-label-regexp: (?i)(major|breaking).release|semver(.|::)(major|breaking)
minor-label-regexp: (?i)(minor|feature).release|semver(.|::)(minor|feature)
patch-label-regexp: (?i)(patch|fix).release|semver(.|::)(patch|fix)
prerelease-label-regexp: (?i)pre.?release
project: dex4er/gitlab-ci-semver-labels
remote-name: origin
work-tree: .
Any option might be overridden with an environment variable with the name the
same as an option with the prefix GITLAB_CI_SEMVER_LABELS_ and an option name
with all capital letters with a dash character replaced with an underscore. Ie.:
GITLAB_CI_SEMVER_LABELS_FETCH_TAGS="false"
Additionally $CI_PROJECT_ID is used as a default project option value and
$CI_SERVER_URL as a default gitlab-url option value.
Example .gitlab-ci.yml:
variables:
DOCKER_IO: docker.io
stages:
- semver
- release
semver:validate:
stage: semver
rules:
- if: $CI_MERGE_REQUEST_LABELS =~ /semver::/ && $CI_MERGE_REQUEST_EVENT_TYPE == 'merge_train'
image:
name: $DOCKER_IO/dex4er/gitlab-ci-semver-labels
entrypoint: [""]
variables:
GIT_DEPTH: 0
script:
- gitlab-ci-semver-labels current || true
- gitlab-ci-semver-labels bump --fail
semver:bump:
stage: semver
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /(^|\n)See merge request (\w[\w.+\/-]*)?!\d+/s
image:
name: $DOCKER_IO/dex4er/gitlab-ci-semver-labels
entrypoint: [""]
variables:
GIT_DEPTH: 0
script:
- gitlab-ci-semver-labels current || true
- gitlab-ci-semver-labels bump --dotenv-file=semver.env
artifacts:
reports:
dotenv: semver.env
release:
stage: release
needs:
- semver:bump
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /(^|\n)See merge request (\w[\w.+\/-]*)?!\d+/s
image: registry.gitlab.com/gitlab-org/release-cli
script:
- test -n "$VERSION" && release-cli create
--name "v$VERSION"
--description "Automatic release by gitlab-ci-semver-labels"
--tag-name "v$VERSION"
--ref $CI_COMMIT_SHA
Content type
Image
Digest
sha256:c25233a8d…
Size
8.1 MB
Last updated
almost 3 years ago
docker pull dex4er/gitlab-ci-semver-labels