28
28
sudo apt-get update
29
29
sudo apt-get install -y gh
30
30
31
- - name : Delete all non-`: latest` versions
31
+ - name : Re-tag newest as “ latest” and prune the rest
32
32
env :
33
33
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
34
34
OWNER : ${{ github.repository_owner }}
@@ -37,29 +37,27 @@ jobs:
37
37
38
38
for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
39
39
echo
40
- echo "🔍 Processing package: $OWNER/$IMAGE"
40
+ echo "🔍 Processing $OWNER/$IMAGE"
41
41
versions=$(gh api --paginate \
42
42
-H "Accept: application/vnd.github.v3+json" \
43
43
/orgs/$OWNER/packages/container/$IMAGE/versions)
44
44
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
49
53
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
63
62
done
64
- done
65
63
done
0 commit comments