Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save alexdiliberto/4dd6572197d09dc2e664fe7c958c8982 to your computer and use it in GitHub Desktop.

Select an option

Save alexdiliberto/4dd6572197d09dc2e664fe7c958c8982 to your computer and use it in GitHub Desktop.
CloudFlare "Purge All Files" githook after deploying to GitHub Pages (post-receive)
#!/bin/sh
#
# Purge the CloudFlare cache after pushing an update to a Github Repo branch
#
# 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.
# EX: Use "master" for Organization Pages, and "gh-pages" for Project Pages.
#
# Find your CloudFlare API token here: https://www.cloudflare.com/a/profile
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "master" == "$branch" ]; then
curl -X DELETE "https://api.cloudflare.com/client/v4/zones/:identifier/purge_cache" \
-H "X-Auth-Email: <insert email>" \
-H "X-Auth-Key: <insert API token>" \
-H "Content-Type: application/json" \
--data '{"purge_everything":true}'
exit 0
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment