1
- name : " Prune old GHCR images "
1
+ name: "Prune all GHCR image versions "
2
2
3
3
on:
4
4
push:
24
24
sudo apt-get update
25
25
sudo apt-get install -y gh
26
26
27
- - name : Delete all but the newest version for CPU & GPU images
27
+ - name: Delete ** all** versions of CPU & GPU images
28
28
env:
29
29
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
30
30
OWNER: ${{ github.repository_owner }}
@@ -34,24 +34,25 @@ jobs:
34
34
for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
35
35
echo
36
36
echo "🔍 Processing package: $OWNER/$IMAGE"
37
+
38
+ # Fetch all versions (paginated)
37
39
versions=$(gh api --paginate \
38
40
-H "Accept: application/vnd.github.v3+json" \
39
41
/orgs/$OWNER/packages/container/$IMAGE/versions)
40
42
41
- # delete every version except the newest
42
- echo "$versions" | jq -c '.[]' | while read version; do
43
- id=$(echo "$version" | jq -r '.id')
43
+ # Delete every version ID
44
+ echo "$versions" | jq -r '.[].id' | while read id; do
44
45
echo "→ Deleting version $id of $IMAGE"
45
46
for attempt in 1 2 3; do
46
- if gh api -X DELETE \
47
- -H "Accept: application/vnd.github.v3+json" \
48
- /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
47
+ if gh api -X DELETE \
48
+ -H "Accept: application/vnd.github.v3+json" \
49
+ /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
49
50
echo " ✅ Deleted $id"
50
51
break
51
- else
52
+ else
52
53
echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s…"
53
54
sleep $((5*attempt))
54
- fi
55
+ fi
55
56
done
56
57
done
57
- done
58
+ done
0 commit comments