mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 21:20:29 +08:00
chore: update workflow to delete old assets
This commit is contained in:
parent
e1c4a94e02
commit
4946d73183
41
.github/workflows/build.yml
vendored
41
.github/workflows/build.yml
vendored
@ -28,17 +28,40 @@ jobs:
|
|||||||
if [ ! -z "$RELEASE_ID" ] && [ "$RELEASE_ID" != "empty" ]; then
|
if [ ! -z "$RELEASE_ID" ] && [ "$RELEASE_ID" != "empty" ]; then
|
||||||
echo "✅ Found dev release with ID: $RELEASE_ID"
|
echo "✅ Found dev release with ID: $RELEASE_ID"
|
||||||
|
|
||||||
# Get all assets
|
echo "📋 Getting list of assets with pagination..."
|
||||||
echo "📋 Getting list of assets..."
|
ALL_ASSETS="[]"
|
||||||
ASSETS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
PAGE=1
|
||||||
"https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID/assets")
|
PER_PAGE=100
|
||||||
|
|
||||||
ASSET_COUNT=$(echo "$ASSETS" | jq '. | length')
|
while true; do
|
||||||
echo "📦 Found $ASSET_COUNT assets to delete"
|
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")
|
||||||
|
|
||||||
if [ "$ASSET_COUNT" -gt 0 ]; then
|
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
|
||||||
|
|
||||||
|
TOTAL_ASSET_COUNT=$(echo "$ALL_ASSETS" | jq '. | length')
|
||||||
|
echo "📦 Total assets found across all pages: $TOTAL_ASSET_COUNT"
|
||||||
|
|
||||||
|
if [ "$TOTAL_ASSET_COUNT" -gt 0 ]; then
|
||||||
# Delete each asset with detailed logging
|
# 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
|
if [ ! -z "$asset_id" ]; then
|
||||||
echo "🗑️ Deleting asset ID: $asset_id"
|
echo "🗑️ Deleting asset ID: $asset_id"
|
||||||
RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X DELETE \
|
RESPONSE=$(curl -s -w "HTTPSTATUS:%{http_code}" -X DELETE \
|
||||||
@ -56,7 +79,7 @@ jobs:
|
|||||||
sleep 0.5
|
sleep 0.5
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "🎉 Finished deleting assets"
|
echo "🎉 Finished deleting all $TOTAL_ASSET_COUNT assets"
|
||||||
else
|
else
|
||||||
echo "ℹ️ No assets found to delete"
|
echo "ℹ️ No assets found to delete"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user