Showing the changes to .github (1 of 1 file). Show all
Unified · Split
| @@ -102,3 +102,38 @@ jobs: · 101 unmodified lines | ||
| 102 | 102 | --tag "${DOCKERHUB_REPO}:${VERSION}" \ |
| 103 | 103 | "${DOCKERHUB_REPO}:${VERSION}-amd64" \ |
| 104 | 104 | "${DOCKERHUB_REPO}:${VERSION}-arm64" |
| 105 | + - name: Cleanup temporary tags | |
| 106 | + continue-on-error: true | |
| 107 | + env: | |
| 108 | + DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} | |
| 109 | + DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
| 110 | + run: | | |
| 111 | + set -euo pipefail | |
| 112 | + namespace="${DOCKERHUB_REPO%%/*}" | |
| 113 | + repo_name="${DOCKERHUB_REPO#*/}" | |
| 114 | + | |
| 115 | + token="$( | |
| 116 | + curl -fsSL \ | |
| 117 | + -H 'Content-Type: application/json' \ | |
| 118 | + -d "{\"username\":\"${DOCKERHUB_USERNAME}\",\"password\":\"${DOCKERHUB_TOKEN}\"}" \ | |
| 119 | + 'https://hub.docker.com/v2/users/login/' \ | |
| 120 | + | python3 -c 'import json,sys; print(json.load(sys.stdin)["token"])' | |
| 121 | + )" | |
| 122 | + | |
| 123 | + delete_tag() { | |
| 124 | + local tag="$1" | |
| 125 | + local url="https://hub.docker.com/v2/repositories/${namespace}/${repo_name}/tags/${tag}/" | |
| 126 | + local http_code | |
| 127 | + http_code="$(curl -sS -o /dev/null -w "%{http_code}" -X DELETE -H "Authorization: JWT ${token}" "${url}" || true)" | |
| 128 | + if [ "${http_code}" = "204" ] || [ "${http_code}" = "404" ]; then | |
| 129 | + echo "Docker Hub tag removed (or missing): ${DOCKERHUB_REPO}:${tag} (HTTP ${http_code})" | |
| 130 | + return 0 | |
| 131 | + fi | |
| 132 | + echo "Docker Hub tag delete failed: ${DOCKERHUB_REPO}:${tag} (HTTP ${http_code})" | |
| 133 | + return 0 | |
| 134 | + } | |
| 135 | + | |
| 136 | + delete_tag "latest-amd64" | |
| 137 | + delete_tag "latest-arm64" | |
| 138 | + delete_tag "${VERSION}-amd64" | |
| 139 | + delete_tag "${VERSION}-arm64" | |