forked from unikraft/kraftkit
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (71 loc) · 2.71 KB
/
expire-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
name: Expire Action Caches
on:
push:
branches: [staging]
jobs:
check-and-update:
name: Clean
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Clean up obsolete caches
uses: actions/github-script@v6
with:
script: |
const cachePrefixes = new Map([
['e2e-cli-Linux-go-', 0],
['gochecks-Linux-go-', 0],
['gounit-Linux-go-', 0],
['build-protoc-Linux-go-', 0],
['build-qemu-devices-Linux-go-', 0]
]);
const cacheSuffixLen = 64
await github.
paginate(github.rest.actions.getActionsCacheList, {
owner: context.repo.owner,
repo: context.repo.repo
})
.then(caches => {
for (const cache of caches) {
if (cache.ref == 'refs/heads/staging') {
const cachePrefix = cache.key.slice(0, -cacheSuffixLen)
if (cachePrefixes.has(cachePrefix)) {
const seen = cachePrefixes.get(cachePrefix)
if (seen > 0) {
(async () => {
await github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id
})
core.notice(`Deleted cache with key ${cache.key} for ref ${cache.ref}`)
})()
}
cachePrefixes.set(cachePrefix, seen + 1)
}
} else {
(async () => {
await github.rest.repos.getBranch({
owner: context.repo.owner,
repo: context.repo.repo,
branch: cache.ref
})
.catch(error => {
if (error.status == 404) {
(async () => {
await github.rest.actions.deleteActionsCacheById({
owner: context.repo.owner,
repo: context.repo.repo,
cache_id: cache.id
})
core.notice(`Deleted cache with key ${cache.key} for ref ${cache.ref}`)
})()
} else {
throw error
}
})
})()
}
}
});