From e3a70f30fef4f355e57531d151f481519ff7aac7 Mon Sep 17 00:00:00 2001
From: Sheogorath <sheogorath@shivering-isles.com>
Date: Mon, 26 Sep 2022 01:23:30 +0200
Subject: [PATCH] ci(charts): Fix broken CI rules

Currently gitlab-ci doesn't allow variables in `exists` rules, which
means the condition below can't be used. This is fixed by moving the
condition into the script and just exit successful if the tests don't
exist.

Further it adds a requirement for the chart-package job to wait for the
chart-helm-unittest job(s) before, this should help to prevent the
release of broken charts.

Finally we namespace the junit files generated during the tests, since
they would overwrite each other, if multiple helm charts would run the
CI jobs at the same time.

References:
https://docs.gitlab.com/ee/ci/yaml/#needs
https://docs.gitlab.com/ee/ci/yaml/#rulesexists
---
 charts/.utils/gitlab-ci.yaml | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/charts/.utils/gitlab-ci.yaml b/charts/.utils/gitlab-ci.yaml
index 46ab14fb5..123ccb894 100644
--- a/charts/.utils/gitlab-ci.yaml
+++ b/charts/.utils/gitlab-ci.yaml
@@ -8,6 +8,8 @@
 chart-package:
   stage: build
   extends: .chart-matrix
+  needs:
+    - chart-helm-unittest
   image: quay.io/helmpack/chart-testing:v3.6.0
   script:
     - export TMP_DIR=$(mktemp -d)
@@ -25,15 +27,14 @@ chart-helm-unittest:
     name: docker.io/quintush/helm-unittest:3.10.0-0.2.9
     entrypoint: [""]
   script:
-    - helm unittest -3 -o helm-unittest.xml -t junit charts/${CHART}
+    - if [ ! -e charts/${CHART}/tests ]; then echo "No helm unittests"; exit 0; fi
+    - helm unittest -3 -o helm-unittest-${CHART}.xml -t junit charts/${CHART}
   artifacts:
     when: always
     reports:
       junit:
-        - helm-unittest.xml
+        - helm-unittest-${CHART}.xml
   rules:
     - if: '$CI_PIPELINE_SOURCE == "push"'
       changes:
         - charts/${CHART}/**/*
-      exists:
-        - charts/${CHART}/tests/**/*
-- 
GitLab