Skip to content

Deploy to Cloudflare Pages #32

Deploy to Cloudflare Pages

Deploy to Cloudflare Pages #32

Workflow file for this run

name: Deploy to Cloudflare Pages
on:
push:
branches: [master]
workflow_run:
workflows: ["PR Build"]
types: [completed]
permissions:
actions: read
contents: read
deployments: write
pull-requests: write
jobs:
deploy:
if: |
github.event_name == 'push' ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'pull_request')
runs-on: ubuntu-latest
steps:
- name: Checkout repository (push deployments)
if: github.event_name == 'push'
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Set up Node.js (push deployments)
if: github.event_name == 'push'
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies (push deployments)
if: github.event_name == 'push'
run: npm ci
- name: Build docs (push deployments)
if: github.event_name == 'push'
run: npm run build
- name: Download build artifact (PR previews)
if: github.event_name == 'workflow_run'
uses: actions/download-artifact@v4
with:
name: docusaurus-build
path: build
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- 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 build --project-name=redot-docs-site --branch=${{ github.event_name == 'workflow_run' && format('pr-{0}', github.event.workflow_run.pull_requests[0].number) || github.ref_name }}
- name: Comment PR with preview URL
if: github.event_name == 'workflow_run' && github.event.workflow_run.pull_requests[0].number
uses: actions/github-script@v7
env:
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
with:
script: |
const prNumber = context.payload.workflow_run.pull_requests[0]?.number;
const deployUrl = process.env.DEPLOY_URL;
if (prNumber && deployUrl) {
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 **Preview deployment ready!**\n\n🔗 ${deployUrl}`
});
}