To deploy your project to Cloudflare Pages using this GitHub Action, follow these steps:
- Generate an API Token: Create a token in the Cloudflare dashboard with the
Cloudflare Pages — Edit permission. - Add GitHub Secret: Add the token to your GitHub repository secrets as
CLOUDFLARE_API_TOKEN. - Configure Workflow: Create a
.github/workflows/publish.yml file. You must provide apiToken, accountId, projectName, and directory (the build output folder).
Example Workflow:
on: [push]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v3
# Run your build step here (e.g., npm run build)
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: YOUR_ACCOUNT_ID
projectName: YOUR_PROJECT_NAME
directory: YOUR_BUILD_OUTPUT_DIRECTORY
# Optional: Enable GitHub Deployments tracking
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Specify the branch (determines production vs preview)
branch: main
# Optional: Specify directory for monorepos
workingDirectory: my-site
# Optional: Specify Wrangler version
wranglerVersion: '3'
on: [push]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
name: Publish to Cloudflare Pages
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: YOUR_ACCOUNT_ID
projectName: YOUR_PROJECT_NAME
directory: YOUR_BUILD_OUTPUT_DIRECTORY
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: main
workingDirectory: my-site
wranglerVersion: '3'