@@ -25,26 +25,39 @@ jobs:
25
25
sudo apt-get update
26
26
sudo apt-get install -y gh
27
27
28
+
28
29
- name : Delete all but the newest version
29
30
env :
31
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
30
32
OWNER : ${{ github.repository_owner }}
31
33
IMAGE : deep-learning-crash-course
32
- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
33
34
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
+
37
42
newest_id=$(echo "$versions" \
38
- | jq -r 'sort_by(.created_at) | reverse | .[0].id')
43
+ | jq -r 'sort_by(.created_at) | reverse | .[0].id')
39
44
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
47
62
fi
48
63
done
49
-
50
-
0 commit comments