Watch
1
0
Fork
You've already forked souveraine
0

publisher: refresh release assets before mutation

This commit is contained in:
Fimeg 2026-08-24 14:37:56 -04:00
commit 579cc53bd2

View file

@ -115,29 +115,39 @@ else
log "publishing into existing $EDGE_TAG release $REL_ID" log "publishing into existing $EDGE_TAG release $REL_ID"
fi fi
ASSETS_JSON=$(api "$API/repos/$ARCHIVE_REPO/releases/$REL_ID/assets") # Query live state every time. The same arch=any package is visited once per
# architecture, so a snapshot taken before the loop becomes false as soon as
asset_id() { # the first architecture deletes or uploads it. Return every matching id as a
printf '%s' "$ASSETS_JSON" | python3 -c " # repair for duplicate same-name assets left by older runs.
asset_ids() {
api "$API/repos/$ARCHIVE_REPO/releases/$REL_ID/assets" | python3 -c "
import json,sys import json,sys
name = sys.argv[1] name = sys.argv[1]
for a in json.load(sys.stdin): for a in json.load(sys.stdin):
if a['name'] == name: if a['name'] == name:
print(a['id']); break print(a['id'])
" "$1" " "$1"
} }
asset_exists() {
[ -n "$(asset_ids "$1")" ]
}
delete_asset() { delete_asset() {
local name="$1" id local name="$1" ids id
id=$(asset_id "$name") ids=$(asset_ids "$name")
[ -n "$id" ] || return 0 [ -n "$ids" ] || return 0
curl -sf -X DELETE -H "$AUTH" \ while IFS= read -r id; do
"$API/repos/$ARCHIVE_REPO/releases/$REL_ID/assets/$id" -o /dev/null [ -n "$id" ] || continue
curl -sf -X DELETE -H "$AUTH" \
"$API/repos/$ARCHIVE_REPO/releases/$REL_ID/assets/$id" -o /dev/null
done <<< "$ids"
log "deleted stale asset $name" log "deleted stale asset $name"
} }
# Gitea happily stores two assets with the same name, which would leave pacman # Gitea happily stores two assets with the same name, which would leave pacman
# fetching whichever the API returned first. Always delete before uploading. # fetching whichever the API returned first. Delete every live match before
# uploading.
upload_asset() { upload_asset() {
local path="$1" name local path="$1" name
name="$(basename "$path")" name="$(basename "$path")"
@ -230,7 +240,7 @@ for ARCH_DIR in "$REPO_DIR"/*/; do
# truncated body, an HTML error page — falling through to a fresh database # truncated body, an HTML error page — falling through to a fresh database
# would erase every other producer on upload. That is precisely the clobber # would erase every other producer on upload. That is precisely the clobber
# this script exists to remove, so it is a hard failure instead. # this script exists to remove, so it is a hard failure instead.
if [ -n "$(asset_id "$DB.db.tar.zst")" ]; then if asset_exists "$DB.db.tar.zst"; then
download_asset "$DB.db.tar.zst" "$WORK/$DB.db.tar.zst" \ download_asset "$DB.db.tar.zst" "$WORK/$DB.db.tar.zst" \
|| { echo "FATAL: $DB.db.tar.zst is published but could not be fetched;" \ || { echo "FATAL: $DB.db.tar.zst is published but could not be fetched;" \
"refusing to publish a database that would drop other producers" >&2 "refusing to publish a database that would drop other producers" >&2
@ -249,7 +259,7 @@ for ARCH_DIR in "$REPO_DIR"/*/; do
# there — without this fetch it would be rebuilt from just our packages and # there — without this fetch it would be rebuilt from just our packages and
# every other producer would vanish from `pacman -F` while still installing # every other producer would vanish from `pacman -F` while still installing
# fine, which is the kind of half-broken that goes unnoticed for months. # fine, which is the kind of half-broken that goes unnoticed for months.
if [ -n "$(asset_id "$DB.files.tar.zst")" ]; then if asset_exists "$DB.files.tar.zst"; then
download_asset "$DB.files.tar.zst" "$WORK/$DB.files.tar.zst" \ download_asset "$DB.files.tar.zst" "$WORK/$DB.files.tar.zst" \
|| { echo "FATAL: $DB.files.tar.zst is published but could not be fetched" >&2; exit 1; } || { echo "FATAL: $DB.files.tar.zst is published but could not be fetched" >&2; exit 1; }
bsdtar -tf "$WORK/$DB.files.tar.zst" >/dev/null 2>&1 \ bsdtar -tf "$WORK/$DB.files.tar.zst" >/dev/null 2>&1 \