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