Skip to content

Instantly share code, notes, and snippets.

@jonlong
Last active May 16, 2022 05:30
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jonlong/240eb9a7501f1ae4c09f to your computer and use it in GitHub Desktop.
Save jonlong/240eb9a7501f1ae4c09f to your computer and use it in GitHub Desktop.
Purge CloudFlare when deploying GitHub Pages: post-receive hook
#!/bin/sh
#
# Purge the CloudFlare cache after pushing an update to GitHub Pages
#
# To use, rename this file to "post-receive" and drop it into the `.git/hooks/` directory in your project's root.
# Change the $branch value based on the type of page you're deploying.
# Use "master" for Organization Pages, and "gh-pages" for Project Pages.
#
# Find your CloudFlare API token here: https://www.cloudflare.com/a/account/my-account
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
curl https://www.cloudflare.com/api_json.html \
-d 'a=fpurge_ts' \
-d 'tkn=<insert API token>' \
-d 'email=<insert email>' \
-d 'z=<insert domain>' \
-d 'v=1' &
exit 0
fi
done
Copy link

ghost commented Jan 29, 2018

Which API token would I use? I'm assuming my global api token.

@stevebaros
Copy link

https://www.cloudflare.com/api_json.html

This API has been deprecated in favor of API v4, available at https://api.cloudflare.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment