From cc23a7218775b4036ef8367816f9e791175f548e Mon Sep 17 00:00:00 2001 From: Nick Vigilante Date: Thu, 12 Nov 2026 13:47:39 -0500 Subject: [PATCH] ci(router): build the router from git on main only Vercel's Git integration built a preview of apps/router for every branch that changed it, with coder-docs's preview environment variables and no reviewer in front of it. Once the repository is public, a fork's branch would be held only by Vercel's fork protection. router-pr-preview.yml now previews router changes from Actions behind the docs-preview reviewers, so git.deploymentEnabled turns the Git builds off for every branch except main, which still deploys production. A branch matching both patterns deploys if either is true, so main keeps deploying; "**" also matches branch names with a slash. A router test pins the setting, and the docs say a pull request gets no Vercel bot preview any more. Assisted-by: AI --- .github/workflows/router-pr-preview.yml | 5 +++-- AGENTS.md | 4 ++-- README.md | 2 +- apps/router/lib/vercel-config.test.ts | 6 ++++++ apps/router/vercel.json | 3 +++ 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/router-pr-preview.yml b/.github/workflows/router-pr-preview.yml index 3ebdd40c..0b1fff64 100644 --- a/.github/workflows/router-pr-preview.yml +++ b/.github/workflows/router-pr-preview.yml @@ -1,6 +1,7 @@ # Previews a docs-engine pull request's apps/router as a login-protected -# preview deployment of the coder-docs Vercel project, so router changes keep -# a preview once Vercel's Git-triggered previews are turned off. +# preview deployment of the coder-docs Vercel project. Vercel's own Git builds +# run for main only (apps/router/vercel.json), so this is a router change's +# only preview. # # Same split as docs-pr-preview.yml: `build` compiles the pull request's code # with no Vercel secret and no Vercel login (`vercel build --standalone` needs diff --git a/AGENTS.md b/AGENTS.md index da43814a..5f43e20d 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -29,8 +29,8 @@ Read [README.md](README.md) and [ARCHITECTURE.md](ARCHITECTURE.md) first for wha - Stylelint checks the CSS in `packages/docs-theme` as part of that package's `lint` script, with `stylelint-config-recommended` only; formatting stays with Oxfmt, so add no Stylelint style rules. - For local dev against the real corpus, run `pnpm dev` in `apps/docs` with `DOCS_REPO` pointing at a `coder/coder` checkout. Without it, a small fixture corpus is used. - Stop a dev server by its port (`kill $(lsof -ti tcp:)`). Never use `pkill -f 'next dev'`, because other sessions run dev servers on the same machine. -- Previews are behind Vercel SSO. Vercel builds only `apps/router`: each branch that changes it gets a stable alias on the `coder-docs` project, built from the branch name with `/` replaced by `-`, which the Vercel bot comment on the PR links. A docs-site change is previewed by running `docs-pr-preview.yml` on the branch, which deploys a prebuilt preview to `coder-docs` and prints its URL. -- A pull request that changes `apps/router`, `docs-config` or `docs-manifest` also gets a router preview from `router-pr-preview.yml`: it builds with `vercel build --standalone` and no Vercel credentials, and deploys once a `docs-preview` reviewer approves, then links the URL in a comment and a `router preview` status. It replaces the Vercel Git previews when those are turned off. The build writes coder-docs's project settings itself, so keep them in step with the Vercel project. +- Previews are behind Vercel SSO. Vercel builds `apps/router` from Git on `main` only, for production; `git.deploymentEnabled` in `apps/router/vercel.json` turns its Git builds off for every other branch, so a pull request gets no Vercel bot preview. A docs-site change is previewed by running `docs-pr-preview.yml` on the branch, which deploys a prebuilt preview to `coder-docs` and prints its URL. +- A pull request that changes `apps/router`, `docs-config` or `docs-manifest` also gets a router preview from `router-pr-preview.yml`: it builds with `vercel build --standalone` and no Vercel credentials, and deploys once a `docs-preview` reviewer approves, then links the URL in a comment and a `router preview` status. It replaces the Vercel Git previews, which are off for every branch but `main`. The build writes coder-docs's project settings itself, so keep them in step with the Vercel project. ## Code diff --git a/README.md b/README.md index 06ed6393..d2dba8c8 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ The docs run on two Vercel projects on the `codercom` team. | Project | Builds | Serves | Previews | | ----------------------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------- | -| `coder-docs` | `apps/router` from Git (Root Directory `apps/router`), with `ROUTER_BASE_PATH=/docs` and `DOCS_ANALYTICS=1` | `coder-docs.coderite.app/docs`, from its own manifest and archive stores, behind coder.com's `/docs` rewrite | Behind Vercel login: router previews from Git and from `router-pr-preview.yml`, and docs-site previews prebuilt by `docs-pr-preview.yml` | +| `coder-docs` | `apps/router` from Git on `main` only (Root Directory `apps/router`), with `ROUTER_BASE_PATH=/docs` and `DOCS_ANALYTICS=1` | `coder-docs.coderite.app/docs`, from its own manifest and archive stores, behind coder.com's `/docs` rewrite | Behind Vercel login: router previews from `router-pr-preview.yml`, and docs-site previews prebuilt by `docs-pr-preview.yml` | | `coder-docs-pr-preview` | Nothing from this repository; coder/coder's own workflows deploy prebuilt output | No production site | Public coder/coder pull request previews only | The retired `/beta-docs` site's project, `coder-docs-router`, is deleted after this repository stops referring to it; see "Retiring the beta site" in `apps/docs/README.md`. diff --git a/apps/router/lib/vercel-config.test.ts b/apps/router/lib/vercel-config.test.ts index 6770fa8c..616fd795 100644 --- a/apps/router/lib/vercel-config.test.ts +++ b/apps/router/lib/vercel-config.test.ts @@ -6,8 +6,14 @@ type HeaderRule = { source: string; headers: { key: string; value: string }[] }; const config = JSON.parse(readFileSync(new URL("../vercel.json", import.meta.url), "utf8")) as { headers: HeaderRule[]; + git?: { deploymentEnabled?: boolean | Record }; }; +test("Vercel builds the router from Git for main only", () => { + // Every other branch is previewed by router-pr-preview.yml, behind a reviewer. + assert.deepEqual(config.git?.deploymentEnabled, { "**": false, main: true }); +}); + test("the router's global header rule carries the browser security headers", () => { const global = config.headers.find((rule) => rule.source === "/(.*)"); assert.ok(global, "vercel.json has no rule for every path"); diff --git a/apps/router/vercel.json b/apps/router/vercel.json index 9b32cfc2..e689717a 100644 --- a/apps/router/vercel.json +++ b/apps/router/vercel.json @@ -4,6 +4,9 @@ "installCommand": "pnpm install --frozen-lockfile", "buildCommand": "cd ../.. && pnpm turbo run build --filter=@coder/docs-router --cache=local:rw,remote:$([ \"$VERCEL_ENV\" = production ] && echo rw || echo r)", "ignoreCommand": "git diff --quiet HEAD^ HEAD -- :/apps/router :/packages :/package.json :/pnpm-lock.yaml :/pnpm-workspace.yaml :/turbo.json || exit 1", + "git": { + "deploymentEnabled": { "**": false, "main": true } + }, "headers": [ { "source": "/(.*)",