Skip to content
Snippets Groups Projects
Rules.yaml 2.66 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 un a `$DEV_BRANCH`, by default `develop`
# - the production code is in `$PROD_BRANCH`, by default `master`
# - the release tags are prefixed with `$RELEASE_TAG_PREFIX`, by
#   default `release/`
#
# Usage:
# echo-a-message-for-prod:
#   extends: .on-prod
#   script:
#     - echo This is a job running only from production branch
#
# Optional variables:
# - `PROD_BRANCH`: name of the production branch
# - `DEV_BRANCH`: name of the developpement branch
variables:
  PROD_BRANCH: master
  RELEASE_TAG_PREFIX: release/
  BUGFIX_PREFIX: bugfix/
  DEV_BRANCH: develop
  FEATURE_PREFIX: feature/
  HOTFIX_PREFIX: hotfix/

# This rules template should be used as the default rules.
# It select all branches except the production one.
# We always exclude schedules.
.not-on-prod:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: $CI_COMMIT_BRANCH == $PROD_BRANCH
      when: never
    - if: $CI_COMMIT_BRANCH
      when: on_success
# Select only branches that are not production or development.
# We always exclude schedules.
.on-branches:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    - if: $CI_COMMIT_BRANCH == $PROD_BRANCH
      when: never
    - if: $CI_COMMIT_BRANCH == $DEV_BRANCH
      when: never
    - if: $CI_COMMIT_TAG
      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 $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 production branch except for commits comming from `semantic-release`
# We always exclude schedules.
.on-prod:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Exclude semantic-release commits on $PROD_BRANCH
    - if: $CI_COMMIT_BRANCH == $PROD_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/
      when: never
    - if: $CI_COMMIT_BRANCH == $PROD_BRANCH
      when: on_success

# Select the protected release tags
# We always exclude schedules.
.on-release-tag:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "schedule"'
      when: never
    # Only for protected release tags
    - if: $CI_COMMIT_TAG =~ /^release\// && $CI_COMMIT_REF_PROTECTED
      when: on_success