generated from sindresorhus/node-module-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
40 lines (34 loc) · 1.15 KB
/
purge-pr-cache.yaml
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
name: Purge closed PR cache
on:
pull_request:
types:
- closed
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Cleanup
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
BRANCH: refs/pull/${{ github.event.pull_request.number }}/merge
run: |
set -euo pipefail
echo "Installing GitHub CLI extension..."
gh extension install actions/gh-actions-cache
echo "Fetching list of cache keys..."
cacheKeysForPR=$(gh actions-cache list -R "$REPO" -B "$BRANCH" -L 100 | cut -f 1)
if [ -z "$cacheKeysForPR" ]; then
echo "No caches found to purge."
exit 0
fi
echo "Deleting caches..."
echo "$cacheKeysForPR" | while read -r cacheKey; do
if [ -n "$cacheKey" ]; then
echo "Deleting cache key: $cacheKey"
gh actions-cache delete "$cacheKey" -R "$REPO" -B "$BRANCH" --confirm || echo "Failed to delete cache key: $cacheKey"
fi
done
echo "Cache purge complete."