name: Docs preview
on:
pull_request:
paths:
- "docs-site/**"
- "docs/cli-reference.md"
- "docs/env-reference.md"
- ".github/workflows/docs-preview.yaml"
permissions:
contents: read
pull-requests: write
concurrency:
group: docs-preview-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
preview:
name: Build & preview
runs-on: ubuntu-latest
env:
CF_CONFIGURED: ${{ secrets.CLOUDFLARE_API_TOKEN != '' && secrets.CLOUDFLARE_ACCOUNT_ID != '' }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e with:
node-version: "22"
cache: npm
cache-dependency-path: docs-site/package-lock.json
- name: Install dependencies
working-directory: docs-site
run: npm ci
- name: Build site
working-directory: docs-site
run: npm run build
- name: Deploy preview to Cloudflare Pages
id: deploy
if: ${{ env.CF_CONFIGURED == 'true' && github.event.pull_request.head.repo.full_name == github.repository }}
uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: docs-site
command: pages deploy dist --project-name=murk-docs --branch=pr-${{ github.event.pull_request.number }} --commit-dirty=true
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Comment preview URL
if: ${{ steps.deploy.outcome == 'success' }}
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
DEPLOY_URL: ${{ steps.deploy.outputs.deployment-url }}
ALIAS_URL: ${{ steps.deploy.outputs.pages-deployment-alias-url }}
run: |
set -euo pipefail
{
echo "Docs preview for this PR:"
echo
echo "- Latest build: ${DEPLOY_URL}"
if [ -n "${ALIAS_URL}" ]; then
echo "- Stable alias: ${ALIAS_URL}"
fi
echo
echo "_Updates on each push to this PR._"
} > preview-comment.md
gh pr comment "$PR" --body-file preview-comment.md --edit-last --create-if-none