This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
75 lines (63 loc) · 1.96 KB
/
docker_clean.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
name: Docker Clean
on:
delete:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:
env:
OWNER: "pydrocsid"
NAME: "morpheushelper"
PLATFORMS: "linux/amd64 linux/arm/v7 linux/arm64/v8 linux/s390x linux/ppc64le"
jobs:
docker_clean:
name: Docker Clean
runs-on: ubuntu-latest
environment: docker-clean
concurrency: docker_clean
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Clean
env:
GITHUB_TOKEN: ${{ secrets.CR_PAT }}
OWNER: ${{ env.OWNER }}
NAME: ${{ env.NAME }}
PLATFORMS: ${{ env.PLATFORMS }}
run: |
set -ex
keep=()
add() {
keep+=("${1}")
for platform in ${PLATFORMS}; do
keep+=("${1}-${platform}")
done
}
add latest
add edge
for branch in $(git ls-remote --heads origin | cut -d/ -f3-); do
echo Found branch: $branch
add $branch
done
for tag in $(git tag); do
echo Found tag: $tag
add $tag
done
keep=$(printf '%s\n' "${keep[@]}" | tr / - | jq -R . | jq -cs .)
URL=/users/${OWNER}/packages/container/${NAME}/versions
page=1
versions=$(mktemp)
while true; do
gh api "${URL}?per_page=100&page=${page}" | jq -c '.[]' > page
if ! [[ -s page ]]; then break; fi
jq -c '.metadata.container.tags as $tags | select($tags-($tags-'"$keep"')==[])' page >> $versions
page=$((page+1))
done
while read version; do
id=$(jq -r .id <<< "$version")
name=$(jq -r .name <<< "$version")
echo Pruning $id $name
curl -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com${URL}/${id}"
done < $versions
echo Pruned $(jq -rs length $versions) versions