ci: package and push the Helm chart to the OCI registry
Add a chart-push job that runs after the chart lint on every push and publishes the packaged chart to oci://gitea.tap-tap.win/taptap/charts. Main builds use <chart version>-sha.<commit> so parallel commits do not overwrite each other; v* tags use the tag version. The shared scripts/push-chart.sh also supports explicit VERSION and local use.
This commit is contained in:
1 parent
441fa056ba
commit
76bccaefea
4 files changed
+139
-2
No files matched your search
Executable
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Package the Helm chart and push it to the OCI registry.
|
||||
#
|
||||
# Run `helm registry login <registry>` first (CI does this with the package
|
||||
# token). 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)"
|
||||
|
||||
REGISTRY="${REGISTRY:-gitea.tap-tap.win}"
|
||||
CHART_REPO="${CHART_REPO:-taptap/charts}"
|
||||
CHART_DIR="${CHART_DIR:-$ROOT/charts/musicmanager}"
|
||||
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>/musicmanager.
|
||||
|
||||
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/musicmanager)
|
||||
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.
|
||||
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
|
||||
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
package="$OUTPUT_DIR/$(basename "$CHART_DIR")-${VERSION}.tgz"
|
||||
|
||||
helm package "$CHART_DIR" --version "$VERSION" --destination "$OUTPUT_DIR"
|
||||
helm push "$package" "oci://${REGISTRY}/${CHART_REPO}"
|
||||
|
||||
echo "Pushed chart to oci://${REGISTRY}/${CHART_REPO}/$(basename "$CHART_DIR") --version ${VERSION}"
|
||||
Reference in new issue
Block a user