@@ -15,48 +15,46 @@ jobs:
1515 steps :
1616 - name : Delete GHCR image
1717 run : |
18- set -x
18+ set -euxo pipefail
1919
20- # Hardcoded GHCR image repository
2120 REPO="datasqrl/flink-sql-runner"
22-
23- # PR image tag is pr-<number>-<flink_profile>
2421 TAG="pr-${{ github.event.number }}-${{ matrix.FLINK_PROFILE }}"
2522 IMAGE="ghcr.io/$REPO:$TAG"
2623
2724 echo "Attempting to delete image: $IMAGE"
2825
29- # Build Basic Auth header from PAT credentials
3026 TOKEN_BASE64="$(echo -n "${{ secrets.PAT_USERNAME }}:${{ secrets.PAT_PASSWORD }}" | base64)"
3127
32- # Make GET request to fetch Docker-Content-Digest header
3328 RAW_RESPONSE=$(curl -sD - \
3429 -H "Authorization: Basic $TOKEN_BASE64" \
35- -H "Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json,application/vnd.oci.image.index.v1+json " \
30+ -H "Accept: application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.docker.distribution.manifest.v2+json" \
3631 "https://ghcr.io/v2/$REPO/manifests/$TAG")
3732
38- # Output raw response for debugging
39- echo "==== RAW RESPONSE START ===="
40- echo "$RAW_RESPONSE"
41- echo "==== RAW RESPONSE END ===="
33+ # Immediately check HTTP status
34+ STATUS_CODE=$(echo "$RAW_RESPONSE" | grep HTTP | awk '{print $2}' | tr -d $'\r')
4235
43- # Separate headers from body
44- HEADERS=$(echo "$RAW_RESPONSE" | sed -n '/^HTTP/,$p' | sed '/^$/q')
36+ if [[ "$STATUS_CODE" -eq 401 ]]; then
37+ echo "ERROR: Unauthorized (401). Check your PAT credentials or GHCR permissions."
38+ exit 1
39+ elif [[ "$STATUS_CODE" -eq 404 ]]; then
40+ echo "ERROR: Image not found (404). Check your image name or tag."
41+ exit 1
42+ elif [[ "$STATUS_CODE" -ge 400 ]]; then
43+ echo "ERROR: Unexpected error occurred. HTTP status: $STATUS_CODE"
44+ exit 1
45+ fi
4546
46- # Extract Docker-Content-Digest from headers
47+ HEADERS=$(echo "$RAW_RESPONSE" | sed -n '/^HTTP/,$p' | sed '/^$/q')
4748 DIGEST=$(echo "$HEADERS" | awk '/docker-content-digest:/ { print $2 }' | tr -d $'\r')
4849
4950 if [[ -z "$DIGEST" ]]; then
50- echo "ERROR: No digest found in GHCR response. The image might not exist, or GHCR didn’t return the digest."
51- echo "==== HEADERS START ===="
51+ echo "ERROR: No digest found. Response headers were:"
5252 echo "$HEADERS"
53- echo "==== HEADERS END ===="
5453 exit 1
5554 fi
5655
5756 echo "Found digest: $DIGEST"
5857
59- # DELETE the image by digest
6058 DELETE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
6159 -X DELETE \
6260 -H "Authorization: Basic $TOKEN_BASE64" \
0 commit comments