---
include:
  - local: 'images/.utils/gitlab-ci.yaml'
  - local: 'charts/.utils/gitlab-ci.yaml'
stages:
  - lint
  - build
  - changelog
  - release


# Automated month-based releases
release-changelog-full:
  stage: changelog
  image: quay.io/git-chglog/git-chglog:0.15.4
  variables:
    GIT_STRATEGY: clone
    GIT_DEPTH: 0
  script:
    - git-chglog --template .chglog/unreleased.tpl.md --next-tag "v$(date +%y.%m)" --output RELEASENOTES.md
  artifacts:
    paths:
      - RELEASENOTES.md
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $INFRA_RELEASE_NOW == "true" && $CI_COMMIT_TAG == null'
  tags:
    - kubernetes


release-branch:
  stage: release
  image: registry.gitlab.com/gitlab-org/release-cli
  variables:
    GIT_STRATEGY: clone
    GIT_DEPTH: 0
  before_script:
    - apk add --no-cache git
    - export INFRA_RELEASE_VERSION="$(date +%y.%m)"
    - export INFRA_RELEASE_NAME="GitOps Infrastructure $INFRA_RELEASE_VERSION"
    - export INFRA_RELEASE_DESCRIPTION="$(cat RELEASENOTES.md && printf "\n\n---\n*This is an automated release. See [#${CI_JOB_ID}]($CI_JOB_URL) for details.*")"
  script:
    - >
      release-cli create --name "$INFRA_RELEASE_NAME" --description "$INFRA_RELEASE_DESCRIPTION"
      --tag-name "v${INFRA_RELEASE_VERSION}" --ref $CI_COMMIT_SHA
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $INFRA_RELEASE_NOW == "true" && $CI_COMMIT_TAG == null'
  tags:
    - kubernetes