1- name : " Prune old GHCR images "
1+ name: "Prune all GHCR image versions "
22
33on:
44 push:
2424 sudo apt-get update
2525 sudo apt-get install -y gh
2626
27- - name : Delete all but the newest version for CPU & GPU images
27+ - name: Delete ** all** versions of CPU & GPU images
2828 env:
2929 GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030 OWNER: ${{ github.repository_owner }}
@@ -34,24 +34,25 @@ jobs:
3434 for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
3535 echo
3636 echo "🔍 Processing package: $OWNER/$IMAGE"
37+
38+ # Fetch all versions (paginated)
3739 versions=$(gh api --paginate \
3840 -H "Accept: application/vnd.github.v3+json" \
3941 /orgs/$OWNER/packages/container/$IMAGE/versions)
4042
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
4445 echo "→ Deleting version $id of $IMAGE"
4546 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
4950 echo " ✅ Deleted $id"
5051 break
51- else
52+ else
5253 echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s…"
5354 sleep $((5*attempt))
54- fi
55+ fi
5556 done
5657 done
57- done
58+ done
0 commit comments