---
# https://github.com/semantic-release/semantic-release#commit-message-format
# https://levelup.gitconnected.com/semantic-versioning-and-release-automation-on-gitlab-9ba16af0c21

variables:
  BADGE_semantic_release: "version-${CI_COMMIT_TAG}-informational"
  BADGE_semantic_release_URL: "${CI_PROJECT_URL}/tags/${CI_COMMIT_TAG}"

semantic-release:
  image: registry.gitlab.com/notno/semantic-release-gitlab:latest
  stage: .post
  variables:
    EXTRA_ARGS: ""
  script:
    - |
      if ! test -f .releaserc; then
        echo "[!] No '.releaserc' file found. The job will probably fail."
        echo "See https://gitlab.com/notno/ci-templates/-/blob/master/.releaserc for an example."
        echo "See https://semantic-release.gitbook.io/semantic-release/usage/configuration on how to configure semantic-release."
      fi
    - npm install -g semantic-release @semantic-release/gitlab @semantic-release/git @semantic-release/changelog
    - semantic-release ${EXTRA_ARGS}
  rules:
    - if: $CI_COMMIT_TAG
      when: never
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
