Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Commit 7a26e2b

Browse files
committed
#whatwouldshellcheckdo
1 parent 84dfb7c commit 7a26e2b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

entrypoint.sh

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh -l
1+
#!/bin/sh
22

33
set -e
44

@@ -19,30 +19,30 @@ fi
1919

2020
# If URL array is passed, only purge those. Otherwise, purge everything.
2121
if [ -n "$PURGE_URLS" ]; then
22-
DATA_ARG='{"files":'"${PURGE_URLS}"'}'
22+
set -- --data '{"files":'"${PURGE_URLS}"'}'
2323
else
24-
DATA_ARG='{"purge_everything":true}'
24+
set -- --data '{"purge_everything":true}'
2525
fi
2626

2727
# Call the API and store the response for later.
2828
HTTP_RESPONSE=$(curl -sS -X POST "https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE}/purge_cache" \
29-
-H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
30-
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
31-
-H "Content-Type: application/json" \
32-
--data ${DATA_ARG} \
33-
--write-out "HTTP_STATUS:%{http_code}")
29+
-H "X-Auth-Email: ${CLOUDFLARE_EMAIL}" \
30+
-H "X-Auth-Key: ${CLOUDFLARE_KEY}" \
31+
-H "Content-Type: application/json" \
32+
-w "HTTP_STATUS:%{http_code}" \
33+
"$@")
3434

3535
# Store result and HTTP status code separately to appropriately throw CI errors.
3636
# https://gist.github.com/maxcnunes/9f77afdc32df354883df
37-
HTTP_BODY=$(echo $HTTP_RESPONSE | sed -E 's/HTTP_STATUS\:[0-9]{3}$//')
38-
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -E 's/.*HTTP_STATUS:([0-9]{3})$/\1/')
37+
HTTP_BODY=$(echo "${HTTP_RESPONSE}" | sed -E 's/HTTP_STATUS\:[0-9]{3}$//')
38+
HTTP_STATUS=$(echo "${HTTP_RESPONSE}" | tr -d '\n' | sed -E 's/.*HTTP_STATUS:([0-9]{3})$/\1/')
3939

4040
# Fail pipeline and print errors if API doesn't return an OK status.
41-
if [ $HTTP_STATUS -eq "200" ]; then
41+
if [ "${HTTP_STATUS}" -eq "200" ]; then
4242
echo "Successfully purged!"
4343
exit 0
4444
else
45-
echo "Purge failed. API response was:"
46-
echo $HTTP_BODY
45+
echo "Purge failed. API response was: "
46+
echo "${HTTP_BODY}"
4747
exit 1
4848
fi

0 commit comments

Comments
 (0)