Skip to content

cssnr/cloudflare-purge-cache-action

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

GitHub Tag Major GitHub Tag Minor GitHub Release Version Image Size Image Latest YAML Version Workflow Release Workflow Test Workflow Lint GitHub Last Commit Codeberg Last Commit GitHub Contributors GitHub Repo Size GitHub Top Language GitHub Forks GitHub Discussions GitHub Repo Stars GitHub Org Stars Discord Ko-fi

Cloudflare Purge Cache Action

Purge Cloudflare cache for a zone or list of zones with optional filters including files, prefixes, tags, and hosts.

Loaded with Options including job summary, fail mode, dry run, custom files prefix and Outputs.

- name: 'Purge Cache Action'
  uses: cssnr/cloudflare-purge-cache-action@v2
  with:
    token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    zones: cssnr.com,example.com

For more details see: action.yaml and src/main.py.

Inputs

Input Default Short Description of the Input Value
token Required Cloudflare API Token ⤵️
zones Required Zone Names to Purge ⤵️
files - Files to Purge ⤵️
prefix - Prefix Prepended to files ⤵️
tags - Tags to Purge (Enterprise) ⤵️
hosts - Hosts to Purge (Enterprise) ⤵️
prefixes - Prefixes to Purge (Enterprise) ⤵️
fail all Fail Mode: [all, any, none] ⤵️
dry_run false Run Without Purging ⤵️
summary true Add Summary to Job ⤵️

token

You need a Cloudflare Token with the permission Zone.Cache Purge.

zones

CSV or Newline Delimited list of zone names to purge.

View CSV and Newline Delimited Examples

CSV - Comma Seperated Value:

zones: cssnr.com,example.com

Newline Delimited:

zones: |
  cssnr.com
  example.com

files

CSV or Newline Delimited list of files to purge. This is limited to 30 files on the free plan and 500 for enterprise. For more information view docs for purge by file.

prefix

If provided, the prefix will be prepended to all the files. Useful for generating full links from file paths.

tags/hosts/prefixes

Enterprise Only. CSV or Newline Delimited list of tags, hosts or prefixes to purge. For more information view docs for purge by tags, hostname, prefix.

fail

When purging multiple domains, set when the action should fail. Options are all, any or none. Default is all.

dry_run

With this enabled it will only output the results and not purge any cache.

summary

Write a Summary for the job. To disable this set to false.

👀 View Example Job Summary

⚠️ Only 1/2 Zones Purged!

⚠️ Dry Run! Remove or disable dry_run to purge cache.

Purge Results
🚽Zone
cssnr.com
example.com
Inputs
zones: cssnr.com,example.com
files:
prefix:
tags:
hosts:
prefixes:
fail: all
summary: true
dry_run: true

 

View the Examples to see more...

Outputs

Output Output Description
success Successful Zones, CSV
failed Failed Zones, CSV
- name: 'Purge Cache Action'
  id: purge
  uses: cssnr/cloudflare-purge-cache-action@v2
  with:
    token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    zones: cssnr.com,example.com

- name: 'Echo Output'
  run: |
    echo "success: '${{ steps.purge.outputs.success }}'"
    echo "failed: '${{ steps.purge.outputs.failed }}'"

Examples

With minimal inputs, this will purge everything:

- name: 'Purge Cache Action'
  uses: cssnr/cloudflare-purge-cache-action@v2
  with:
    token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    zones: cssnr.com,example.com

To limit what is purged, specify either files, tags, hosts, or prefixes.

With all inputs:

- name: 'Purge Cache Action'
  uses: cssnr/cloudflare-purge-cache-action@v2
  with:
    token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    zones: cssnr.com
    files: |
      favicon.ico
      static/logo.png
    prefix: 'https://cssnr.com/'
    tags: prod, dev
    hosts: example.com, dev.example.com
    prefixes: |
      example.com
      example.com/foo
    fail: all
    summary: true
    dry_run: false

Workflow Example.

name: 'Cloudflare Purge Cache'

on:
  push:

jobs:
  test:
    name: 'Test'
    runs-on: ubuntu-latest
    timeout-minutes: 5

    steps:
      - name: 'Purge Cache Action'
        uses: cssnr/cloudflare-purge-cache-action@v2
        with:
          token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
          zones: |
            cssnr.com
            example.com

For more examples, you can check out other projects using this action:
https://github.com/cssnr/cloudflare-purge-cache-action/network/dependents

Tags

The following rolling tags are maintained.

Version Tag Rolling Bugs Feat. Name Target Example
GitHub Tag Major Major vN.x.x vN
GitHub Tag Minor Minor vN.N.x vN.N
GitHub Release Micro vN.N.N vN.N.N

You can view the release notes for each version on the releases page.

The Major tag is recommended. It is the most up-to-date and always backwards compatible. Breaking changes would result in a Major version bump. At a minimum you should use a Minor tag.

Support

For general help or to request a feature, see:

If you are experiencing an issue/bug or getting unexpected results, you can:

For more information, see the CSSNR SUPPORT.md.

Contributing

Please consider making a donation to support the development of this project and additional open source projects.

Ko-fi

If you would like to submit a PR, please review the CONTRIBUTING.md.

Additionally, you can support other GitHub Actions I have published:

❔ Unpublished Actions

These actions are not published on the Marketplace, but may be useful.


📝 Template Actions

These are basic action templates that I use for creating new actions.

Note: The docker-test-action builds, runs and pushes images to GitHub Container Registry.


For a full list of current projects visit: https://cssnr.github.io/

About

Cloudflare Purge Cache Action

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Packages