Skip to content

Latest commit

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Cloudflare Pages Deploy

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.

Usage

- name: Deploy to Cloudflare Pagesuses: https://github.com/Systemscape/cf-pages-deploy@v1with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}project-name: my-sitedirectory: public

On pull requests, the action automatically comments (or updates) a preview URL on the PR:

Cloudflare Pages Preview

Preview URLhttps://my-branch.my-site.pages.dev
Commitabc1234
Environmentpreview

Inputs

InputRequiredDefaultDescription
cloudflare-api-tokenYesCloudflare API token with Pages permissions
cloudflare-account-idYesCloudflare account ID
project-nameYesCloudflare Pages project name
directoryYesDirectory of static assets to deploy
forgejo-tokenNo${{ github.token }}Forgejo API token for PR comments
comment-markerNo<!-- cf-pages-deploy -->HTML comment marker for idempotent comment updates

Caching wrangler

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@v4with:
path: ~/.npmkey: ${{ runner.os }}-npm-wrangler

With a warm cache, the npm ci step takes a couple of seconds instead of downloading wrangler from the registry.

Outputs

OutputDescription
deployment-urlThe deployment URL (hash-based, e.g. https://abc123.my-site.pages.dev)
deployment-alias-urlBranch-specific alias URL (e.g. https://my-branch.my-site.pages.dev)
environmentproduction or preview

Full workflow example

name: Build and deployon:
push:
branches: [main]pull_request:
jobs:
deploy:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4
- uses: actions/cache@v4with:
path: ~/.npmkey: ${{ runner.os }}-npm-wrangler
- name: Builduses: https://github.com/shalzz/zola-deploy-action@v0.21.0env:
BUILD_ONLY: trueOUT_DIR: public
- name: Deploy to Cloudflare Pagesuses: https://github.com/Systemscape/cf-pages-deploy@v1with:
cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }}cloudflare-account-id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}project-name: my-sitedirectory: public

Setting up the Cloudflare API token

  1. Go to the Cloudflare dashboard API tokens page
  2. Create a token with the Cloudflare Pages: Edit permission
  3. Add the token as a secret named CLOUDFLARE_API_TOKEN in your Forgejo repository settings

How it works

  1. Deploy: Runs wrangler pages deploy with the correct --branch derived from the CI environment (PR source branch or push branch), avoiding the detached-HEAD alias URL issue common in CI
  2. 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

Requirements

The runner image must have curl, jq, and node/npm installed.

About

Cloudflare Pages Deploy Action that works with Forgejo

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors