From 4946d731839d00e855516f96d6f07d15836767c5 Mon Sep 17 00:00:00 2001 From: ezequielnick <107352853+ezequielnick@users.noreply.github.com> Date: Sun, 31 Aug 2025 12:33:41 +0800 Subject: [PATCH] chore: update workflow to delete old assets --- .github/workflows/build.yml | 41 +++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 733da2e..563099c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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