Skip to content

Commit 68fcc41

Browse files
committed
feat(ci): add automatic PR cache cleanup workflow
- Automatically clean up GitHub Actions caches when PRs are closed - Prevents cache accumulation and keeps repository tidy - Uses concurrency control to prevent duplicate cleanup runs - Continues on deletion errors to ensure workflow completes - Includes 10-minute timeout for safety
1 parent efec878 commit 68fcc41

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
name: Cleanup Cache
3+
4+
on:
5+
pull_request:
6+
types:
7+
- closed
8+
9+
concurrency:
10+
group: cleanup-cache-${{ github.event.pull_request.number }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
cleanup:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 10
17+
permissions:
18+
actions: write
19+
steps:
20+
- name: 🧹 Cleanup Cache
21+
run: |
22+
echo "Fetching list of cache keys"
23+
cacheKeysForPR=$(gh cache list --ref "$BRANCH" --limit 100 --json id --jq ".[].id")
24+
25+
## Setting this to not fail the workflow while deleting cache keys.
26+
set +e
27+
echo "Deleting caches..."
28+
for cacheKey in $cacheKeysForPR
29+
do
30+
gh cache delete "$cacheKey"
31+
done
32+
echo "Done"
33+
env:
34+
GH_TOKEN: ${{ github.token }}
35+
GH_REPO: ${{ github.repository }}
36+
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge

0 commit comments

Comments
 (0)