Skip to content

Cyb3r-Jak3/action-cloudflare-cache

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 Cleaner

A Github Action that clears cache from Cloudflare. Useful for after deployment as new code will be pulled from your server rather than served from Cloudflare.

Configuration

All senstive information like zones and tokens should be stored with encrypted secrets

Zone ID

Your zone ID will be on the bottom right of the overview page.

Image of blurred out Zone ID

Setting up Authentication

There are two ways that you can provide authentication for Cloudflare, Global Token or API Token. It is strongly recommended to use API Token over Global API Key. To get a walk through guide of getting set up with Authentication then check out the wiki.

API Token permissons.

The only permissions required for an API Token is Zone -> Cache Purge -> Purge. You can set this for all zones but best pratice would be restricting to the zone in use. Right now there is no method for running with multiple zones.

Example workflow

name: Deploy Site
on: push

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:

    # Put steps here to build your site, check, and deploy your site.

    - name: Clear Cloudflare cache
      uses: Cyb3r-Jak3/action-cloudflare-cache@<Latest Release>
      with:
        # Zone is required by both methods
        zone: ${{ secrets.CLOUDFLARE_ZONE }}

        # Using API Token
        api_token: ${{ secrets.CLOUDFLARE_TOKEN }}

        # Using Global Token
        email: ${{ secrets.CLOUDFLARE_EMAIL }}
        global_token: ${{ secrets.CLOUDFLARE_KEY }}

Keep up-to-date with GitHub Dependabot

Since Dependabot has native GitHub Actions support, to enable it on your GitHub repo all you need to do is add the .github/dependabot.yml file:

version: 2
updates:
  # Maintain dependencies for GitHub Actions
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "daily"