Skip to content

Commit a24092c

Browse files
committed
cache cleanup pr
1 parent 6b23e9e commit a24092c

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Cleanup branch caches on merge
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
jobs:
8+
cleanup-cache:
9+
# Runs on both merged PRs and PRs closed without merging
10+
runs-on: ubuntu-latest
11+
permissions:
12+
actions: write
13+
steps:
14+
- name: Delete caches for merged branch
15+
run: |
16+
set +e
17+
CACHE_IDS=$(gh cache list \
18+
--repo "${{ github.repository }}" \
19+
--ref "refs/heads/${{ github.head_ref }}" \
20+
--limit 100 \
21+
--json id \
22+
--jq '.[].id')
23+
24+
if [ -z "$CACHE_IDS" ]; then
25+
echo "No caches found for branch ${{ github.head_ref }}"
26+
exit 0
27+
fi
28+
29+
echo "Deleting caches for merged branch: ${{ github.head_ref }}"
30+
echo "$CACHE_IDS" | while IFS= read -r id; do
31+
echo " Deleting cache ID: $id"
32+
gh cache delete "$id" --repo "${{ github.repository }}"
33+
done
34+
env:
35+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)