28
28
sudo apt-get update
29
29
sudo apt-get install -y gh
30
30
31
- - name : Re-tag newest as “latest” and prune the rest
31
+ - name : Delete all but the newest version for CPU & GPU images
32
32
env :
33
33
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
34
34
OWNER : ${{ github.repository_owner }}
@@ -37,27 +37,32 @@ jobs:
37
37
38
38
for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
39
39
echo
40
- echo "🔍 Processing $OWNER/$IMAGE"
40
+ echo "🔍 Processing package: $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
- # pick the newest by creation date
45
+ # pick most recent by creation date
46
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
53
-
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
47
+ | jq -r 'sort_by(.created_at) | reverse | .[0].id')
48
+ echo "🛡 Keeping version $newest_id for $IMAGE"
49
+
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"
55
+ for attempt in 1 2 3; do
56
+ if gh api -X DELETE \
57
+ -H "Accept: application/vnd.github.v3+json" \
58
+ /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
59
+ echo " ✅ Deleted $id"
60
+ break
61
+ else
62
+ echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s…"
63
+ sleep $((5*attempt))
64
+ fi
62
65
done
66
+ fi
67
+ done
63
68
done
0 commit comments