aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tasks/chart')
-rwxr-xr-xtasks/chart111+111 −0
1 files changed, 111 insertions, 0 deletions
diff --git a/tasks/chart b/tasks/chart
new file mode 100755
--- /dev/null
+++ b/tasks/chart
@@ -0,0 +1,111 @@
+#!/bin/sh -eu
+# SPDX-FileCopyrightText: 2026 Nikolay Govorov
+# SPDX-License-Identifier: 0BSD
+#MISE description="Lint, package, and optionally publish a Helm chart"
+#MISE tools={"helm"="4.1.1"}
+
+usage() {
+ cat <<'EOF'
+Usage: mise run chart -- --chart DIR [options]
+
+Options:
+ --version VERSION Immutable chart version (required for packaging)
+ --app-version VERSION Application version written to Chart.yaml
+ --output DIR Package directory (default: dist/charts)
+ --push OCI_URL Push package to an OCI registry; repeatable
+ --lint-only Strictly lint without packaging
+EOF
+}
+
+chart=
+version=
+app_version=
+output=dist/charts
+push_urls=
+lint_only=false
+
+while [ "$#" -gt 0 ]; do
+ case "$1" in
+ --chart)
+ [ "$#" -ge 2 ] || { echo "chart: --chart requires a value" >&2; exit 2; }
+ chart=$2
+ shift 2
+ ;;
+ --version)
+ [ "$#" -ge 2 ] || { echo "chart: --version requires a value" >&2; exit 2; }
+ version=$2
+ shift 2
+ ;;
+ --app-version)
+ [ "$#" -ge 2 ] || { echo "chart: --app-version requires a value" >&2; exit 2; }
+ app_version=$2
+ shift 2
+ ;;
+ --output)
+ [ "$#" -ge 2 ] || { echo "chart: --output requires a value" >&2; exit 2; }
+ output=$2
+ shift 2
+ ;;
+ --push)
+ [ "$#" -ge 2 ] || { echo "chart: --push requires a value" >&2; exit 2; }
+ case $2 in
+ oci://*) ;;
+ *) echo "chart: registry must use oci://: $2" >&2; exit 2 ;;
+ esac
+ push_urls="${push_urls}${push_urls:+
+}$2"
+ shift 2
+ ;;
+ --lint-only)
+ lint_only=true
+ shift
+ ;;
+ -h|--help)
+ usage
+ exit 0
+ ;;
+ *)
+ echo "chart: unknown argument: $1" >&2
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+
+command -v helm >/dev/null 2>&1 || { echo "chart: helm is not installed" >&2; exit 1; }
+[ -n "$chart" ] || { echo "chart: --chart is required" >&2; exit 2; }
+[ -d "$chart" ] || { echo "chart: directory not found: $chart" >&2; exit 1; }
+[ -f "$chart/Chart.yaml" ] || { echo "chart: Chart.yaml not found in $chart" >&2; exit 1; }
+
+name=$(sed -n 's/^name:[[:space:]]*\([A-Za-z0-9_.-][A-Za-z0-9_.-]*\)[[:space:]]*$/\1/p' "$chart/Chart.yaml" | head -n 1)
+[ -n "$name" ] || { echo "chart: cannot read chart name from $chart/Chart.yaml" >&2; exit 1; }
+
+helm lint "$chart" --strict
+
+if [ "$lint_only" = true ]; then
+ if [ -n "$version" ] || [ -n "$app_version" ] || [ -n "$push_urls" ]; then
+ echo "chart: --lint-only cannot package or push a chart" >&2
+ exit 2
+ fi
+ exit 0
+fi
+
+[ -n "$version" ] || { echo "chart: --version is required unless --lint-only is used" >&2; exit 2; }
+mkdir -p "$output"
+
+set -- helm package "$chart" --destination "$output" --version "$version"
+if [ -n "$app_version" ]; then
+ set -- "$@" --app-version "$app_version"
+fi
+"$@"
+
+package=$output/$name-$version.tgz
+[ -f "$package" ] || { echo "chart: Helm did not create expected package: $package" >&2; exit 1; }
+
+old_ifs=$IFS
+IFS='
+'
+for registry in $push_urls; do
+ helm push "$package" "${registry%/}"
+done
+IFS=$old_ifs