@@ -25,26 +25,39 @@ jobs:
2525 sudo apt-get update
2626 sudo apt-get install -y gh
2727
28+
2829 - name : Delete all but the newest version
2930 env :
31+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3032 OWNER : ${{ github.repository_owner }}
3133 IMAGE : deep-learning-crash-course
32- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3334 run : |
34- echo "Fetching all versions of $OWNER/$IMAGE..."
35- versions=$(gh api --paginate -H "Accept: application/vnd.github.v3+json" \
36- /orgs/$OWNER/packages/container/$IMAGE/versions)
35+ set -euo pipefail
36+
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+
3742 newest_id=$(echo "$versions" \
38- | jq -r 'sort_by(.created_at) | reverse | .[0].id')
43+ | jq -r 'sort_by(.created_at) | reverse | .[0].id')
3944 echo "🛡 Keeping version $newest_id (most recent)"
40- echo "$versions" | jq -c '.[]' | while read ver; do
41- id=$(echo "$ver" | jq -r '.id')
42- if [ "$id" != "$newest_id" ]; then
43- echo "Deleting version $id"
44- gh api -X DELETE \
45- -H "Accept: application/vnd.github.v3+json" \
46- /orgs/$OWNER/packages/container/$IMAGE/versions/$id
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
4762 fi
4863 done
49-
50-
0 commit comments