Skip to content

Commit 61ad58f

Browse files
committed
clean all
1 parent f0310ec commit 61ad58f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

.github/workflows/prune-all.yml

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "Prune all GHCR image versions"
1+
name: "Prune old GHCR images"
22

33
on:
44
push:
@@ -24,7 +24,7 @@ jobs:
2424
sudo apt-get update
2525
sudo apt-get install -y gh
2626
27-
- name: Delete **all** versions of CPU & GPU images
27+
- name: Delete all but the newest version for CPU & GPU images
2828
env:
2929
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3030
OWNER: ${{ github.repository_owner }}
@@ -34,25 +34,24 @@ jobs:
3434
for IMAGE in deep-learning-crash-course deep-learning-crash-course-gpu; do
3535
echo
3636
echo "🔍 Processing package: $OWNER/$IMAGE"
37-
38-
# Fetch all versions (paginated)
3937
versions=$(gh api --paginate \
4038
-H "Accept: application/vnd.github.v3+json" \
4139
/orgs/$OWNER/packages/container/$IMAGE/versions)
4240
43-
# Delete every version ID
44-
echo "$versions" | jq -r '.[].id' | while read id; do
41+
# delete every version except the newest
42+
echo "$versions" | jq -c '.[]' | while read version; do
43+
id=$(echo "$version" | jq -r '.id')
4544
echo "→ Deleting version $id of $IMAGE"
4645
for attempt in 1 2 3; do
47-
if gh api -X DELETE \
48-
-H "Accept: application/vnd.github.v3+json" \
49-
/orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
46+
if gh api -X DELETE \
47+
-H "Accept: application/vnd.github.v3+json" \
48+
/orgs/$OWNER/packages/container/$IMAGE/versions/$id; then
5049
echo " ✅ Deleted $id"
5150
break
52-
else
51+
else
5352
echo " ⚠️ Attempt $attempt failed, retrying in $((5*attempt))s…"
5453
sleep $((5*attempt))
55-
fi
54+
fi
5655
done
5756
done
58-
done
57+
done

0 commit comments

Comments
 (0)