File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 }}
You can’t perform that action at this time.
0 commit comments