This GitHub Action purges Cloudflare cache via Cloudflare API. It supports:
- full purge (
purge_everything) - targeted purge by
files,tags,hosts,prefixes
- Pure Bash implementation with minimal dependencies (
bash, pluscurlandjqfor the API call) - Fast startup: no
npm/pipinstall step during workflow execution - Lower supply-chain and maintenance overhead: no runtime pinning, lockfiles, or dependency CVEs
- Easier security audit: all logic lives in a small, readable script
- Covered by automated tests (
./tests/run) and CI - Works on
ubuntu-slim, which can help reduce runner costs: https://docs.github.com/en/actions/reference/runners/github-hosted-runners - Can be used both as a GitHub Action and as a standalone script
- Released under the MIT License: a short and simple permissive license
- Documented security policy: SECURITY.md
| Input | Description | Required | Default |
|---|---|---|---|
CLOUDFLARE_API_TOKEN |
Cloudflare API token with cache purge permissions for the zone | Yes | - |
CLOUDFLARE_ZONE_ID |
Cloudflare Zone ID | Yes | - |
files |
URLs to purge (space-, comma- or newline-separated) | No | "" |
tags |
Cache tags to purge (space-, comma- or newline-separated) | No | "" |
hosts |
Hostnames to purge (space-, comma- or newline-separated) | No | "" |
prefixes |
URL prefixes to purge (space-, comma- or newline-separated) | No | "" |
dry_run |
If true, print planned request and skip API call |
No | "false" |
verbose |
If true, print detailed logs |
No | "false" |
If files, tags, hosts and prefixes are all empty, the action sends:
{"purge_everything": true}.
Required permissions for a User API Token or Account API tokens if you prefer credentials that are not associated with users:
Cache Purge:Purge
Documentation:
To copy your Zone ID in the Cloudflare dashboard:
- Go to Account home and locate your account
- Open your account Overview page and find the API section near the bottom
- Under Zone ID, click Click to copy
Reference:
Purge everything:
name: Purge Cloudflare cache
on:
workflow_dispatch:
jobs:
purge-cache:
runs-on: ubuntu-latest
steps:
- uses: octivi/cloudflare-cache-purge@v1
with:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ZONE_ID: ${{ vars.CLOUDFLARE_ZONE_ID }}Targeted purge:
- uses: octivi/cloudflare-cache-purge@v1
with:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ZONE_ID: ${{ vars.CLOUDFLARE_ZONE_ID }}
files: "https://example.com/ https://example.com/app.js"
tags: "release-2026-02"
hosts: "example.com"
prefixes: "example.com/static"Run locally from this repository:
CLOUDFLARE_API_TOKEN="..." \
CLOUDFLARE_ZONE_ID="..." \
./cloudflare-cache-purge \
--files https://example.com/ https://example.com/app.js \
--tags release-2026-02 \
--hosts example.com \
--prefixes example.com/staticOptional execution modes:
./cloudflare-cache-purge --dry-run --verboseYou can also set values via env vars: FILES, TAGS, HOSTS, PREFIXES, DRY_RUN, VERBOSE.
List values can be space-separated, comma-separated, newline-separated, or mixed.
DRY_RUN and VERBOSE are presence flags: any non-empty value enables the mode, leaving the variable unset disables it.
When run inside GitHub Actions, logs are grouped, warnings/errors are emitted as workflow annotations, and a short result is written to GITHUB_STEP_SUMMARY.
Run tests:
./tests/runBefore using this action, read Cloudflare docs, especially limits and purge behavior:
- Purge cache overview: https://developers.cloudflare.com/cache/how-to/purge-cache/
- Purge cache API: https://developers.cloudflare.com/api/resources/cache/methods/purge/
bashcurljq
If you run into issues, open a GitHub issue in this repository and include a minimal reproduction (workflow snippet + inputs).
If you are interested in other GitHub Actions we build, see:
octivi/update-copyright-year- Updates the copyright year in file headers across your repositoryoctivi/update-securitytxt-expires- Updates theExpiresfield insecurity.txtfiles to a future date so published security contact metadata stays currentoctivi/release-notes-from-changelog- Extracts Release Notes from Changelog
Maintained by the Octivi DevOps team. Contributions are welcome via pull requests.
Built with Octivi Bash Boilerplate.
This project is not affiliated with, endorsed by, or sponsored by Cloudflare. Cloudflare and related marks are trademarks or registered trademarks of Cloudflare, Inc.