Based on this Action from jakejarvis which seems unmaintained, and merged this PR from chabad360 to work with the new YAML syntax.
This simple action calls the Cloudflare API to purge the cache of your website, which can be a helpful last step after deploying a new version.
All sensitive variables should be set as encrypted secrets in the action's configuration.
| Key | Value | Suggested Type | Required |
|---|---|---|---|
cloudflareZone |
The Zone ID of your domain, which can be found in the right sidebar of your domain's overview page on the Cloudflare dashboard. For example, xyz321xyz321xyz321xyz321xyz321xy. |
secret |
Yes |
cloudflareApiKey |
Your Cloudflare API key, which can be generated using these instructions. For example, abc123abc123abc123abc123abc123abc123abc123abc. |
secret |
Yes |
purgeURLs |
Optional. An array of fully qualified URLs to purge. For example: '["https://example.com/style.css", "https://example.com/favicon.ico"]'. If unset, the action will purge everything (which is suggested). |
option |
No |
API Tokens are a feature that allows you to restrict the scope of this action to only purging the cache of zones you specify. In other words, this is much safer than allowing this action complete control of your entire Cloudflare account.
Creating a token is easy; here's an example of what you should enter on this page to create a token for purging the cache of a single domain on your account:
Place in a .yml file such as this one in your .github/workflows folder. Refer to the documentation on workflow YAML syntax here.
name: Deploy my website
on: push
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# Put other steps here if you'd like, i.e. to build your site, deploy it to a service, etc.
- name: Purge cache
uses: Jonakemon/purge-cache-cloudflare-zone
with:
cloudflareZone: ${{ secrets.CLOUDFLARE_ZONE }}
cloudflareApiKey: ${{ secrets.CLOUDFLARE_API_KEY }}To purge only specific files, you can pass an array of fully qualified URLs via a fourth environment variable named PURGE_URLS. Unfortunately, Cloudflare doesn't support wildcard on all plans. In order to purge a folder, you'd need to list every file in that folder. It's probably safer to leave this out and purge everything, but in case you want really to, the syntax is as follows:
purgeURLs: '["https://example.com/style.css", "https://example.com/favicon.ico"]'This project is distributed under the MIT license. It is based on a similar repository from jakejarvis.
