Skip to content
Snippets Groups Projects
Rules.yaml 4.7 KiB
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/`
#
# 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]`
  RELEASE_TAG_PREFIX: release/
  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.
# We always exclude schedules.
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    - if: $CI_COMMIT_BRANCH
      when: on_success
# Select only branches that are not stable, testing or development.
# We always exclude schedules.
.on-branches:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
    - if: $CI_COMMIT_BRANCH == $TESTING_BRANCH
      when: never
    - if: $CI_COMMIT_BRANCH == $DEV_BRANCH
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    - if: $CI_COMMIT_BRANCH
      when: on_success
# Select the developpment branch except for commits comming from `semantic-release`
# We always exclude schedules.
.on-dev:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    # Exclude $CI_DEFAULT_BRANCH of semantic-release commits
    - if: $CI_COMMIT_BRANCH == $DEV_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
    - if: $CI_COMMIT_BRANCH == $DEV_BRANCH
      when: on_success
# Select the pre-release testing branch except for commits comming from `semantic-release`
# We always exclude schedules.
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    # Exclude $CI_DEFAULT_BRANCH of semantic-release commits
    - if: $CI_COMMIT_BRANCH == $TESTING_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
      when: never
    - if: $CI_COMMIT_BRANCH == $TESTING_BRANCH
      when: on_success

# Select the stable branch except for commits comming from `semantic-release`
# We always exclude schedules.
.on-stable:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    # Exclude $CI_DEFAULT_BRANCH of semantic-release commits
    - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
    - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
      when: on_success

# Select the protected release tags
# We always exclude schedules.
.on-release-tag:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Exclude `Draft` or `WIP` messages
    - if: $CI_COMMIT_MESSAGE =~ /(?:draft|wip):|\[(?:draft|wip)\]|\((?:draft|wip)\)/i
      when: never
    # Only for protected release tags
    - if: $CI_COMMIT_TAG =~ /^release\// && $CI_COMMIT_REF_PROTECTED
      when: on_success