CI: the GitHub mirror keeps the last 30 releases (Gitea 5) as an archive

Changelog: -
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-12-04 12:30:22 +01:00
1 parent 20477d299a
commit 73d14e60a1
2 files changed
+17 -13

No files matched your search

+15 -11
View File
@@ -5,10 +5,13 @@
# the release notes' links point there, and integrity rests on the signed
# SHA256SUMS, not on the host.
#
# Converges instead of copying "the one new release": every run makes the
# GitHub side equal to the newest $KEEP releases of Gitea -- creates what is
# missing, uploads assets a failed run left out, deletes GitHub releases that
# Gitea pruned (their tags stay). A GitHub outage is mended by the next run.
# Converges instead of copying "the one new release": every run brings the
# newest $KEEP releases of Gitea over -- creates what is missing, uploads
# assets a failed run left out -- so a GitHub outage is mended by the next
# run. GitHub is the ARCHIVE: Gitea keeps $KEEP, GitHub the newest $GH_KEEP
# (older ones are deleted, their tags stay), so an older build stays
# downloadable for a rollback over USB/BLE. Their notes' links to Gitea
# release pages die with Gitea's pruning; the mirror header links the list.
#
# A release is created only once GitHub has its commit (the export pushes it
# as branch `tth` in tth-upstream-sync.yml); until then it is skipped with a
@@ -19,7 +22,7 @@
#
# env: GH_TOKEN (fine-grained, Contents: write on GH_REPO), GITEA (default
# https://git.rfa.cz), SRC_REPO (tth-pub/meshcore-tth), GH_REPO
# (TeTeHacko/MeshCore-TTH), KEEP (5).
# (TeTeHacko/MeshCore-TTH), KEEP (5, as pub-release.yml), GH_KEEP (30).
set -euo pipefail
case "${1:-}" in
@@ -39,6 +42,7 @@ GITEA=${GITEA:-https://git.rfa.cz}
SRC_REPO=${SRC_REPO:-tth-pub/meshcore-tth}
GH_REPO=${GH_REPO:-TeTeHacko/MeshCore-TTH}
KEEP=${KEEP:-5}
GH_KEEP=${GH_KEEP:-30}
src="$GITEA/api/v1/repos/$SRC_REPO"
gh="https://api.github.com/repos/$GH_REPO"
up="https://uploads.github.com/repos/$GH_REPO"
@@ -78,8 +82,8 @@ while read -r rel; do
echo "create $tag ($sha)"
[ "$DRY" = 1 ] && continue
body=$(
echo "> **Zrcadlo** · mirror of $GITEA/$SRC_REPO/releases/tag/$(enc "$tag") -- primární zdroj"
echo "> (auto-OTA, podpisy \`SHA256SUMS\`) je git.rfa.cz."
echo "> **Zrcadlo** · mirror of $GITEA/$SRC_REPO/releases -- primární zdroj (auto-OTA,"
echo "> podpisy \`SHA256SUMS\`) je git.rfa.cz; tam drží posledních $KEEP vydání, tady $GH_KEEP."
echo
jq -r .body <<<"$rel"
)
@@ -103,11 +107,11 @@ while read -r rel; do
[ "$n" = 0 ] || echo "$tag: $n asset(s) $([ "$DRY" = 1 ] && echo "to upload" || echo uploaded)"
done <"$tmp/src.jsonl"
# Gitea pruned it: the GitHub copy goes too (the tag stays, like the export's)
jq -r '.tag_name' "$tmp/src.jsonl" >"$tmp/keep"
jq -r 'select(.tag_name | startswith("tth-") or test("[+]tth[.]")) | "\(.id) \(.tag_name)"' "$tmp/gh.jsonl" |
# the archive keeps the newest $GH_KEEP (the tags stay, like the export's)
[ "$DRY" = 1 ] || ghapi -f "$gh/releases?per_page=100" | jq -c '.[]' >"$tmp/gh.jsonl"
jq -sr --argjson k "$GH_KEEP" 'map(select(.tag_name | startswith("tth-") or test("[+]tth[.]")))
| sort_by(.created_at) | reverse | .[$k:][] | "\(.id) \(.tag_name)"' "$tmp/gh.jsonl" |
while read -r id tag; do
grep -qxF "$tag" "$tmp/keep" && continue
echo "prune $tag"
[ "$DRY" = 1 ] || ghapi -f -X DELETE "$gh/releases/$id" >/dev/null
done