-
-
Notifications
You must be signed in to change notification settings - Fork 755
42 lines (34 loc) · 1.24 KB
/
clean-up-pr-caches.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#force-deleting-cache-entries
name: Cleanup caches for closed branches
on:
pull_request:
types: [closed]
workflow_dispatch:
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: 🧹 Cleanup caches
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
run: |
# Install GitHub CLI cache extension
gh extension install actions/gh-actions-cache
echo "Fetching list of cache keys..."
cacheKeys=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1)
# Continue even if some cache deletions fail
set +e
if [ -z "$cacheKeys" ]; then
echo "No caches found to delete"
exit 0
fi
echo "Deleting caches..."
for cacheKey in $cacheKeys; do
echo "Deleting cache: $cacheKey"
gh actions-cache delete "$cacheKey" -R $REPO -B $BRANCH --confirm
done
echo "Cache cleanup completed"