Skip to content

Commit ca5208b

Browse files
committed
cpu and gpu
1 parent d5932bb commit ca5208b

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

.github/workflows/cleanup-ghcr.yml

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
- cron: '0 2 * * *' # daily at 02:00 UTC
66
push:
77
branches: [ docker ]
8+
89
permissions:
910
contents: read
1011
packages: write
@@ -25,39 +26,41 @@ jobs:
2526
sudo apt-get update
2627
sudo apt-get install -y gh
2728
28-
29-
- name: Delete all but the newest version
29+
- name: Delete all but the newest version for CPU & GPU images
3030
env:
3131
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
OWNER: ${{ github.repository_owner }}
33-
IMAGE: deep-learning-crash-course
32+
OWNER: ${{ github.repository_owner }}
3433
run: |
3534
set -euo pipefail
3635
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
6366
done

0 commit comments

Comments
 (0)