Repository navigation
ci: preview the docs site on every engine pull request push - #311
Conversation
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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
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
DOCS-1510 Preview the docs site automatically on every docs-engine PR push
PR #311 adds Why: Vercel's Git builds only cover Still manual: the deploy waits for a |
Docs preview deploymentRendered 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
left a comment
There was a problem hiding this comment.
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/mainlocally: it merges cleanly,actionlintpasses, and #347'sworkflow-secrets.test.mjspasses 11 of 11. The new caller has nosecrets.Xreference, andsecrets: inheritpasses 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_IDcome fromsecrets., andsecrets: inheritpasses them through, so the two PRs work together.
Suggestions (P2/P3, none block merging), inline:
- P2: the
docs-previewapproval is now the only barrier between a branch's workflow YAML andVERCEL_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. - P3:
statuses: writeon the reusable deploy job is a new requirement for every caller. - Nit: report a
pendingstatus 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 }} |
There was a problem hiding this comment.
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_TOKENwithin 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 apull_request_target-style split where the token-holding workflow always comes frommain. Removing the reviewer from this structure isn't enough.
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| statuses: write |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
Merge order
Independent. It works today with the existing
docs-previewenvironment. 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 putVERCEL_TOKENwithin 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 frommain(aworkflow_runorpull_request_target-style design).Summary
A docs-site change could only be previewed by dispatching
docs-pr-preview.ymlby hand with a coder/coder SHA. Vercel's Git builds cover onlyapps/router, and Vercel skips them when the router isn't affected, so a change to a shared package such asdocs-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/codermainand deploys it as a login-protected preview oncoder-docs. The URL lands in a single comment on the pull request, updated on each push, and in adocs previewcommit 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.ymlresolves coder/codermainwithgit ls-remoteand calls the existing reusabledocs-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 todocs-previewand waits for its required reviewer. The reusable workflow gains three optional inputs, each validated before use.comment_repositorypoints the URL comment at the engine pull request instead of the content repository's.status_shaadds the commit status.deploy_engine_refpicks 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 toVERCEL_TOKENaremain's, not the pull request's. Existing callers pass none of them and behave as before. The deploy job now needsstatuses: write, so anyworkflow_callcaller must grant it.deploy_engine_refcovers only the engine checkout. For apull_requestrun, the localuses:loads the pull request's own copy ofdocs-pr-preview.yml, so the deploy job's steps come from the pull request, and thedocs-previewapproval is the only check between a workflow edit andVERCEL_TOKEN. This matchesrouter-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 withVERCEL_TOKENempty. The token stays scoped to thedocs-previewenvironment, 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-levelVERCEL_TOKENever appears. The caller'spendingandfailedstatus jobs use only the job token withstatuses: writeand 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.ymlanddocs-pr-preview.yml, and one sentence in the AGENTS.md preview paragraph, say that adocs-previewapproval is a review of the PR's.github/workflows/changes; the reviewer-dropping follow-up is withdrawn above. P3 (statuses: writefor every caller): thestatus_shainput description now says every caller must grant it, even with the input empty, or the run fails at startup. Nit (pending status): a newpendingjob in the caller marks the head commitpending("Building; the deploy awaits docs-preview approval") before the reusable workflow starts, the deploy's existing step replaces it withsuccess, and afailedjob (if: failure()) marks itfailurewith a link to the run, so a stalesuccessfrom an earlier push no longer looks current. Both use the samedocs previewcontext and the job token, and neither reads a secret.QA
Nothing changes on the site. In Firefox or Chrome:
engine-pr-previewrun has aresolve coder/coder mainjob and amark the preview pendingjob that passed, and apreview / build previewjob that passed. While the deploy waits, the Checks list shows a pendingdocs previewstatus reading "Building; the deploy awaits docs-preview approval".preview / deploy previewjob waits for review. Review this PR's.github/workflows/changes, then approve it from the run page (Review deployments, tickdocs-preview, Approve and deploy).coder-docspreview URL, and thedocs previewstatus turns green with a Details link that opens the same URL.Pages to compare
mainTesting
pnpm lint:actions(actionlint with ShellCheck) passes on both workflows, andworkflow-secrets.test.mjsfrom #347 passes 11 of 11 after mergingmain. 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.