@@ -13,17 +13,51 @@ jobs:
13
13
steps :
14
14
- name : Cleanup
15
15
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
25
56
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
27
61
env :
28
62
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
29
63
GH_REPO : ${{ github.repository }}
0 commit comments