Schedule moves to Mondays 04:00 UTC. release.sh now deletes older releases for the same image/distro (and their assets and tags) after publishing, so only the newest is kept. Add prune-releases.sh for a one-off cleanup.
51 lines
1.7 KiB
Bash
Executable File
51 lines
1.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Delete older Gitea releases (including their assets and git tags) for an
|
|
# image, keeping only the newest release per distro.
|
|
#
|
|
# Usage: RELEASE_TOKEN=<token-with-write:repository> ./prune-releases.sh [image]
|
|
#
|
|
# The token defaults to $RELEASE_TOKEN; GITEA_URL/GITEA_REPO match the workflow.
|
|
set -euo pipefail
|
|
|
|
IMAGE="${1:-fedora-cosmic}"
|
|
GITEA_URL="${GITEA_URL:-https://git.plabble.org}"
|
|
GITEA_REPO="${GITEA_REPO:-Misthios/bootc-images}"
|
|
TOKEN="${RELEASE_TOKEN:-${GITHUB_TOKEN:-}}"
|
|
|
|
[[ -n "${TOKEN}" ]] || { echo "RELEASE_TOKEN (write:repository) is required" >&2; exit 1; }
|
|
API="${GITEA_URL%/}/api/v1/repos/${GITEA_REPO}"
|
|
|
|
# Collect matching releases (API returns newest first).
|
|
all=""
|
|
page=1
|
|
while :; do
|
|
page_json="$(curl -fsSL -H "Authorization: token ${TOKEN}" \
|
|
"${API}/releases?limit=50&page=${page}")"
|
|
[[ "$(jq 'length' <<< "${page_json}")" -eq 0 ]] && break
|
|
all+="$(jq -r --arg p "${IMAGE}-" \
|
|
'.[] | select(.tag_name | startswith($p)) | "\(.tag_name)\t\(.id)"' \
|
|
<<< "${page_json}")"$'\n'
|
|
page=$((page + 1))
|
|
[[ "${page}" -gt 40 ]] && break
|
|
done
|
|
|
|
# Tag shape: "<image>-<distro>.<date>.<run>" -> prefix "<image>-<distro>".
|
|
# Keep the first (newest) release seen per prefix, delete the rest.
|
|
seen=""
|
|
while IFS=$'\t' read -r tag id; do
|
|
[[ -z "${tag}" ]] && continue
|
|
prefix="${tag%.*.*}"
|
|
if grep -qxF "${prefix}" <<< "${seen}"; then
|
|
echo "removing ${tag}"
|
|
curl -fsSL -X DELETE -H "Authorization: token ${TOKEN}" \
|
|
"${API}/releases/${id}" >/dev/null || true
|
|
curl -fsSL -X DELETE -H "Authorization: token ${TOKEN}" \
|
|
"${API}/tags/${tag}" >/dev/null || true
|
|
else
|
|
seen+="${prefix}"$'\n'
|
|
echo "keeping ${tag}"
|
|
fi
|
|
done <<< "${all}"
|
|
|
|
echo "Pruned ${IMAGE} releases (kept newest per distro)."
|