Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit e9fa043

Browse files
authored
Merge pull request #280 from mtdvlpr/patch-2
chore: cleanup cache on PR close
2 parents e958210 + 8d0cb4c commit e9fa043

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

.github/workflows/cleanup.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Cleanup cache
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
workflow_dispatch:
7+
inputs:
8+
branch:
9+
description: 'Branch ref to delete caches for'
10+
required: true
11+
type: string
12+
13+
jobs:
14+
cleanup:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- name: Check out code
18+
uses: actions/checkout@v4
19+
20+
- name: Cleanup cache
21+
run: |
22+
gh extension install actions/gh-actions-cache
23+
24+
REPO=${{ github.server_url }}/${{ github.repository }}
25+
REF=${{ github.event.pull_request.number }}
26+
BRANCH=${{ inputs.branch || 'refs/pull/$REF/merge' }}
27+
28+
echo "Fetching list of cache key"
29+
echo $BRANCH
30+
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
31+
echo $cacheKeysForPR
32+
33+
## Setting this to not fail the workflow while deleting cache keys.
34+
set +e
35+
echo "Deleting caches..."
36+
for cacheKey in $cacheKeysForPR
37+
do
38+
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
39+
done
40+
echo "Done"
41+
env:
42+
GH_TOKEN: ${{ github.token }}

0 commit comments

Comments
 (0)