Skip to content

mlopstemplates/purge-cache-cloudflare-zone

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub Action to Purge Cloudflare Cache 🗑️

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.

Usage

All sensitive variables should be set as encrypted secrets in the action's configuration.

Configuration Variables

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

Creating a restricted API token on Cloudflare

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:

Creating an API Token for purging

workflow.yml Example

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 }}

Purging specific files

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"]'

License

This project is distributed under the MIT license. It is based on a similar repository from jakejarvis.

About

A simple action to purge Cloudflare's cache for a single zone/domain.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors