Skip to content
Snippets Groups Projects
Semantic-release.yaml 2.81 KiB
Newer Older
# -*- coding: utf-8 -*-
# vim: ft=yaml
---
# Produce a new release using semantic versionning scheme when new
# commits arrive on the production branch.
#
# USAGE
# =====
#
# include:
#   - project: EOLE/infra/ci-tools
#     ref: stable
#     file: /templates/Release/Semantic-release.yaml
#
# REQUIREMENTS
# ============
#
# - A `release` stage must be present in your pipeline
# - One of the `semantic-release` configuration file must be present
#   - `release.config.js`
#   - `.releaserc`
#   - `.releaserc.js`
#   - `.releaserc.json`
#   - `.releaserc.yaml`
#   - `.releaserc.yml`
# - an access token named `GITLAB_TOKEN` with
#   - `api`
#   - `read_repository`
#   - `write_repository`
# - The variable `$STABLE_BRANCH` defined
#
# OPTIONAL VARIABLES
# ==================
#
# - `SEMANTIC_RELEASE_IMAGE`: name of the `semantic-release` docker
#   image to use
#
# SEE ALSO
# ========
#
# - Semantic release software: https://github.com/semantic-release/semantic-release/
# - Commitlint: https://github.com/conventional-changelog/commitlint/
#
# IMPORTANT NOTE
# ==============
#
# We can't merge rules with `!reference` until we switch to Gitlab >= 14.3
# https://gitlab.com/gitlab-org/gitlab/-/issues/322992
# Use a `.rules-map` as a workaround
#
semantic-release:
  extends: .semantic-release:stable

.on-stable-with-semantic-release-config:
  rules:
    - !reference [.rules-map, not-on-schedule]
    - !reference [.rules-map, not-on-draft]
    - !reference [.rules-map, not-on-semantic-release-commit]
    - if: $CI_COMMIT_BRANCH == $STABLE_BRANCH
      exists:
        - release.config.js
        - .releaserc
        - .releaserc.yaml
        - .releaserc.yml
        - .releaserc.json
        - .releaserc.js
      when: on_success

.on-testing-with-semantic-release-config:
  rules:
    - !reference [.rules-map, not-on-schedule]
    - !reference [.rules-map, not-on-draft]
    - !reference [.rules-map, not-on-semantic-release-commit]
    - if: $CI_COMMIT_BRANCH == $TESTING_BRANCH
      exists:
        - release.config.js
        - .releaserc
        - .releaserc.yaml
        - .releaserc.yml
        - .releaserc.json
        - .releaserc.js
      when: on_success

.on-dev-with-semantic-release-config:
  rules:
    - !reference [.rules-map, not-on-schedule]
    - !reference [.rules-map, not-on-draft]
    - !reference [.rules-map, not-on-semantic-release-commit]
    - if: $CI_COMMIT_BRANCH == $DEV_BRANCH
      exists:
        - release.config.js
        - .releaserc
        - .releaserc.yaml
        - .releaserc.yml
        - .releaserc.json
        - .releaserc.js
      when: on_success

.semantic-release:stable:
  stage: release
  extends: .on-stable-with-semantic-release-config
  image: "$SEMANTIC_RELEASE_IMAGE"
  variables:
    SEMANTIC_RELEASE_IMAGE: 'hub.eole.education/eole/semantic-release-gitlab:latest'