-
Notifications
You must be signed in to change notification settings - Fork 0
56 lines (50 loc) · 1.91 KB
/
prune.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
---
name: Prune Untagged Images
on:
schedule:
- cron: '22 1 * * *' # 22 past 1am daily
workflow_dispatch:
jobs:
prune_images:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
# Based on https://github.com/orgs/community/discussions/26716#discussioncomment-3253034
# Thanks to @jcansdale
script: |
const response = await github.request("GET /${{ env.OWNER }}/packages/container/${{ env.PACKAGE_NAME }}/versions",
{ per_page: ${{ env.PER_PAGE }}
});
empty_tag_versions = response.data.filter(function(version) {
return version.metadata.container.tags.length == 0;
}
)
sort_by_created_date = function(a, b) {
date_a = new Date(a.created_at)
date_b = new Date(b.created_at)
// Oldest first
if ( date_a > date_b) {
return 1;
} else if ( date_b > date_a ) {
return -1;
} else {
return 0;
}
}
empty_tag_versions.sort(sort_by_created_date)
console.log(empty_tag_versions)
num_to_delete = empty_tag_versions.length - ${{ env.KEEP_MIN }}
console.log("Number of versions to delete: " + num_to_delete)
for (let i = 0; i < num_to_delete; i++){
version = empty_tag_versions[i]
console.log("delete " + version.id)
const deleteResponse = await github.request("DELETE /${{ env.OWNER }}/packages/container/${{ env.PACKAGE_NAME }}/versions/" + version.id, { });
console.log("status " + deleteResponse.status)
}
env:
OWNER: orgs/UtrechtUniversity
PACKAGE_NAME: SRC-test-workspace
KEEP_MIN: 3
PER_PAGE: 100