A GitHub Action that posts a comment on a Pull Request with Cloudflare Pages deployment details.
- Automatically comments the Preview URL and Branch Preview URL on a PR after deployment.
- Supports custom branch patterns to restrict when the action runs.
- Prevents duplicate comments by updating existing ones.
- Works seamlessly with Cloudflare Pages deployments.
Include the following in your GitHub Actions workflow:
name: Staging Deploy
on:
pull_request:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
pull-requests: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Deploy to Cloudflare Pages
id: deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy dist --project-name=${{ vars.PROJECT_NAME }} --branch=${{ github.head_ref }}
wranglerVersion: '3'
- name: Comment Preview URL on PR
uses: moojing/cf-preview-bot@v1
with:
deployment_url: ${{ steps.deploy.outputs.deployment-url }}
branch_preview_url: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
Name | Required | Description |
---|---|---|
deployment_url |
✅ Yes | The deployment URL generated by Cloudflare Pages |
branch_preview_url |
✅ Yes | The branch alias URL generated by Cloudflare Pages |
allowed_branch_patterns |
❌ No | A comma-separated list of branch name patterns (e.g., feat/,fix/,hotfix/ ). If not set, all branches are allowed. |
After deployment, the action posts a comment like this:
## 🚀 Deploying feat/enhance-ci-process with ⚡ Cloudflare Pages
| **Latest commit:** | `506cf7e8070bb6fdd66952eadae66692b4a99710` |
|--------------------|----------------------|
| **Status:** | ✅ Deploy successful |
| **Preview URL:** | [https://your-preview-url.pages.dev](https://your-preview-url.pages.dev) |
| **Branch Preview URL:** | [https://feat-enhance-ci.pages.dev](https://feat-enhance-ci.pages.dev) |
If you only want to trigger the comment for specific branch prefixes, pass allowed_branch_patterns
:
- name: Comment Preview URL on PR
uses: moojing/cf-preview-bot@v1
with:
deployment_url: ${{ steps.deploy.outputs.deployment-url }}
branch_preview_url: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
allowed_branch_patterns: "feat/,fix/,hotfix/"
This ensures that the action only runs when the PR head branch starts with feat/
, fix/
, or hotfix/
.
This action requires the following permissions:
contents: read
→ To access repository files.pull-requests: write
→ To create/update PR comments.
Make sure your GitHub Token has the necessary scopes.
MIT © 2025 Moojing