Composite action for Forgejo that deploys to Cloudflare Pages and posts a preview URL comment on pull requests — replicating the GitHub-native Cloudflare Pages integration.
- name: Deploy to Cloudflare Pages
uses: https://github.com/Systemscape/cf-pages-deploy@v1
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
project-name: my-site
directory: publicOn pull requests, the action automatically comments (or updates) a preview URL on the PR:
Preview URL https://my-branch.my-site.pages.dev Commit abc1234Environment preview
| Input | Required | Default | Description |
|---|---|---|---|
cloudflare-api-token |
Yes | Cloudflare API token with Pages permissions | |
cloudflare-account-id |
Yes | Cloudflare account ID | |
project-name |
Yes | Cloudflare Pages project name | |
directory |
Yes | Directory of static assets to deploy | |
forgejo-token |
No | ${{ github.token }} |
Forgejo API token for PR comments |
comment-marker |
No | <!-- cf-pages-deploy --> |
HTML comment marker for idempotent comment updates |
The action installs wrangler via npm ci on each run. To avoid re-downloading it every time, cache the npm store before this action runs:
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-wranglerWith a warm cache, the npm ci step takes a couple of seconds instead of downloading wrangler from the registry.
| Output | Description |
|---|---|
deployment-url |
The deployment URL (hash-based, e.g. https://abc123.my-site.pages.dev) |
deployment-alias-url |
Branch-specific alias URL (e.g. https://my-branch.my-site.pages.dev) |
environment |
production or preview |
name: Build and deploy
on:
push:
branches: [main]
pull_request:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-wrangler
- name: Build
uses: https://github.com/shalzz/zola-deploy-action@v0.21.0
env:
BUILD_ONLY: true
OUT_DIR: public
- name: Deploy to Cloudflare Pages
uses: https://github.com/Systemscape/cf-pages-deploy@v1
with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}
cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
project-name: my-site
directory: public- Go to the Cloudflare dashboard API tokens page
- Create a token with the Cloudflare Pages: Edit permission
- Add the token as a secret named
CLOUDFLARE_API_TOKENin your Forgejo repository settings
- Deploy: Runs
wrangler pages deploywith the correct--branchderived from the CI environment (PR source branch or push branch), avoiding the detached-HEAD alias URL issue common in CI - Comment: On pull request events, creates or updates a comment on the PR with the preview URL using the Forgejo API. Uses an HTML comment marker to find and update existing comments instead of creating duplicates
The runner image must have curl, jq, and node/npm installed.