From b41e0f49bfe0335d06e60f7dc5ad0c225847868b Mon Sep 17 00:00:00 2001 From: 3uzbcqje <3uzbcqje@addy.to> Date: Mon, 16 Feb 2026 19:08:36 -0800 Subject: [PATCH] Adding workflow and script to build helm chart. --- .woodpecker/helm.yaml | 36 ++++++++++++++++++++++++++++++++++++ pipeline.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 .woodpecker/helm.yaml create mode 100755 pipeline.sh diff --git a/.woodpecker/helm.yaml b/.woodpecker/helm.yaml new file mode 100644 index 00000000..44021f98 --- /dev/null +++ b/.woodpecker/helm.yaml @@ -0,0 +1,36 @@ +steps: + helm: + when: + - event: pull_request + branch: main + - event: push + branch: main + image: alpine/helm:4.1.1 + environment: + helm_registry: codeberg.org + helm_username: ${CI_REPO_OWNER} + + # To create helm_password: + # 1. Go to https://codeberg.org/user/settings/applications. + # 2. Create a token with these settings: + # - Token name: https://git.deuxfleurs.fr/3uzbcqje/garage/src/branch/main-v2/.woodpecker/helm.yaml + # - Set package permission to "Read and write". + # 3. Click "Generate token". + # 4. Copy the token. + # 5. Log into https://ci.codeberg.org. + # 6. Find your repo, and add a secret with these settings: + # - Name: helm_password + # - Value: + # 7. Click "Add secret". + + helm_password: + from_secret: helm_password + + git_repo_owner: ${CI_REPO_OWNER} + commands: + - | + if [[ "${CI_PIPELINE_EVENT}" == "push" && "${CI_COMMIT_BRANCH}" == "main" ]]; then + ./pipeline.sh push + else + ./pipeline.sh + fi diff --git a/pipeline.sh b/pipeline.sh new file mode 100755 index 00000000..a79551fd --- /dev/null +++ b/pipeline.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash + +# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ +# Not using "-x" because we aren't debugging. +set -Eeuo pipefail + +# We get unbound var err if we don't set arg +arg="${1:-}" + +echo "$helm_password" | helm registry login -u "$helm_username" --password-stdin "$helm_registry" + +helm lint "script/helm/garage" + +for chart in "script/helm/garage"; do + chart_name=$(echo "$chart" | cut -d/ -f2) + chart_version=$(grep '^version: ' "${chart}/Chart.yaml" | cut -d' ' -f 2) + + helm package "${chart}" + + # If chart already exists in the chart repository, don't push. + if helm pull "oci://${helm_registry}/${git_repo_owner}/charts/${chart_name}" --version "${chart_version}" &> /dev/null; then + echo -e "\e[31mWARNING: Chart ${chart_name} version ${chart_version} already exists in the repository.\nThis means that the chart's code has not changed, or you forgot to update the version in Chart.yaml.\e[0m" + else + if [[ $arg == 'push' ]]; then + helm push "${chart_name}-${chart_version}.tgz" "oci://${helm_registry}/${git_repo_owner}/charts" + fi + fi +done