3030 - name : Delete old ${{ env.TAG_PREFIX }}* tags using GitHub API, keep ${{ env.KEEP_X_IMAGES }}
3131 run : |
3232 set -e
33+ set -o pipefail
3334
3435 # Get all ${{ env.TAG_PREFIX }}* tags and their version IDs, sorted by tag (descending)
3536 VERSIONS=$(gh api -H "Accept: application/vnd.github+json" \
@@ -42,14 +43,30 @@ jobs:
4243 echo "Deleting the following tags:"
4344 echo "$TO_DELETE" | awk '{print $2}'
4445
46+ if [ -z "$TO_DELETE" ]; then
47+ echo "No tags to delete."
48+ exit 0
49+ fi
50+
51+ FAILED_DELETIONS=""
4552 while read -r line; do
4653 id=$(echo "$line" | awk '{print $1}')
4754 tag=$(echo "$line" | awk '{print $2}')
4855 echo "Deleting tag $tag (version ID $id)"
49- gh api -X DELETE -H "Accept: application/vnd.github+json" \
50- /orgs/${{ env.ORG }}/packages/container/${{ env.IMAGE_NAME }}/versions/$id || echo "Failed to delete version $id ($tag)"
56+ if ! gh api -X DELETE -H "Accept: application/vnd.github+json" \
57+ /orgs/${{ env.ORG }}/packages/container/${{ env.IMAGE_NAME }}/versions/$id; then
58+ echo "Failed to delete version $id ($tag)"
59+ FAILED_DELETIONS="${FAILED_DELETIONS}\n$id ($tag)"
60+ fi
61+ echo "Failed to delete version $id ($tag)"
62+ FAILED_DELETIONS="${FAILED_DELETIONS}\n$id ($tag)"
63+ fi
5164 done <<< "$TO_DELETE"
5265
66+ if [ -n "$FAILED_DELETIONS" ]; then
67+ echo -e "The following deletions failed:\n$FAILED_DELETIONS"
68+ exit 1
69+ fi
5370 - name : List remaining ${{ env.TAG_PREFIX }}* tags and their version IDs (debug)
5471 run : |
5572 gh api -H "Accept: application/vnd.github+json" \
0 commit comments