chore: update workflow to delete old assets

This commit is contained in:
ezequielnick 2025-08-31 12:33:41 +08:00
parent e1c4a94e02
commit 4946d73183

View File

@ -27,18 +27,41 @@ jobs:
if [ ! -z "$RELEASE_ID" ] && [ "$RELEASE_ID" != "empty" ]; then
echo "✅ Found dev release with ID: $RELEASE_ID"
echo "📋 Getting list of assets with pagination..."
ALL_ASSETS="[]"
PAGE=1
PER_PAGE=100
# Get all assets
echo "📋 Getting list of assets..."
ASSETS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets")
while true; do
echo "📄 Fetching page $PAGE..."
ASSETS_PAGE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?page=$PAGE&per_page=$PER_PAGE")
PAGE_COUNT=$(echo "$ASSETS_PAGE" | jq '. | length')
echo "📦 Found $PAGE_COUNT assets on page $PAGE"
if [ "$PAGE_COUNT" -eq 0 ]; then
echo "📋 No more assets found, stopping pagination"
break
fi
ALL_ASSETS=$(echo "$ALL_ASSETS" "$ASSETS_PAGE" | jq -s '.[0] + .[1]')
if [ "$PAGE_COUNT" -lt "$PER_PAGE" ]; then
echo "📋 Last page reached (got $PAGE_COUNT < $PER_PAGE), stopping pagination"
break
fi
PAGE=$((PAGE + 1))
done
ASSET_COUNT=$(echo "$ASSETS" | jq '. | length')
echo "📦 Found $ASSET_COUNT assets to delete"
TOTAL_ASSET_COUNT=$(echo "$ALL_ASSETS" | jq '. | length')
echo "📦 Total assets found across all pages: $TOTAL_ASSET_COUNT"
if [ "$ASSET_COUNT" -gt 0 ]; then
if [ "$TOTAL_ASSET_COUNT" -gt 0 ]; then
# Delete each asset with detailed logging
echo "$ASSETS" | jq -r '.[].id' | while read asset_id; do
echo "$ALL_ASSETS" | jq -r '.[].id' | while read asset_id; do
if [ ! -z "$asset_id" ]; then
echo "🗑️ Deleting asset ID: $asset_id"
RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X DELETE \
@ -56,7 +79,7 @@ jobs:
sleep 0.5
fi
done
echo "🎉 Finished deleting assets"
echo "🎉 Finished deleting all $TOTAL_ASSET_COUNT assets"
else
echo " No assets found to delete"
fi