Files
AudioManager/scripts/push-chart.sh
T
TapTap 0ac226b011
CI / chart (push) Successful in 2s
CI / chart-push (push) Successful in 2s
CI / test (push) Successful in 1m38s
CI / image (push) Successful in 3m4s
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.
2026-11-14 10:03:44 +00:00

115 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Package the Helm chart and publish it to the classic Helm chart repository
# in TapTap/Charts.
#
# 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,
# - the chart version for a local build outside CI.
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
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}"
VERSION="${VERSION:-}"
usage() {
cat <<'EOF'
Usage: scripts/push-chart.sh [options]
Package the chart and publish it to the classic Helm repository in
TapTap/Charts.
Options:
-h, --help Show this help
Environment:
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
}
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
usage
exit 0
fi
chart_version="$(awk '/^version:/ { print $2; exit }' "$CHART_DIR/Chart.yaml")"
if [[ -z "$chart_version" ]]; then
echo "Could not read the chart version from $CHART_DIR/Chart.yaml" >&2
exit 1
fi
if [[ -z "$VERSION" ]]; then
if [[ "${GITHUB_REF:-}" == refs/tags/* ]]; then
VERSION="${GITHUB_REF_NAME#v}"
elif [[ -n "${GITHUB_SHA:-}" ]]; then
VERSION="${chart_version}-sha.${GITHUB_SHA::7}"
elif git -C "$ROOT" rev-parse --git-dir >/dev/null 2>&1; then
VERSION="${chart_version}-sha.$(git -C "$ROOT" rev-parse --short=7 HEAD)"
else
VERSION="$chart_version"
fi
fi
workdir="$(mktemp -d "${TMPDIR:-/tmp}/charts-publish.XXXXXX")"
trap 'rm -rf "$workdir"' EXIT
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
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"