2828 sudo apt-get update
2929 sudo apt-get install -y gh
3030
31- - name : Delete all non-`: latest` versions
31+ - name : Re-tag newest as “ latest” and prune the rest
3232 env :
3333 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3434 OWNER : ${{ github.repository_owner }}
@@ -37,29 +37,27 @@ jobs:
3737
3838 for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
3939 echo
40- echo "🔍 Processing package: $OWNER/$IMAGE"
40+ echo "🔍 Processing $OWNER/$IMAGE"
4141 versions=$(gh api --paginate \
4242 -H "Accept: application/vnd.github.v3+json" \
4343 /orgs/$OWNER/packages/container/$IMAGE/versions)
4444
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
45+ # pick the newest by creation date
46+ newest_id=$(echo "$versions" \
47+ | jq -r 'sort_by(.created_at) | last | .id')
48+ echo "🛡 Retagging version $newest_id as latest"
49+ gh api -X POST \
50+ -H "Accept: application/vnd.github.v3+json" \
51+ /orgs/$OWNER/packages/container/$IMAGE/versions/$newest_id/tags \
52+ -f name=latest
4953
50- id=$(echo "$version" | jq -r '.id')
51- tags=$(echo "$version" | jq -r '.metadata.container.tags[]')
52- echo "→ Deleting version $id (tags: $tags)"
53- for attempt in 1 2 3; do
54- if gh api -X DELETE \
55- -H "Accept: application/vnd.github.v3+json" \
56- /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
57- echo " ✅ Deleted $id"
58- break
59- else
60- echo " ⚠️ Attempt $attempt failed, retrying…"
61- sleep $((5*attempt))
62- fi
54+ # delete all other versions
55+ echo "$versions" \
56+ | jq -r --arg keep "$newest_id" '.[] | select(.id != ($keep|tonumber)) | .id' \
57+ | while read id; do
58+ echo "→ Deleting version $id"
59+ gh api -X DELETE \
60+ -H "Accept: application/vnd.github.v3+json" \
61+ /orgs/$OWNER/packages/container/$IMAGE/versions/$id
6362 done
64- done
6563 done
0 commit comments