2828 sudo apt-get update
2929 sudo apt-get install -y gh
3030
31- - name : Delete all but the newest version for CPU & GPU images
31+ - name : Delete all non-`:latest` versions
3232 env :
3333 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3434 OWNER : ${{ github.repository_owner }}
@@ -42,27 +42,24 @@ jobs:
4242 -H "Accept: application/vnd.github.v3+json" \
4343 /orgs/$OWNER/packages/container/$IMAGE/versions)
4444
45- # pick most recent by creation date
46- newest_id=$( echo "$versions" \
47- | jq -r 'sort_by(.created_at ) | reverse | .[0].id')
48- echo "🛡 Keeping version $newest_id for $IMAGE"
45+ # Only delete versions *not* tagged "latest"
46+ echo "$versions" \
47+ | jq -c '.[] | select((.metadata.container.tags // [] ) | index("latest") | not)' \
48+ | while read version; do
4949
50- # delete every version except the newest
51- echo "$versions" | jq -c '.[]' | while read version; do
52- id=$(echo "$version" | jq -r '.id')
53- if [[ "$id" != "$newest_id" ]]; then
54- echo "→ Deleting version $id of $IMAGE"
50+ id=$(echo "$version" | jq -r '.id')
51+ tags=$(echo "$version" | jq -r '.metadata.container.tags[]')
52+ echo "→ Deleting version $id (tags: $tags)"
5553 for attempt in 1 2 3; do
5654 if gh api -X DELETE \
5755 -H "Accept: application/vnd.github.v3+json" \
5856 /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
5957 echo " ✅ Deleted $id"
6058 break
6159 else
62- echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s …"
60+ echo " ⚠️ Attempt $attempt failed, retrying…"
6361 sleep $((5*attempt))
6462 fi
6563 done
66- fi
67- done
68- done
64+ done
65+ done
0 commit comments