@@ -15,48 +15,46 @@ jobs:
15
15
steps :
16
16
- name : Delete GHCR image
17
17
run : |
18
- set -x
18
+ set -euxo pipefail
19
19
20
- # Hardcoded GHCR image repository
21
20
REPO="datasqrl/flink-sql-runner"
22
-
23
- # PR image tag is pr-<number>-<flink_profile>
24
21
TAG="pr-${{ github.event.number }}-${{ matrix.FLINK_PROFILE }}"
25
22
IMAGE="ghcr.io/$REPO:$TAG"
26
23
27
24
echo "Attempting to delete image: $IMAGE"
28
25
29
- # Build Basic Auth header from PAT credentials
30
26
TOKEN_BASE64="$(echo -n "${{ secrets.PAT_USERNAME }}:${{ secrets.PAT_PASSWORD }}" | base64)"
31
27
32
- # Make GET request to fetch Docker-Content-Digest header
33
28
RAW_RESPONSE=$(curl -sD - \
34
29
-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" \
36
31
"https://ghcr.io/v2/$REPO/manifests/$TAG")
37
32
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')
42
35
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
45
46
46
- # Extract Docker-Content-Digest from headers
47
+ HEADERS=$(echo "$RAW_RESPONSE" | sed -n '/^HTTP/,$p' | sed '/^$/q')
47
48
DIGEST=$(echo "$HEADERS" | awk '/docker-content-digest:/ { print $2 }' | tr -d $'\r')
48
49
49
50
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:"
52
52
echo "$HEADERS"
53
- echo "==== HEADERS END ===="
54
53
exit 1
55
54
fi
56
55
57
56
echo "Found digest: $DIGEST"
58
57
59
- # DELETE the image by digest
60
58
DELETE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
61
59
-X DELETE \
62
60
-H "Authorization: Basic $TOKEN_BASE64" \
0 commit comments