Skip to content

ci: preview the docs site on every engine pull request push - #311

Merged
nickvigilante merged 6 commits into
mainfrom
vigilante/engine-pr-preview
Nov 16, 2026
Merged

nickvigilante merged 6 commits into
mainfrom
vigilante/engine-pr-preview

Conversation

@nickvigilante

@nickvigilante nickvigilante commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Merge order

Independent. It works today with the existing docs-preview environment. A later change could move previews off Vercel's Git integration on top of it. The earlier idea of a follow-up that drops the required reviewer for same-repository pull requests is withdrawn as designed: removing the reviewer would put VERCEL_TOKEN within reach of anyone who can push a branch, which is the Nov 14–15 incident path. A future same-repository auto-deploy needs a split where the token-holding workflow always comes from main (a workflow_run or pull_request_target-style design).

Summary

A docs-site change could only be previewed by dispatching docs-pr-preview.yml by hand with a coder/coder SHA. Vercel's Git builds cover only apps/router, and Vercel skips them when the router isn't affected, so a change to a shared package such as docs-theme (#310) never got a preview on its own.

With this PR, every push to a pull request from this repository that touches apps/docs, apps/offlinedocs, packages/**, the root manifests or the two preview workflows builds the docs site against coder/coder main and deploys it as a login-protected preview on coder-docs. The URL lands in a single comment on the pull request, updated on each push, and in a docs preview commit status in the Checks list. That status shows as pending while the build runs and the deploy waits for approval, and as failed if the build or deploy fails. A newer push cancels the run in flight. Pull requests from forks are skipped.

Design

engine-pr-preview.yml resolves coder/coder main with git ls-remote and calls the existing reusable docs-pr-preview.yml, so the build and deploy split is unchanged: the build job compiles with no Vercel secret, and the deploy job is still bound to docs-preview and waits for its required reviewer. The reusable workflow gains three optional inputs, each validated before use. comment_repository points the URL comment at the engine pull request instead of the content repository's. status_sha adds the commit status. deploy_engine_ref picks the engine commit the deploy job checks out; the caller passes the pull request's base commit, so the lockfile and Vercel CLI that run next to VERCEL_TOKEN are main's, not the pull request's. Existing callers pass none of them and behave as before. The deploy job now needs statuses: write, so any workflow_call caller must grant it.

deploy_engine_ref covers only the engine checkout. For a pull_request run, the local uses: loads the pull request's own copy of docs-pr-preview.yml, so the deploy job's steps come from the pull request, and the docs-preview approval is the only check between a workflow edit and VERCEL_TOKEN. This matches router-pr-preview.yml. Approving a preview therefore means reviewing the pull request's .github/workflows/ changes first, and the header comments and AGENTS.md now say so.

The caller passes secrets: inherit, because a called workflow sees only the secrets its caller passes, environment secrets included: the first run without it reached the deploy job with VERCEL_TOKEN empty. The token stays scoped to the docs-preview environment, so the build job, which has no environment, still can't read it, and its existing "Refuse to run holding a Vercel secret" step fails the run if a repository-level VERCEL_TOKEN ever appears. The caller's pending and failed status jobs use only the job token with statuses: write and read no secret.

What this PR doesn't do: remove the approval click, turn off Vercel's Git previews, or retire coder-docs-router.

Review feedback applied

Jess's review, all in 2d15ba7. P2 (the approval gates the PR's own workflow YAML): one line in the header comments of engine-pr-preview.yml and docs-pr-preview.yml, and one sentence in the AGENTS.md preview paragraph, say that a docs-preview approval is a review of the PR's .github/workflows/ changes; the reviewer-dropping follow-up is withdrawn above. P3 (statuses: write for every caller): the status_sha input description now says every caller must grant it, even with the input empty, or the run fails at startup. Nit (pending status): a new pending job in the caller marks the head commit pending ("Building; the deploy awaits docs-preview approval") before the reusable workflow starts, the deploy's existing step replaces it with success, and a failed job (if: failure()) marks it failure with a link to the run, so a stale success from an earlier push no longer looks current. Both use the same docs preview context and the job token, and neither reads a secret.

QA

Nothing changes on the site. In Firefox or Chrome:

  1. Open this PR's Checks tab. The engine-pr-preview run has a resolve coder/coder main job and a mark the preview pending job that passed, and a preview / build preview job that passed. While the deploy waits, the Checks list shows a pending docs preview status reading "Building; the deploy awaits docs-preview approval".
  2. Its preview / deploy preview job waits for review. Review this PR's .github/workflows/ changes, then approve it from the run page (Review deployments, tick docs-preview, Approve and deploy).
  3. After about three minutes, a "Docs preview deployment" comment appears on this PR with a coder-docs preview URL, and the docs preview status turns green with a Details link that opens the same URL.
  4. Open the URL and sign in to Vercel when asked. The docs home page renders.

Pages to compare

What to check Production Preview
Docs home renders from coder/coder main https://coder.com/docs/ The URL in this PR's "Docs preview deployment" comment (Vercel login)

Testing

pnpm lint:actions (actionlint with ShellCheck) passes on both workflows, and workflow-secrets.test.mjs from #347 passes 11 of 11 after merging main. This PR changes both preview workflows, so the path filter makes it preview itself: the run on this PR is the end-to-end test, using the base commit's engine for the deploy job.

Upstream

No. These are Coder's own CI workflows.

Linear: https://linear.app/codercom/issue/DOCS-1510/preview-the-docs-site-automatically-on-every-docs-engine-pr-push


🤖 Built with AI assistance.

A docs-site change could only be previewed by dispatching docs-pr-preview.yml by hand, and Vercel's own Git builds only cover apps/router, so a change to a shared package such as docs-theme never got a preview at all.

engine-pr-preview.yml now runs on each push to a same-repository pull request that touches the docs site or a package, resolves coder/coder main, and calls docs-pr-preview.yml with it. The reusable workflow gains three optional inputs: comment_repository, so the URL comment can go on the engine pull request instead of the content repository's; status_sha, which links the deployment from a "docs preview" commit status; and deploy_engine_ref, which the caller sets to the pull request's base commit so the deploy job never installs the pull request's own lockfile or Vercel CLI next to the token. The deploy still waits for a docs-preview reviewer. Fork pull requests are skipped.

Assisted-by: AI
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
coder-docs Ready Ready Preview Nov 9, 2026 10:01pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
coder-docs-router Ignored Ignored Preview Nov 9, 2026 10:01pm UTC

Request Review

@nickvigilante
nickvigilante marked this pull request as ready for review November 4, 2026 19:46
A called workflow sees only the secrets its caller passes, environment secrets included, so the deploy job found docs-preview's VERCEL_TOKEN empty. secrets: inherit fixes that; the token stays environment-scoped, and the build job still refuses to run if a Vercel secret is visible to it.

Assisted-by: AI
@linear-code

linear-code Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
DOCS-1510 Preview the docs site automatically on every docs-engine PR push

PR #311 adds engine-pr-preview.yml. Every push to a same-repository PR that touches apps/docs, apps/offlinedocs, packages/** or the root manifests builds the docs site against coder/coder main and deploys a login-protected preview on coder-docs. The URL goes in one PR comment and a docs preview commit status. Fork PRs are skipped, and the deploy job checks out the PR's base commit so the PR's lockfile and Vercel CLI never run beside VERCEL_TOKEN.

Why: Vercel's Git builds only cover apps/router and skip unaffected packages, so a docs-theme or docs-ui change (#310, #312) never got a preview without a hand-dispatched run.

Still manual: the deploy waits for a docs-preview reviewer on each push (see the follow-up issue on dropping that click).

Review in Linear

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Docs preview deployment

Rendered with docs-engine bec8344 from coder/coder at f776c020ff85ebe1df48c07f582dd74650f5cd54: https://coder-docs-bupf5dt0r.coderite.app

The preview is behind Vercel authentication; sign in with your Coder Vercel account.

Assisted-by: AI
Resolve the AGENTS.md previews entry: keep main's note that Vercel builds
the router from Git on main only, this branch's engine-pr-preview.yml
description in place of the manual docs-pr-preview.yml run, and main's
router preview entry.

Assisted-by: AI

@Jesswinters Jesswinters left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found no P0 or P1 issues, so I'm approving. This uses the same trust model as router-pr-preview.yml, which is already accepted: forks are skipped, the build job compiles the content with no Vercel secret, the deploy job is gated by the docs-preview reviewer, and the deploy job's engine comes from the base commit. The three new inputs are validated as strictly as the existing ones. Existing callers pass none of them, so their behavior doesn't change.

What I checked (local checkout of 25415da)

  • I merged origin/main locally: it merges cleanly, actionlint passes, and #347's workflow-secrets.test.mjs passes 11 of 11. The new caller has no secrets.X reference, and secrets: inherit passes to a workflow in this repository, which is scanned on its own.
  • I also merged #321's branch in test-only: no conflicts. After #321, the deploy job's VERCEL_ORG_ID / VERCEL_PROJECT_ID come from secrets., and secrets: inherit passes them through, so the two PRs work together.

Suggestions (P2/P3, none block merging), inline:

  1. P2: the docs-preview approval is now the only barrier between a branch's workflow YAML and VERCEL_TOKEN. That should be stated wherever the gate is described, and the "drop the required reviewer for same-repository PRs" follow-up should be reconsidered.
  2. P3: statuses: write on the reusable deploy job is a new requirement for every caller.
  3. Nit: report a pending status while the deploy waits for approval.

This review was generated by Coder Agents on behalf of @Jesswinters.

pr_number: ${{ format('{0}', github.event.pull_request.number) }}
comment_repository: ${{ github.repository }}
status_sha: ${{ github.event.pull_request.head.sha }}
deploy_engine_ref: ${{ github.event.pull_request.base.sha }}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: deploy_engine_ref covers the deploy job's checkout, but not the workflow code that runs beside the token. For a pull_request run, a local uses: ./.github/workflows/docs-pr-preview.yml is loaded from the caller's commit, which is the PR's merge commit. So the deploy job's steps are the PR's version of docs-pr-preview.yml. The path filter includes that file, so a PR that edits the deploy job (for example, to echo $VERCEL_TOKEN | base64) previews itself, and only the docs-preview approval stands between that edit and the token. The base-commit engine stops the PR's lockfile and Vercel CLI from running there, but it doesn't stop a change to the YAML itself.

This matches router-pr-preview.yml today, so it isn't a regression. Two things follow from it:

  • The approval should be treated as a code review of .github/workflows/ in that PR. A line in the header comment here and in the README paragraph would say so. A run that fires on every push to every docs-touching PR also invites click-through approvals, which wears this gate down over time.
  • The follow-up the description mentions, "dropping the required reviewer for same-repository pull requests", would put VERCEL_TOKEN within reach of anyone who can push a branch and open a PR. That is essentially the Nov 14–15 incident path. If that follow-up goes ahead, it needs a different design, for example a pull_request_target-style split where the token-holding workflow always comes from main. Removing the reviewer from this structure isn't enough.

permissions:
contents: read
pull-requests: write
statuses: write

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: a reusable workflow's job can't request more permissions than its caller grants, so every workflow_call caller now has to grant statuses: write, even when it passes no status_sha. Otherwise the run fails at startup. No other caller exists today (coder/coder doesn't call this workflow), so nothing breaks. I'd mention it in the workflow_call input descriptions or the header comment, so whoever wires a new caller doesn't hit an unexplained startup failure.

echo "Created the preview comment."
fi

- name: Mark the commit with the preview

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the status appears only after a successful deploy. While the deploy waits for approval, which is the state these runs spend the longest in, the Checks list shows nothing for docs preview. A pending status from the preview caller (or the build job's end) with the description "awaiting docs-preview approval", replaced by success here, would tell PR authors why there's no URL yet. On failure, a failure or error state in an if: failure() step would avoid leaving a stale success from an earlier push looking current.

…roval gate

The docs preview status only appeared after a successful deploy, so a PR showed nothing while the deploy waited for approval, and a success from an earlier push stayed current when a later run failed. The caller now marks the head commit pending before the build and failure if the build or deploy fails; both jobs use only the job token.

For a pull_request run the deploy job's steps come from the PR's own copy of docs-pr-preview.yml, so the docs-preview approval is the only check between a workflow edit and VERCEL_TOKEN. The header comments and AGENTS.md now say that approving a preview means reviewing the PR's workflow changes. The status_sha input also notes that every caller must grant statuses write.

Assisted-by: AI
@nickvigilante
nickvigilante merged commit 5529e8e into main Nov 16, 2026
31 of 33 checks passed
@nickvigilante
nickvigilante deleted the vigilante/engine-pr-preview branch November 16, 2026 22:43

This branch is waiting to be deployed

1 active (outdated) and 1 waiting deployments
docs-preview — 2d15ba79 Waiting Nov 16, 2026 by nickvigilante via preview / deploy preview #5
Preview — 35d1b975 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants