Skip to content

Commit 93c68cb

Browse files
committed
Summary for cleaning cache
1 parent 5858773 commit 93c68cb

File tree

1 file changed

+44
-10
lines changed

1 file changed

+44
-10
lines changed

.github/workflows/cache-cleanup.yml

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,51 @@ jobs:
1313
steps:
1414
- name: Cleanup
1515
run: |
16-
echo "Fetching list of cache key"
17-
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
18-
19-
## Setting this to not fail the workflow while deleting cache keys.
20-
set +e
21-
echo "Deleting caches..."
22-
for cacheKey in $cacheKeysForPR
23-
do
24-
gh cache delete $cacheKey
16+
echo "# Cache Cleanup Summary" >> $GITHUB_STEP_SUMMARY
17+
echo "" >> $GITHUB_STEP_SUMMARY
18+
echo "**PR Number:** #${{ github.event.pull_request.number }}" >> $GITHUB_STEP_SUMMARY
19+
echo "**Branch:** \`$BRANCH\`" >> $GITHUB_STEP_SUMMARY
20+
echo "" >> $GITHUB_STEP_SUMMARY
21+
22+
echo "[DEBUG] Fetching cache list..."
23+
# Get full cache details
24+
CACHE_LIST=$(gh cache list --ref $BRANCH --limit 100 --json key,size,createdAt,id)
25+
26+
if [ -z "$CACHE_LIST" ] || [ "$CACHE_LIST" = "[]" ]; then
27+
echo "[DEBUG] No caches found"
28+
echo "No caches found for this PR" >> $GITHUB_STEP_SUMMARY
29+
exit 0
30+
fi
31+
32+
# Create table header
33+
echo "| Cache ID | Cache Key | Size | Created At | Status |" >> $GITHUB_STEP_SUMMARY
34+
echo "|----------|-----------|------|------------|--------|" >> $GITHUB_STEP_SUMMARY
35+
36+
# Extract IDs and process deletions
37+
echo "$CACHE_LIST" | jq -r '.[] | [.id, .key, .size, .createdAt] | @tsv' | while IFS=$'\t' read -r id key size created; do
38+
# Convert size to human readable format
39+
if [ $size -ge 1048576 ]; then
40+
readable_size=$(echo "scale=2; $size/1048576" | bc)"MB"
41+
else
42+
readable_size=$(echo "scale=2; $size/1024" | bc)"KB"
43+
fi
44+
45+
echo "[DELETE] Processing cache ID: $id"
46+
if gh cache delete $id > /dev/null 2>&1; then
47+
status="✅ Deleted"
48+
echo "[SUCCESS] Cache $id deleted"
49+
else
50+
status="❌ Failed"
51+
echo "[ERROR] Failed to delete cache $id"
52+
fi
53+
54+
# Add row to summary table
55+
echo "| \`$id\` | \`$key\` | $readable_size | $created | $status |" >> $GITHUB_STEP_SUMMARY
2556
done
26-
echo "Done"
57+
58+
# Add completion timestamp
59+
echo "" >> $GITHUB_STEP_SUMMARY
60+
echo "Cleanup completed at: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
2761
env:
2862
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2963
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)