Newer
Older
# -*- mode: yaml; coding: utf-8 -*-
#
# Define variables and rules to work in a git-flow like workflow
# See https://nvie.com/posts/a-successful-git-branching-model/
#
# - the developpment is done in a `$DEV_BRANCH`, by default `dev`
# - the pre-release fixes are done in a `$TESTING_BRANCH`, by default `testing`
# - the stable code is in `$STABLE_BRANCH`, by default `stable`
# - the release tags are prefixed with `$RELEASE_TAG_PREFIX`, by
# default `release/`
#
# USAGE
# =====
#
# echo-a-message-for-stable:
# extends: .on-stable
# - echo "This is a job running only from stable branch"
# OPTIONAL VARIABLES
# ==================
#
# - `STABLE_BRANCH`: name of the stable branch
# - `TESTING_BRANCH`: name of the pre-release testing branch
# - `DEV_BRANCH`: name of the developpement branch
# IMPORTANT NOTE
# ==============
#
# - Scheduled pipelines are always excluded.
# - Commit message containing the following are skipped:
# - default skip pattern https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/pipeline/chain/skip.rb#L10
# - message containing `draft` or `wip` (case insensitive) either followed by colon `:`
# or surrounded by brakets `[]` or parethesis `()`, for example:
# - `Draft: foo`
# - `wip foo`
# - `foo (draft)`
# - `foo [WIP]`
# - message generated by `semantic-release`
STABLE_BRANCH: stable
HOTFIX_PREFIX: hotfix/
TESTING_BRANCH: testing
DEV_BRANCH: dev
BUGFIX_PREFIX: bugfix/
FEATURE_PREFIX: feature/
# This rules template should be used as the default rules.
# It select all branches except the stable one.
.not-on-stable:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-stable]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-branch]
# Select only branches that are not stable, testing or development.
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-tag]
- !reference [.rules-map, not-on-stable]
- !reference [.rules-map, not-on-testing]
- !reference [.rules-map, not-on-dev]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-branch]
# Select the developpment branch
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-dev]
# Select the pre-release testing branch
.on-testing:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-testing]
# Select the stable branch
.on-stable:
rules:
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, not-on-semantic-release-commit]
- !reference [.rules-map, on-stable]
# Select the protected release tags
.on-release-tag:
rules:
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
- !reference [.rules-map, not-on-schedule]
- !reference [.rules-map, not-on-draft]
- !reference [.rules-map, on-release-tag]
# We use a single rules hash to be referenced as array elements by
# individual rules templates above.
# This avoid the duplication of rules conditions
#
# SEE ALSO
# ========
#
# - https://forum.gitlab.com/t/add-conditions-to-rules-array-merged-with-reference/62600
# - https://gitlab.com/gitlab-org/gitlab/-/issues/322992
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67922
# - https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67922
.rules-map:
not-on-schedule:
if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
not-on-tag:
if: $CI_COMMIT_TAG
when: never
not-on-stable:
if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
when: never
not-on-testing:
if: $CI_COMMIT_BRANCH == $TESTING_BRANCH
when: never
not-on-dev:
if: $CI_COMMIT_BRANCH == $DEV_BRANCH
when: never
not-on-draft:
# Exclude `Draft` or `WIP` messages
if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
when: never
not-on-semantic-release-commit:
# Exclude $CI_DEFAULT_BRANCH of semantic-release commits
if: $CI_COMMIT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
when: never
on-branch:
if: $CI_COMMIT_BRANCH
when: on_success
on-stable:
if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
when: on_success
on-testing:
if: $CI_COMMIT_BRANCH == $TESTING_BRANCH
when: on_success
on-dev:
if: $CI_COMMIT_BRANCH == $DEV_BRANCH
when: on_success
on-tag:
if: $CI_COMMIT_TAG
when: on_success
on-release-tag:
if: $CI_COMMIT_TAG =~ /^release\// && $CI_COMMIT_REF_PROTECTED
when: on_success