-
Notifications
You must be signed in to change notification settings - Fork 188
154 lines (138 loc) · 5.46 KB
/
clean_caches.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
on:
workflow_dispatch:
inputs:
cache_type:
type: choice
description: What kind of caches to delete. Note that *all* caches of that type will be deleted.
options:
- branch
- tar
- selective
required: false
default: selective
cache_keys:
type: string
description: Space separated string of cache keys to delete.
required: false
workflow_run:
workflows:
- CI
- Deployments
types:
- completed
delete:
pull_request_target:
types:
- closed
name: Clean GitHub caches
jobs:
automatic_cleanup:
name: Clean up GitHub caches produced by other workflows
if: github.event_name == 'workflow_run'
permissions: write-all
runs-on: ubuntu-latest
steps:
- name: Download cache keys
id: artifacts
run: |
artifacts_url=${{ github.event.workflow_run.artifacts_url }}
artifacts=$(gh api $artifacts_url -q '.artifacts[] | {name: .name, url: .archive_download_url}')
for artifact in `echo "$artifacts"`; do
name=`echo $artifact | jq -r '.name'`
if [ "${name#cache_key}" != "${name}" ]; then
url=`echo $artifact | jq -r '.url'`
gh api $url > cache_keys.zip
unzip -d cache_keys cache_keys.zip
for file in `find cache_keys/ -type f`; do
keys+=" `cat $file`"
done
rm -rf cache_keys cache_keys.zip
fi
done
echo "cache_keys='$(echo $keys)'" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- run: |
gh extension install actions/gh-actions-cache
for key in `echo ${{ steps.artifacts.outputs.cache_keys }}`; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}
selective_cleanup:
name: Clean up selective GitHub caches
if: (github.event_name == 'workflow_dispatch' && inputs.cache_keys != '' )
runs-on: ubuntu-latest
permissions: write-all
steps:
- run: |
gh extension install actions/gh-actions-cache
for key in ${{ inputs.cache_keys }}; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}
tar_cleanup:
name: Clean up Github caches with tar archives
if: (github.event_name == 'workflow_dispatch' && inputs.cache_type == 'tar' )
runs-on: ubuntu-latest
permissions: write-all
steps:
- run: |
gh extension install actions/gh-actions-cache
keys=$(gh actions-cache list -R ${{ github.repository }} --key tar- | cut -f 1 )
for key in $keys; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}
branch_cleanup:
name: Clean up branch specific caches
if: (github.event_name == 'workflow_dispatch' && inputs.cache_type == 'branch' ) || (github.event_name == 'delete' && github.event.ref_type == 'branch')
runs-on: ubuntu-latest
permissions: write-all
steps:
- name: Delete GitHub caches
run: |
gh extension install actions/gh-actions-cache
keys=$(gh actions-cache list -R ${{ github.repository }} -B ${{ github.event.ref }} | cut -f 1 )
for key in $keys; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}
# For the installer validation, we push a cache for the minimal MPI build.
# This cache is pushed every time, and some caches are even shared between different branches.
# We can hence delete the entire build cache for all branches at any time without significant
# downsides, and do just that here to have some periodic clean up.
- name: Delete build caches for MPI asset (ARM64)
uses: actions/delete-package-versions@v5
with:
package-name: buildcache-cuda-quantum-assets-openmpi-gcc11-arm64
package-type: 'container'
min-versions-to-keep: 1 # the used action does not support 0 here
- name: Delete build caches for MPI asset (AMD64)
uses: actions/delete-package-versions@v5
with:
package-name: buildcache-cuda-quantum-assets-openmpi-gcc11-amd64
package-type: 'container'
min-versions-to-keep: 1 # the used action does not support 0 here
pr_cleanup:
name: Clean up PR related GitHub caches
if: github.event_name == 'pull_request_target'
runs-on: ubuntu-latest
permissions: write-all
steps:
- run: |
gh extension install actions/gh-actions-cache
keys=$(gh actions-cache list -R ${{ github.repository }} -B refs/pull/${{ github.event.number }}/merge | cut -f 1 )
for key in $keys; do
(gh actions-cache delete $key -R ${{ github.repository }} --confirm && echo "Deleted cache $key") \
|| echo "Cache $key not found"
done
env:
GH_TOKEN: ${{ github.token }}