-
Notifications
You must be signed in to change notification settings - Fork 0
37 lines (33 loc) · 1.15 KB
/
cache.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
name: Cleanup caches by a branch
on:
pull_request:
types:
- closed
workflow_dispatch:
inputs:
pull_request_number:
description: 'Run on pull request number'
required: false
type: string
jobs:
cleanup:
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Cleanup
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH=${{ env.PULL_REQUEST_NUMBER && format('refs/pull/{0}/merge', env.PULL_REQUEST_NUMBER) || github.ref }}
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
while [[ $(gh actions-cache list -R $REPO -B $BRANCH | grep -v 'no Actions caches') ]]
do
gh actions-cache list -R $REPO -B $BRANCH --limit=100 | cut -f 1 | xargs -I{} gh actions-cache delete {} -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number || inputs.pull_request_number }}