Skip to content

Commit fdc0a63

Browse files
committed
fix: use direct curl for cloudflare purge with better error handling
1 parent 4e75bae commit fdc0a63

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

.github/workflows/test_cloudflare_purge.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,38 @@ jobs:
1919
echo "Host: polygon-docs.polygon.technology"
2020
2121
- name: Cloudflare Cache Purge
22-
uses: nathanvaughn/actions-cloudflare-purge@master
23-
with:
24-
cf_zone: ${{ secrets.CLOUDFLARE_ZONE }}
25-
cf_auth: ${{ secrets.CLOUDFLARE_AUTH_KEY }}
26-
hosts: polygon-docs.polygon.technology
22+
run: |
23+
ZONE_ID="${{ secrets.CLOUDFLARE_ZONE }}"
24+
AUTH_TOKEN="${{ secrets.CLOUDFLARE_AUTH_KEY }}"
25+
HOST="polygon-docs.polygon.technology"
26+
27+
echo "Purging cache for host: $HOST"
28+
29+
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
30+
"https://api.cloudflare.com/client/v4/zones/${ZONE_ID}/purge_cache" \
31+
-H "Authorization: Bearer ${AUTH_TOKEN}" \
32+
-H "Content-Type: application/json" \
33+
--data "{\"hosts\":[\"${HOST}\"]}")
34+
35+
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
36+
BODY=$(echo "$RESPONSE" | sed '$d')
37+
38+
echo "HTTP Status Code: $HTTP_CODE"
39+
echo "Response:"
40+
echo "$BODY" | jq '.' || echo "$BODY"
41+
42+
if [ "$HTTP_CODE" -eq 200 ]; then
43+
SUCCESS=$(echo "$BODY" | jq -r '.success' 2>/dev/null || echo "false")
44+
if [ "$SUCCESS" = "true" ]; then
45+
echo "✅ Cache purge successful!"
46+
exit 0
47+
else
48+
echo "❌ Cache purge failed - success field is false"
49+
echo "$BODY" | jq -r '.errors[]? | "Error \(.code): \(.message)"' 2>/dev/null || echo "$BODY"
50+
exit 1
51+
fi
52+
else
53+
echo "❌ HTTP request failed with status $HTTP_CODE"
54+
exit 1
55+
fi
2756

0 commit comments

Comments
 (0)