Skip to content

moojing/cf-preview-bot

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Preview URL Comment Bot

A GitHub Action that posts a comment on a Pull Request with Cloudflare Pages deployment details.


Features

  • 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.

Usage

Step 1: Add to Your Workflow

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 }}

⚙️ Inputs

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.

📝 Example PR Comment Format

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) |

🚀 Advanced Configuration

Restrict to Specific Branch Patterns

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/.


🔐 Permissions

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.


📜 License

MIT © 2025 Moojing

About

A github action to leave your cloudfare preview url in your pull request

Resources

Stars

Watchers

Forks

Packages

No packages published