From 67172a90294e3073b43df6a47fb207987323aa41 Mon Sep 17 00:00:00 2001 From: Josh W Lewis Date: Wed, 21 Feb 2024 10:01:55 -0600 Subject: [PATCH] Fixup unpublish step --- bin/unpublish-temp-tags.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) mode change 100644 => 100755 bin/unpublish-temp-tags.sh diff --git a/bin/unpublish-temp-tags.sh b/bin/unpublish-temp-tags.sh old mode 100644 new mode 100755 index c4030ef2..e0e30ff0 --- a/bin/unpublish-temp-tags.sh +++ b/bin/unpublish-temp-tags.sh @@ -3,19 +3,27 @@ set -euo pipefail set -x +dockerhub_token=$(curl -s -f -H "Content-Type: application/json" -X POST -d "{\"username\": \"${DOCKER_HUB_USERNAME}\", \"password\": \"${DOCKER_HUB_TOKEN}\"}" https://hub.docker.com/v2/users/login/ | jq -r .token) + unpublish_group() { - local tagBase="$1" + local stackVersion="$1" local targetTagSuffix="$2" variants=("" "-build") - if (( STACK_VERSION <= 22 )); then + if (( stackVersion <= 22 )); then variants+=("-cnb" "-cnb-build") fi for variant in "${variants[@]}"; do - hub-tool tag rm "${tagBase}${variant}${targetTagSuffix}" + echo "Deleting heroku/heroku:${stackVersion}${variant}${targetTagSuffix}" + code=$(curl -s -f -X DELETE -H "Authorization: JWT ${dockerhub_token}" --write-out "%{http_code}" + "https://hub.docker.com/v2/repositories/heroku/heroku/tags/${stackVersion}${variant}${targetTagSuffix}/") + + if (( code != 404 )) || (( code != 200 )) || (( code != 201 )); then + echo "Couldn't delete heroku/heroku:${stackVersion}${variant}${targetTagSuffix}: ${code}" + fi done } -publicTag="heroku/heroku:${STACK_VERSION}" -tempTagSuffix=".temp_${GITHUB_RUN_ID}" - -unpublish_group "${publicTag}" "${tempTagSuffix}" +stackVersion="${1:-$STACK_VERSION}" +tempTagSuffix="${2:-".temp_$GITHUB_RUN_ID"}" +# delete each tag in a group on Docker Hub. +unpublish_group "${stackVersion}" "${tempTagSuffix}"