Fix workflow YAML syntax, use jq instead of inline Python
build / build-and-push (push) Successful in 6s

This commit is contained in:
nick
2026-07-12 07:24:35 +08:00
parent aa9e82b4ba
commit 38153c77b2
+7 -10
View File
@@ -41,17 +41,14 @@ jobs:
# sha256: 開頭的 digest 記錄不主動處理,避免誤刪或刪掉
# 還在被引用的 manifest。
run: |
VERSIONS=$(curl -s -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
curl -s -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing" \
| python3 -c "
import json, sys, re
data = json.load(sys.stdin)
sha_versions = [v for v in data if re.fullmatch(r'[0-9a-f]{40}', v['version'])]
sha_versions.sort(key=lambda v: v['created_at'], reverse=True)
print('\n'.join(str(v['id']) for v in sha_versions[5:]))
")
for id in $VERSIONS; do
| jq -r '[.[] | select(.version | test("^[0-9a-f]{40}$"))] | sort_by(.created_at) | reverse | .[5:] | .[].id' \
> /tmp/prune-ids.txt
while read -r id; do
[ -z "$id" ] && continue
echo "Deleting package version id=$id"
curl -s -X DELETE -H "Authorization: token ${{ secrets.CI_REGISTRY_TOKEN }}" \
"https://gitea.niq-dev.com/api/v1/packages/gitea_admin/container/landing/$id"
done
done < /tmp/prune-ids.txt