Skip to content

Instantly share code, notes, and snippets.

@lucleray
Last active January 25, 2018 15:14
Show Gist options
  • Save lucleray/94fcdd2b0b5222600441eba4b989ef5e to your computer and use it in GitHub Desktop.
Save lucleray/94fcdd2b0b5222600441eba4b989ef5e to your computer and use it in GitHub Desktop.
Purge CloudFlare when deploying GitHub Pages: post-receive hook
#!/bin/sh
#
# 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 Zone Id and get your API key in the Cloudflare interface, under the "Overview" tab
#
# Inspired by jonlong/cloudflare-purge-post-receive : https://gist.github.com/jonlong/240eb9a7501f1ae4c09f
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/<insert Zone ID here>/purge_cache" \
-H "X-Auth-Email: <insert Email here>" \
-H "X-Auth-Key: <insert API key here>" \
-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