-
Notifications
You must be signed in to change notification settings - Fork 83
51 lines (45 loc) · 1.86 KB
/
remove-obsolete-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
name: Cleanup obsolete caches
on:
pull_request:
types:
- closed
jobs:
cleanup:
runs-on: ubuntu-latest
steps:
- name: Remove caches
run: |
gh extension install actions/gh-actions-cache
REPO=${{ github.repository }}
BRANCH="refs/pull/${{ github.event.pull_request.number }}/merge"
echo "Fetching list of cache key"
cacheKeysForPR=$(gh actions-cache list -R $REPO -B $BRANCH | cut -f 1 )
## Setting this to not fail the workflow while deleting cache keys.
set +e
echo "Deleting caches..."
for cacheKey in $cacheKeysForPR
do
gh actions-cache delete $cacheKey -R $REPO -B $BRANCH --confirm
done
echo "Done"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Remove untagged docker images
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_tag = "pr-${{ github.event.pull_request.number }}"
for (const image of ["hash-graph-cache", "hash-ai-worker-ts-cache", "hash-integration-worker-cache"]) {
const url = "/orgs/hashintel/packages/container/" + image + "/versions";
const response = await github.request("GET " + url, { per_page: 100 });
for (const version of response.data) {
if (version.metadata.container.tags.length == 0 || version.metadata.container.tags.includes(pr_tag)) {
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE " + url + "/" + version.id, { });
console.log("status " + deleteResponse.status)
}
}
}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}