From 802879fc3e77ee3352432064492a5bc6ec79d930 Mon Sep 17 00:00:00 2001 From: m3ultra Date: Sat, 25 Jul 2026 23:27:50 +1000 Subject: [PATCH] deploy: parse the CF zone id with json, not a greedy sed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The purge silently did nothing. `sed -n 's/.*"id":"\([a-f0-9]\{32\}\)".*/\1/p'` looks right, but the zones response carries several 32-hex "id" fields (account, plan, ...) and the leading `.*` is greedy, so it returned the LAST one — a valid-looking id for the wrong object. The API then rejected the purge and the old grep-for-success check reported a bare "purge failed" with no reason. Parse with python3 (already a dep — serve.py) and surface the API's own error message when it fails. Verified end to end against the live zone: cf-cache-status HIT -> purge -> MISS -> HIT. Co-Authored-By: Claude Opus 5 --- deploy/deploy.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/deploy/deploy.sh b/deploy/deploy.sh index 47f7926..a0e8bd9 100755 --- a/deploy/deploy.sh +++ b/deploy/deploy.sh @@ -45,17 +45,28 @@ fi if [ -n "${CF_API_TOKEN:-}" ]; then echo "==> purging cloudflare" API=https://api.cloudflare.com/client/v4 + # Parse with python3 (already a dep — serve.py), NOT sed. The zone response + # carries several 32-hex "id" fields (account, plan, ...) and a greedy + # `.*"id":"..."` grabs the LAST one, which silently purges nothing. ZONE=$(curl -s -H "Authorization: Bearer $CF_API_TOKEN" \ - "$API/zones?name=monsterrobot.games" | sed -n 's/.*"id":"\([a-f0-9]\{32\}\)".*/\1/p' | head -1) + "$API/zones?name=monsterrobot.games" \ + | python3 -c 'import sys,json;r=json.load(sys.stdin).get("result") or [];print(r[0]["id"] if r else "")') if [ -n "$ZONE" ]; then files=$(cd "$SRC" && find index.html src -type f \ - | sed "s|^|\"https://monsterrobot.games/mollycool/|; s|$|\"|" | paste -sd, -) - ok=$(curl -s -X POST "$API/zones/$ZONE/purge_cache" \ + | python3 -c 'import sys,json;print(json.dumps({"files":["https://monsterrobot.games/mollycool/"+l.strip() for l in sys.stdin if l.strip()]}))') + resp=$(curl -s -X POST "$API/zones/$ZONE/purge_cache" \ -H "Authorization: Bearer $CF_API_TOKEN" -H 'Content-Type: application/json' \ - --data "{\"files\":[$files]}" | grep -o '"success":true' || true) - [ -n "$ok" ] && echo " purged" || echo " !! purge failed — hard-reload to be sure" + --data "$files") + echo "$resp" | python3 -c ' +import sys,json +d=json.load(sys.stdin) +if d.get("success"): print(" purged") +else: + print(" !! purge failed:", "; ".join(e.get("message","?") for e in d.get("errors") or [])) + print(" hard-reload to be sure")' else - echo " !! could not resolve zone id — hard-reload to be sure" + echo " !! could not resolve zone id — check the token has Zone:Read" + echo " hard-reload to be sure" fi else echo "==> NO CF_API_TOKEN — skipping purge."