diff --git a/templates/Lint/Commitlint.yaml b/templates/Lint/Commitlint.yaml index 3285cc5e851cb1d617392b0d842516a0b79896d3..93126cb859f4fc4edc9554c6b47a5b9cde127d64 100644 --- a/templates/Lint/Commitlint.yaml +++ b/templates/Lint/Commitlint.yaml @@ -3,7 +3,7 @@ --- commitlint: stage: lint - extends: .default_rules + extends: .not-on-prod image: 'hub.eole.education/eole/commitlint:latest' before_script: # Add `upstream` remote to get access to `upstream/master` diff --git a/templates/Rules.yaml b/templates/Rules.yaml index 757de88195030fd4388ef5f37947853daf887411..4f7529023e81a3a5c39c5a99634db5b2cc83555c 100644 --- a/templates/Rules.yaml +++ b/templates/Rules.yaml @@ -1,40 +1,90 @@ -# -*- coding: utf-8 -*- +# -*- mode: yaml; coding: utf-8 -*- # vim: ft=yaml +# +# 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 --- -############################################################################### -# Define rules templates to be used by jobs -############################################################################### -# Rules used by default -.default_rules: +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: rules: - # Exclude $CI_DEFAULT_BRANCH of semantic-release commits - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/ + - if: '$CI_PIPELINE_SOURCE == "schedule"' + when: never + - if: $CI_COMMIT_BRANCH == $PROD_BRANCH when: never - # All branches - if: $CI_COMMIT_BRANCH + when: on_success -# Build on branches and release tag push -.build_rules: +# Select only branches that are not production or development. +# We always exclude schedules. +.on-branches: rules: - # Exclude $CI_DEFAULT_BRANCH of semantic-release commits - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/ + - 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 - # All branches - if: $CI_COMMIT_BRANCH - # Only for protected release tags - - if: $CI_COMMIT_TAG =~ /^release\// && $CI_COMMIT_REF_PROTECTED + when: on_success -# Run semantic release only on $CI_DEFAULT_BRANCH except for release commits -.release_rules: +# Select the developpment branch except for commits comming from `semantic-release` +# We always exclude schedules. +.on-dev: rules: + - if: '$CI_PIPELINE_SOURCE == "schedule"' + when: never # Exclude $CI_DEFAULT_BRANCH of semantic-release commits - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/ + - if: $CI_COMMIT_BRANCH == $DEV_BRANCH && $CI_COMMIT_MESSAGE =~ /^chore\(release\):/ when: never - - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH + - if: $CI_COMMIT_BRANCH == $DEV_BRANCH + when: on_success -# Run on published release tags -.tag_rules: +# Select the production branch except for commits comming from `semantic-release` +# We always exclude schedules. +.on-prod: rules: + - 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 ...