Skip to content

NathanVaughn/actions-cloudflare-purge

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Cloudflare Cache Purge Action

This unofficial Action uses Cloudflare's API to purge their cache of your site. A Python 3.9+ interpreter is required (installed by default on GitHub-hosted runners).

As of April 1st, 2025, all purge methods are now available for all customers.

Inputs

You can mix and match the various inputs however you want (other than the zone and auth key). If you don't provide files or tags or hosts or prefixes, then all files will be purged.

cf_zone or CLOUDFLARE_ZONE environment variable

The zone ID of your Cloudflare site. Example:

023e105f4ecef8ad9ca31a8372d0c353

cf_auth or CLOUDFLARE_AUTH_KEY environment variable

The Cloudflare API key you've generated for your zone. Example:

c2547eb745079dac9320b638f5e225cf483cc5cfdda41

files (optional)

A space separated list of URLs to purge. Example:

files: https://nathanv.me/assets/images/profile.png https://nathanv.me/assets/images/favicons/apple-touch-icon.png

URL and header pairs are not supported in this Action.

The key urls is also accepted for backwards compatibility.

tags (optional)

A space separated list of tags to purge. Example:

tags: some-tag another-tag

hosts (optional)

A space separated list of hosts to purge. Example:

hosts: nathanv.me blog.nathanv.me

prefixes (optional)

A space separated list of prefixes to purge. Example:

prefixes: nathanv.me/assets/ blog.nathanv.me/assets

python (optional)

The path to the Python interpreter to use, in case you are using a self-hosted runner. Defaults to python. Must be Python 3.9 or higher.

Example:

python: /usr/bin/python3.10

Outputs

None

Example Usages

- name: Purge cache
  uses: nathanvaughn/[email protected]
  # preferred
  with:
      cf_zone: ${{ secrets.CLOUDFLARE_ZONE }}
      cf_auth: ${{ secrets.CLOUDFLARE_AUTH_KEY }}
- name: Purge cache
  uses: nathanvaughn/[email protected]
  # legacy
  env:
      CLOUDFLARE_ZONE: ${{ secrets.CLOUDFLARE_ZONE }}
      CLOUDFLARE_AUTH_KEY: ${{ secrets.CLOUDFLARE_AUTH_KEY }}
- name: Purge cache
  uses: nathanvaughn/[email protected]
  with:
      cf_zone: ${{ secrets.CLOUDFLARE_ZONE }}
      cf_auth: ${{ secrets.CLOUDFLARE_AUTH_KEY }}
      files: |
         https://nathanv.me/assets/images/profile.png
         https://nathanv.me/assets/images/favicons/apple-touch-icon.png
      tags: |
         some-tag
         another-tag
      hosts: |
         nathanv.me
         blog.nathanv.me
      prefixes: |
         nathanv.me/assets/
         blog.nathanv.me/assets

Getting Cloudflare Info

  1. First, go to your user or account API tokens page in your Cloudflare dashboard.

Account API tokens

  1. Click "Create Token", and scroll down to the bottom for "Create Custom Token". Click "Get started".

Create custom token

  1. Fill out the form. Make sure to give the permission of "Zone" -> "Cache Purge" -> "Purge". Either select a specific zone, or all zones in the account.

Custom token creation form

  1. Click "Continue to summary", then "Create Token".

  2. Copy the value of the token.

Copy token page

  1. To find the zone ID for your site, go to your dashboard for the zone, and look on the right-hand panel.

Zone ID location

  1. Follow GitHub's documentation to add these values to your repository's secrets. It is under the "Settings" tab, then "Secrets and variables" and "Actions".

Repository secrets

About

A GitHub Action to purge Cloudflare's cache of your site

Topics

Resources

License

Stars

Watchers

Forks

Contributors 5

Languages