# https://docs.gitlab.com/ee/user/packages/helm_repository/
include:
  - remote: https://open.greenhost.net/stackspin/stackspin/raw/main/.gitlab/ci_templates/kaniko.yml

stages:
  - test
  - package
  - build

# https://dnsmichi.at/2021/09/23/efficient-pipelines-gitlab-ci-cd-parallel-matrix-builds-reference/
.charts:
  parallel:
    matrix:
      - CHART: [personal-gitlab-exporter, restic-rest-server, tmate-ssh-server]

lint:
  stage: test
  image:
    name: alpine/helm:3.17.0
    entrypoint: ["/bin/sh", "-c"]
  script:
    - helm lint $CHART
  rules:
    - changes:
      - .gitlab-ci.yml
      - $CHART/**/*
  parallel: !reference [.charts,parallel]

package_charts:
  stage: package
  image:
    name: alpine/helm:3.17.0
    entrypoint: ["/bin/sh", "-c"]
  script:
    # The helm-push command is broken in Helm 3.7. For more information,
    # see the open issue in the Chart Museum project:
    # https://github.com/chartmuseum/helm-push/issues/109
    - apk add curl
    - mkdir public/
    - helm package -d public/ $CHART
    - 'chart_filename=$(ls public/${CHART}*)'
    - 'curl --request POST --user gitlab-ci-token:$CI_JOB_TOKEN --form "chart=@${chart_filename}" "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/helm/api/stable/charts"'
  rules:
    - changes:
      - .gitlab-ci.yml
      - $CHART/**/*
  parallel: !reference [.charts,parallel]