ci: publish charts to TapTap/Charts
Replace the OCI chart push with a classic Helm repository in the public TapTap/Charts repository. CI packages the chart, regenerates index.yaml and pushes both to main, so `helm repo add` and Kustomize helmCharts work. The publisher authenticates with the AUDIOMANAGER_CHARTS_TOKEN secret and supports an explicit VERSION for local releases.
This commit is contained in:
1 parent
df3ed281f8
commit
0ac226b011
3 files changed
+109
-46
No files matched your search
+63
-20
@@ -1,9 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Package the Helm chart and push it to the OCI registry.
|
||||
# Package the Helm chart and publish it to the classic Helm chart repository
|
||||
# in TapTap/Charts.
|
||||
#
|
||||
# Run `helm registry login <registry>` first (CI does this with the package
|
||||
# token). The version is:
|
||||
# The repository keeps index.yaml and the packaged .tgz files on its main
|
||||
# branch, so it works with `helm repo add` and Kustomize's helmCharts
|
||||
# generator. The version is:
|
||||
# - VERSION if set,
|
||||
# - the pushed tag for a v* tag build,
|
||||
# - <chart version>-sha.<commit> for a main branch build,
|
||||
@@ -12,30 +14,35 @@ set -euo pipefail
|
||||
|
||||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
|
||||
REGISTRY="${REGISTRY:-gitea.tap-tap.win}"
|
||||
CHART_REPO="${CHART_REPO:-taptap/charts}"
|
||||
CHARTS_REPO_URL="${CHARTS_REPO_URL:-https://gitea.tap-tap.win/TapTap/Charts.git}"
|
||||
CHARTS_BRANCH="${CHARTS_BRANCH:-main}"
|
||||
CHARTS_USERNAME="${CHARTS_USERNAME:-TapTap}"
|
||||
CHARTS_TOKEN="${CHARTS_TOKEN:-}"
|
||||
CHARTS_RAW_URL="${CHARTS_RAW_URL:-https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main}"
|
||||
CHART_DIR="${CHART_DIR:-$ROOT/charts/audiomanager}"
|
||||
OUTPUT_DIR="${OUTPUT_DIR:-$ROOT/dist}"
|
||||
VERSION="${VERSION:-}"
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: scripts/push-chart.sh [options]
|
||||
|
||||
Push the chart to oci://<registry>/<chart-repo>/audiomanager.
|
||||
Package the chart and publish it to the classic Helm repository in
|
||||
TapTap/Charts.
|
||||
|
||||
Options:
|
||||
-h, --help Show this help
|
||||
|
||||
Environment:
|
||||
REGISTRY OCI registry (default: gitea.tap-tap.win)
|
||||
CHART_REPO Repository path below the registry (default: taptap/charts)
|
||||
CHART_DIR Chart directory (default: charts/audiomanager)
|
||||
OUTPUT_DIR Directory for the packaged chart (default: dist)
|
||||
VERSION Chart version to package (overrides auto-detection)
|
||||
|
||||
Run `helm registry login <registry>` before this script if the registry is
|
||||
private.
|
||||
CHARTS_REPO_URL Git URL of the chart repository
|
||||
(default: https://gitea.tap-tap.win/TapTap/Charts.git)
|
||||
CHARTS_BRANCH Published branch (default: main)
|
||||
CHARTS_USERNAME Git username for the chart repository (default: TapTap)
|
||||
CHARTS_TOKEN Token with write access to the chart repository. When empty,
|
||||
normal git credentials are used.
|
||||
CHARTS_RAW_URL Public URL written into index.yaml
|
||||
(default: https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main)
|
||||
CHART_DIR Chart directory (default: charts/audiomanager)
|
||||
VERSION Chart version to package (overrides auto-detection)
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -62,10 +69,46 @@ if [[ -z "$VERSION" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
package="$OUTPUT_DIR/$(basename "$CHART_DIR")-${VERSION}.tgz"
|
||||
workdir="$(mktemp -d "${TMPDIR:-/tmp}/charts-publish.XXXXXX")"
|
||||
trap 'rm -rf "$workdir"' EXIT
|
||||
|
||||
helm package "$CHART_DIR" --version "$VERSION" --destination "$OUTPUT_DIR"
|
||||
helm push "$package" "oci://${REGISTRY}/${CHART_REPO}"
|
||||
if [[ -n "$CHARTS_TOKEN" ]]; then
|
||||
askpass="$workdir/askpass.sh"
|
||||
cat > "$askpass" <<'SH'
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
*Username*) printf '%s\n' "${CHARTS_USERNAME:?}" ;;
|
||||
*Password*) printf '%s\n' "${CHARTS_TOKEN:?}" ;;
|
||||
esac
|
||||
SH
|
||||
chmod 700 "$askpass"
|
||||
export CHARTS_USERNAME CHARTS_TOKEN
|
||||
export GIT_ASKPASS="$askpass"
|
||||
export GIT_TERMINAL_PROMPT=0
|
||||
fi
|
||||
|
||||
echo "Pushed chart to oci://${REGISTRY}/${CHART_REPO}/$(basename "$CHART_DIR") --version ${VERSION}"
|
||||
git clone --quiet --depth=1 --branch "$CHARTS_BRANCH" \
|
||||
"$CHARTS_REPO_URL" "$workdir/repo"
|
||||
|
||||
chart_name="$(awk '/^name:/ { print $2; exit }' "$CHART_DIR/Chart.yaml")"
|
||||
if [[ -f "$workdir/repo/${chart_name}-${VERSION}.tgz" ]]; then
|
||||
echo "Chart $chart_name $VERSION is already published."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
helm package "$CHART_DIR" --version "$VERSION" --destination "$workdir/repo"
|
||||
helm repo index "$workdir/repo" --url "$CHARTS_RAW_URL"
|
||||
|
||||
git -C "$workdir/repo" add .
|
||||
if git -C "$workdir/repo" diff --cached --quiet; then
|
||||
echo "Chart $(basename "$CHART_DIR") $VERSION is already published."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git -C "$workdir/repo" \
|
||||
-c user.name="${GIT_AUTHOR_NAME:-Chart Publisher}" \
|
||||
-c user.email="${GIT_AUTHOR_EMAIL:-charts@tap-tap.win}" \
|
||||
commit -q -m "chart: publish $(basename "$CHART_DIR") $VERSION"
|
||||
git -C "$workdir/repo" push -q origin "$CHARTS_BRANCH"
|
||||
|
||||
echo "Published $(basename "$CHART_DIR") $VERSION to $CHARTS_RAW_URL"
|
||||
Reference in new issue
Block a user