Skip to content
Merged
86 changes: 77 additions & 9 deletions .github/workflows/ci-website-preview.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "CI - Website: Run Checks and Deploy Preview"
name: "CI - Website: Validate and Deploy Preview"

on:
workflow_call:
Expand All @@ -17,8 +17,15 @@ env:
CLOUDFLARE_WORKERS_DOMAIN: billy-daly.workers.dev

jobs:
build-and-deploy-preview:
# Install, build, and run checks/tests/audit. All post-build steps are
# sequential but each runs regardless of the previous step's pass/fail so
# lint, test, and audit failures all surface in a single CI run.
validate:
runs-on: ubuntu-latest
outputs:
# Read from the upload step (not the build step) so deploy-preview only
# tries to download when the artifact actually exists.
artifact_ready: ${{ steps.upload-build.outcome == 'success' }}

steps:
- name: Checkout Code
Expand All @@ -38,29 +45,91 @@ jobs:
run: pnpm install --frozen-lockfile

- name: Build site
# This needs to run before running checks because it generates the schema docs and changelogs.
id: build
run: pnpm run build

- name: Upload build output
# Path-structure invariant: every entry must stay under `website/` so
# upload-artifact strips that common prefix and the deploy-preview
# download (path: website) restores them at website/dist, etc. Adding
# a path outside website/ shrinks the prefix and silently shifts
# download locations.
id: upload-build
if: always() && steps.build.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: website-build
path: |
website/dist
website/tsp-output
website/.extension-schemas
website/cache
website/public/schemas/yaml
website/public/openapi
retention-days: 1
if-no-files-found: error

- name: Run all checks
# linting, formatting, spelling, astro checking
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: pnpm run checks

- name: Run tests
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: pnpm run test

- name: Audit dependencies
# Calls the npm bulk advisory endpoint directly as a workaround for
# pnpm audit 410 errors (pnpm/pnpm#11265). Remove this script and
# revert to `pnpm run audit:high` once pnpm ships native support.
if: ${{ !cancelled() && steps.build.outcome == 'success' }}
run: node ${GITHUB_WORKSPACE}/.github/scripts/audit-deps.js --level high

# Preview deployment (only on PRs)
# Deploy the built artifact to a per-PR Cloudflare Worker. Decoupled from
# the test/check/audit outcome (via artifact_ready) so previews stay
# available for reviewing UI changes on PRs that have unrelated failures.
deploy-preview:
runs-on: ubuntu-latest
needs: validate
# !cancelled() (not always()) so a user-cancelled run skips the deploy.
# Dependabot and workflow_call skipped: no PR number to name the worker.
if: |
!cancelled()
&& needs.validate.outputs.artifact_ready == 'true'
&& github.event_name == 'pull_request'
&& github.actor != 'dependabot[bot]'

steps:
- name: Checkout Code
uses: actions/checkout@v6

- name: Setup pnpm
uses: pnpm/action-setup@v6

- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: "22"
cache: "pnpm"

- name: Download build output
uses: actions/download-artifact@v4
with:
name: website-build
path: website

- name: Deploy PR preview
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
run: pnpm wrangler deploy --name cg-pr-${{ github.event.pull_request.number }}
# pnpm dlx fetches wrangler on demand — avoids a full workspace install
# just to get wrangler on PATH. Pin to major @4 to match the devDep in
# website/package.json and avoid silent v5+ drift.
# --allow-build list: wrangler pulls in workerd/esbuild/sharp, each of
# which wants to run a postinstall build; pnpm 10's default rejects
# those unless explicitly allowed.
run: pnpm --allow-build=workerd --allow-build=esbuild --allow-build=sharp dlx wrangler@4 deploy --name cg-pr-${{ github.event.pull_request.number }}
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}

- name: Find existing comment
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
id: find-comment
uses: peter-evans/find-comment@v4
with:
Expand All @@ -69,7 +138,6 @@ jobs:
body-includes: Website Preview Deployed

- name: Post preview link comment
if: github.event_name == 'pull_request' && github.actor != 'dependabot[bot]'
uses: peter-evans/create-or-update-comment@v5
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
Expand Down
Loading