5
5
- cron : ' 0 2 * * *' # daily at 02:00 UTC
6
6
push :
7
7
branches : [ docker ]
8
+
8
9
permissions :
9
10
contents : read
10
11
packages : write
@@ -25,39 +26,41 @@ jobs:
25
26
sudo apt-get update
26
27
sudo apt-get install -y gh
27
28
28
-
29
- - name : Delete all but the newest version
29
+ - name : Delete all but the newest version for CPU & GPU images
30
30
env :
31
31
GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
32
- OWNER : ${{ github.repository_owner }}
33
- IMAGE : deep-learning-crash-course
32
+ OWNER : ${{ github.repository_owner }}
34
33
run : |
35
34
set -euo pipefail
36
35
37
- echo "Fetching all versions of $OWNER/$IMAGE…"
38
- versions=$(gh api --paginate \
39
- -H "Accept: application/vnd.github.v3+json" \
40
- /orgs/$OWNER/packages/container/$IMAGE/versions)
41
-
42
- newest_id=$(echo "$versions" \
43
- | jq -r 'sort_by(.created_at) | reverse | .[0].id')
44
- echo "🛡 Keeping version $newest_id (most recent)"
45
-
46
- echo "$versions" | jq -c '.[]' | while read version; do
47
- id=$(echo "$version" | jq -r '.id')
48
- if [[ "$id" != "$newest_id" ]]; then
49
- echo "→ Deleting version $id"
50
- # retry up to 3 times on transient errors
51
- for attempt in 1 2 3; do
52
- if gh api -X DELETE \
53
- -H "Accept: application/vnd.github.v3+json" \
54
- /orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
55
- echo " ✅ Deleted $id"
56
- break
57
- else
58
- echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s…"
59
- sleep $((5*attempt))
60
- fi
61
- done
62
- fi
36
+ for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
37
+ echo
38
+ echo "🔍 Processing package: $OWNER/$IMAGE"
39
+ versions=$(gh api --paginate \
40
+ -H "Accept: application/vnd.github.v3+json" \
41
+ /orgs/$OWNER/packages/container/$IMAGE/versions)
42
+
43
+ # pick most recent by creation date
44
+ newest_id=$(echo "$versions" \
45
+ | jq -r 'sort_by(.created_at) | reverse | .[0].id')
46
+ echo "🛡 Keeping version $newest_id for $IMAGE"
47
+
48
+ # delete every version except the newest
49
+ echo "$versions" | jq -c '.[]' | while read version; do
50
+ id=$(echo "$version" | jq -r '.id')
51
+ if [[ "$id" != "$newest_id" ]]; then
52
+ echo "→ Deleting version $id of $IMAGE"
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 in $((5*attempt))s…"
61
+ sleep $((5*attempt))
62
+ fi
63
+ done
64
+ fi
65
+ done
63
66
done
0 commit comments