Skip to content

Commit 7f4cd36

Browse files
committed
GHA - add more logging to cache cleaning workflow
1 parent c76c0a3 commit 7f4cd36

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

.github/workflows/cleanup-caches.yml

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,51 @@ jobs:
1212
steps:
1313
- name: Cleanup
1414
run: |
15-
echo "Fetching list of cache keys"
16-
cacheKeysForPR=$(gh cache list --ref $BRANCH --limit 100 --json id --jq '.[].id')
15+
echo "::group::Fetching cache list for PR #${{ github.event.pull_request.number }}"
16+
echo "Branch ref: $BRANCH"
17+
18+
# Get full cache list with details for logging
19+
cacheList=$(gh cache list --ref $BRANCH --limit 100 --json id,key,sizeInBytes)
20+
cacheCount=$(echo "$cacheList" | jq '. | length')
21+
22+
echo "Found $cacheCount cache(s) for this PR"
23+
24+
if [ "$cacheCount" -gt 0 ]; then
25+
echo "Cache details:"
26+
echo "$cacheList" | jq -r '.[] | " - ID: \(.id) | Key: \(.key) | Size: \(.sizeInBytes | tonumber / 1024 / 1024 | floor)MB"'
27+
fi
28+
echo "::endgroup::"
29+
30+
if [ "$cacheCount" -eq 0 ]; then
31+
echo "No caches to delete"
32+
exit 0
33+
fi
34+
35+
# Extract just the IDs for deletion
36+
cacheKeysForPR=$(echo "$cacheList" | jq -r '.[].id')
1737
1838
## Setting this to not fail the workflow while deleting cache keys.
1939
set +e
20-
echo "Deleting caches..."
40+
41+
echo "::group::Deleting caches"
42+
deleted=0
43+
failed=0
44+
2145
for cacheKey in $cacheKeysForPR
2246
do
23-
gh cache delete $cacheKey
47+
echo "Deleting cache ID: $cacheKey"
48+
if gh cache delete $cacheKey; then
49+
echo " ✓ Successfully deleted cache $cacheKey"
50+
((deleted++))
51+
else
52+
echo " ✗ Failed to delete cache $cacheKey"
53+
((failed++))
54+
fi
2455
done
25-
echo "Done"
56+
57+
echo "::endgroup::"
58+
59+
echo "::notice::Cache cleanup complete: $deleted deleted, $failed failed out of $cacheCount total"
2660
env:
2761
GH_TOKEN: ${{ github.token }}
2862
GH_REPO: ${{ github.repository }}

0 commit comments

Comments
 (0)