From f1dc60aae5a27414fbdf91a8fc49f65d7307f5fc Mon Sep 17 00:00:00 2001 From: TapTap Date: Sat, 14 Nov 2026 21:59:51 +0000 Subject: [PATCH] chart: show the newest chart in the Charts repository README The chart repository README was static, so the published version was only visible in index.yaml. push-chart.sh now regenerates a marked "Newest chart" section with the version, app version, publish time and source commit, plus a table of the newest version of every chart in the repository. Plain markdown only, so the README stays readable on the Gitea front page. The section is inserted before the first section on the first publish and replaced in place afterwards. --- README.md | 4 ++ scripts/push-chart.sh | 85 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/README.md b/README.md index 168cec2..365d4b7 100644 --- a/README.md +++ b/README.md @@ -259,6 +259,10 @@ Image: gitea.tap-tap.win/taptap/audiomanager: Chart: https://gitea.tap-tap.win/TapTap/Charts/raw/branch/main ``` +The [Charts README](https://gitea.tap-tap.win/TapTap/Charts) always shows the +newest published chart version; `scripts/push-chart.sh` regenerates that section +on every publish. + Kustomize example: diff --git a/scripts/push-chart.sh b/scripts/push-chart.sh index 4828fef..d669c31 100755 --- a/scripts/push-chart.sh +++ b/scripts/push-chart.sh @@ -99,6 +99,91 @@ fi helm package "$CHART_DIR" --version "$VERSION" --destination "$workdir/repo" helm repo index "$workdir/repo" --url "$CHARTS_RAW_URL" +# Keep the repository README pointing at the newest version of every chart so +# the published version is visible without reading index.yaml. +app_version="$(awk '/^appVersion:/ { print $2; exit }' "$CHART_DIR/Chart.yaml" | tr -d '"')" +source_sha="${GITHUB_SHA:-$(git -C "$ROOT" rev-parse HEAD)}" +source_repo="${GITHUB_REPOSITORY:-TapTap/AudioManager}" +source_server="${GITHUB_SERVER_URL:-https://gitea.tap-tap.win}" +published_at="$(date -u '+%Y-%m-%d %H:%M UTC')" + +newest_charts="$( + for archive in "$workdir/repo"/*.tgz; do + [[ -f "$archive" ]] || continue + helm show chart "$archive" 2>/dev/null \ + | awk ' + /^name:/ { name = $2 } + /^version:/ { version = $2 } + /^appVersion:/ { app = $2; gsub(/"/, "", app) } + END { if (name != "") printf "%s|%s|%s\n", name, version, app } + ' + done | sort -t '|' -k1,1 -k2,2V \ + | awk -F '|' ' + { if ($1 == last) { row = $0 } else { if (last != "") print row; last = $1; row = $0 } } + END { if (last != "") print row } + ' +)" + +section="$workdir/newest-chart.md" +{ + echo '' + echo '## Newest chart' + echo + echo "\`$chart_name\` **$VERSION** (app \`$app_version\`), published $published_at" + echo "from commit [\`${source_sha:0:7}\`]($source_server/$source_repo/commit/$source_sha)." + echo + echo '| Chart | Newest version | App version |' + echo '| --- | --- | --- |' + while IFS='|' read -r name version app; do + [[ -n "$name" ]] || continue + echo "| \`$name\` | \`$version\` | ${app:--} |" + done <<< "$newest_charts" + echo '' +} > "$section" + +readme="$workdir/repo/README.md" +updated_readme="$workdir/repo/README.md.new" +if [[ -f "$readme" ]] && grep -q '' "$readme"; then + awk -v section="$section" ' + // { + while ((getline line < section) > 0) print line + skipping = 1 + next + } + // { skipping = 0; next } + !skipping { print } + ' "$readme" > "$updated_readme" +else + # No generated section yet: put it before the first "## " heading. + { + if [[ -f "$readme" ]]; then + awk -v section="$section" ' + !inserted && /^## / { + while ((getline line < section) > 0) print line + print "" + inserted = 1 + } + { print } + END { + if (!inserted) { + print "" + while ((getline line < section) > 0) print line + } + } + ' "$readme" + else + { + echo '# Charts' + echo + echo 'Published Helm chart repository for TapTap projects.' + echo + } + cat "$section" + fi + } > "$updated_readme" +fi +mv "$updated_readme" "$readme" + git -C "$workdir/repo" add . if git -C "$workdir/repo" diff --cached --quiet; then echo "Chart $(basename "$CHART_DIR") $VERSION is already published."