From 62f3b61e9d6d03d1905a4b228fb8ed94b6b48ebd Mon Sep 17 00:00:00 2001 From: Alex Lebens Date: Sun, 17 May 2026 22:11:14 -0500 Subject: [PATCH] ci: handle errors in helm templating --- .gitea/workflows/lint-test-helm.yaml | 1 + .gitea/workflows/render-manifests.yaml | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/lint-test-helm.yaml b/.gitea/workflows/lint-test-helm.yaml index ee87fe119..1c4937a29 100644 --- a/.gitea/workflows/lint-test-helm.yaml +++ b/.gitea/workflows/lint-test-helm.yaml @@ -343,6 +343,7 @@ jobs: helm dependency build "${CHART_PATH}" --skip-refresh + set -o pipefail if ! helm template "${DIR}" "${CHART_PATH}" --include-crds --namespace default --api-versions "gateway.networking.k8s.io/v1/HTTPRoute,monitoring.coreos.com/v1,monitoring.coreos.com/v1/ServiceMonitor" | \ kubeconform \ ${SCHEMA_LOCATIONS} \ diff --git a/.gitea/workflows/render-manifests.yaml b/.gitea/workflows/render-manifests.yaml index 9c703005e..1f86fe5e9 100644 --- a/.gitea/workflows/render-manifests.yaml +++ b/.gitea/workflows/render-manifests.yaml @@ -250,6 +250,8 @@ jobs: echo ">> Rendering Manifests ..." + EXIT_CODE=0 + render_chart() { local DIR="$1" local CHART_PATH="${MAIN_DIR}/clusters/${CLUSTER}/helm/${DIR}" @@ -283,10 +285,17 @@ jobs: echo ">> Formating rendered template ..." local TEMPLATE - TEMPLATE=$(helm template "${CHART_NAME}" ./ --namespace "${NAMESPACE}" --include-crds --dry-run=server --api-versions "gateway.networking.k8s.io/v1/HTTPRoute,monitoring.coreos.com/v1,monitoring.coreos.com/v1/ServiceMonitor") + if ! TEMPLATE=$(helm template "${CHART_NAME}" ./ --namespace "${NAMESPACE}" --include-crds --dry-run=server --api-versions "gateway.networking.k8s.io/v1/HTTPRoute,monitoring.coreos.com/v1,monitoring.coreos.com/v1/ServiceMonitor"); then + echo "${DIR}" > "${MAIN_DIR}/.failed_chart_${DIR}" + return 1 + fi # Format and split rendered template - echo "${TEMPLATE}" | yq '... comments=""' | yq 'select(. != null)' | yq -s '"'"${OUTPUT_FOLDER}"'" + .kind + "-" + .metadata.name + ".yaml"' + set -o pipefail + if ! echo "${TEMPLATE}" | yq '... comments=""' | yq 'select(. != null)' | yq -s '"'"${OUTPUT_FOLDER}"'" + .kind + "-" + .metadata.name + ".yaml"'; then + echo "${DIR}" > "${MAIN_DIR}/.failed_chart_${DIR}" + return 1 + fi # Strip comments again to ensure formatting correctness for file in "$OUTPUT_FOLDER"/*; do @@ -316,9 +325,16 @@ jobs: done | xargs -P 5 -I {} bash -c 'OUT=$(render_chart "$@" 2>&1); printf "%s\n" "$OUT"' _ {} + if ls .failed_chart_* 1> /dev/null 2>&1; then + EXIT_CODE=1 + rm -f .failed_chart_* + fi + echo "" echo "----" + exit $EXIT_CODE + - name: Check for Changes id: check-changes if: steps.check-dir-changes.outputs.changes-detected == 'true'