diff --git a/dashboard/package.json b/dashboard/package.json index 89468a9cf..c2191c48a 100644 --- a/dashboard/package.json +++ b/dashboard/package.json @@ -7,6 +7,7 @@ "start": "astro dev", "build:astro": "astro check && astro build", "postbuild:search": "pagefind --site dist --output-path dist/pagefind", + "prebuild": "node scripts/check-npm-pin.mjs", "build": "npm run build:astro && npm run postbuild:search", "preview": "astro preview" }, diff --git a/dashboard/scripts/check-npm-pin.mjs b/dashboard/scripts/check-npm-pin.mjs new file mode 100644 index 000000000..7f999f91a --- /dev/null +++ b/dashboard/scripts/check-npm-pin.mjs @@ -0,0 +1,27 @@ +// renovate.json's constraints.npm sets the npm version Renovate writes +// dashboard/package-lock.json with. It must match the npm CI runs, which is +// the one bundled with Node, so a Node major can move it. Renovate doesn't +// offer updates to the pin, so this fails the Node major PR's dashboard +// build until someone raises it. Enforced in CI only, so a local build on +// another npm isn't blocked. +import { readFileSync } from "node:fs"; + +const running = (process.env.npm_config_user_agent ?? "").match( + /\bnpm\/(\d+)\.\d+\.\d+/, +); +if (!process.env.CI || !running) process.exit(0); + +const config = JSON.parse( + readFileSync(new URL("../../renovate.json", import.meta.url), "utf8"), +); +const pin = config.constraints?.npm ?? ""; +const version = running[0].slice(4); + +if (pin.match(/\d+/)?.[0] !== running[1]) { + console.error( + `renovate.json has constraints.npm "${pin}", but CI runs npm ${version}. ` + + `Set constraints.npm to "^${version}" in this pull request.`, + ); + process.exit(1); +} +console.log(`renovate.json constraints.npm "${pin}" matches npm ${version}.`); diff --git a/docs/skills/ci-ops/dashboard-metrics/SKILL.md b/docs/skills/ci-ops/dashboard-metrics/SKILL.md index 9fb4fc895..381882bf8 100644 --- a/docs/skills/ci-ops/dashboard-metrics/SKILL.md +++ b/docs/skills/ci-ops/dashboard-metrics/SKILL.md @@ -93,6 +93,8 @@ This skill guides agents through modifying, compiling, and deploying the QA dash 11. **`publish-to-pages.yml` is not exercised by PR checks**: the workflow only triggers on `schedule`, `workflow_dispatch`, and pushes to `main` under `dashboard/**`. A dependency PR can therefore merge fully green and only break the dashboard hours later on the next 2-hourly cron. Any PR touching `dashboard/package.json`, `dashboard/package-lock.json`, or `dashboard/scripts/**` must be validated locally with `npm ci && npm run build` before merge. +12. **Renovate's npm pin must match CI's npm**: `renovate.json` sets `constraints.npm` (`^11.20.0`, #1255) so Renovate writes `dashboard/package-lock.json` with the same npm CI uses; npm 12 could not update that lock file (#1257). CI's npm is the one bundled with Node (`node-version: '26'` → npm 11), and Renovate doesn't offer updates to the pin. So a Node major PR that brings a newer npm fails `dashboard-build` at `prebuild` (`dashboard/scripts/check-npm-pin.mjs`), with the exact value to set. Fix it by raising `constraints.npm` in that same PR, not by editing or skipping the check. Local builds skip the check; it only enforces when `CI` is set. + ## Common Rationalizations | Rationalization | Reality | diff --git a/renovate.json b/renovate.json index d16b09356..7987f145c 100644 --- a/renovate.json +++ b/renovate.json @@ -50,6 +50,20 @@ "matchUpdateTypes": ["major"], "enabled": false }, + { + "description": "Don't offer updates to the npm pin under constraints: it must match the npm version CI runs (Node 26 ships npm 11), not the newest npm (#1257 was closed for this). Raise it in the same change that moves CI to a newer npm; dashboard/scripts/check-npm-pin.mjs fails the dashboard build until then.", + "matchManagers": ["renovate-config"], + "matchDepTypes": ["tool-constraint"], + "enabled": false + }, + { + "description": "A Node major brings a newer bundled npm. Remind whoever merges it to raise constraints.npm in the same PR, since updates to that pin are switched off above.", + "matchDepNames": ["node"], + "matchUpdateTypes": ["major"], + "prBodyNotes": [ + "**Before merging:** this Node version may bundle a newer npm. Check `npm --version` in this PR's CI log and set `constraints.npm` in `renovate.json` to match, in this same PR." + ] + }, { "description": "A major update always waits for a person. automerge false only stops Renovate; the hive merges trusted-bot pull requests itself, so label the update needs-owner-merge (the hive's auto_merge.human_merge_labels default): the hive never merges a PR with it, and only the owner's merge click lands it. hold was used first (#1233) but a held PR merges as soon as someone removes hold. The hive merged #1229 and #1230 before any label, and #1230 broke the dashboard publish. Last matching rule wins, so keep this rule last.", "matchUpdateTypes": ["major"],