Created
March 16, 2018 02:25
-
-
Save alexdiliberto/4dd6572197d09dc2e664fe7c958c8982 to your computer and use it in GitHub Desktop.
CloudFlare "Purge All Files" githook after deploying to GitHub Pages (post-receive)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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