Skip to content

Cloudflare Cache Clear #6

Cloudflare Cache Clear

Cloudflare Cache Clear #6

name: Cloudflare Cache Clear
on:
workflow_run:
workflows: ["pages-build-deployment"]
types:
- completed
jobs:
clear-cache:
runs-on: ubuntu-latest
steps:
- name: Clear Cache
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
run: |
DOMAIN="database-answers.com"
ZONE_ID=$(curl -s -X GET "https://api.cloudflare.com/client/v4/zones?name=$DOMAIN" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" | jq -r .result[0].id)
curl -s -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}' | grep "success" | awk -F": " '{gsub(/,/, "", $2); print "success:", $2}'