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 GHCR Size Release WF Test WF Lint WF GitHub Last Commit Codeberg Last Commit GitHub Top Language GitHub Org Stars Discord

Cloudflare Purge Cache Action

Purge Cloudflare cache for a zone or list of zones with optional file/url filter.

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

Inputs

input required default description
token Yes - Cloudflare API Token
zones Yes - Zone Names to Purge *
files - - Files to Purge *
prefix - - Prefix Prepended to Files *
tags - - Tags to Purge (Enterprise only) *
hosts - - Hosts to Purge (Enterprise only) *
prefixes - - Prefixes to Purge (Enterprise only) *
fail - all Fail Mode: [all, any, none]
summary - true Add Summary to Job *
dry_run - false Run Without Purging

zones - CSV or Newline Delimited list of zone names to purge.

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.

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

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

Outputs

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

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

Tags

The following rolling tags are maintained.

Tag Example Target Bugs Feat. Description
GitHub Tag Major vN vN.x.x Includes new features but is always backwards compatible.
GitHub Tag Minor vN.N vN.N.x Only receives bug fixes. This is the most stable tag.
GitHub Release vN.N.N vN.N.N Not a rolling tag. Not recommended.

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

Support

For general help or to request a feature, see:

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

Contributing

Currently, the best way to contribute to this project is to star this project on GitHub.

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

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

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