From ca9d89813ff5d8c8da11265f5539f934e4b6940b Mon Sep 17 00:00:00 2001 From: Grantfox Agent <160465301+emirykl@users.noreply.github.com> Date: Tue, 24 Nov 2026 00:37:38 +0300 Subject: [PATCH] chore: declare and verify Node 22 version --- .github/workflows/coverage.yml | 2 + .nvmrc | 1 + CONTRIBUTING.md | 2 +- package.json | 2 + scripts/check-node-version.mjs | 69 +++++++++++++++++++++++++++++ scripts/check-node-version.test.mjs | 43 ++++++++++++++++++ 6 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 .nvmrc create mode 100644 scripts/check-node-version.mjs create mode 100644 scripts/check-node-version.test.mjs diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d7ce5890..a5e0a709 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -43,6 +43,8 @@ jobs: run: pnpm errors:normalize:test && pnpm errors:normalize:check - name: Validate workflow pnpm version matches packageManager run: pnpm ci:pnpm-version:test && pnpm ci:pnpm-version:check + - name: Validate Node version file, engines, and workflows + run: pnpm ci:node-version:test && pnpm ci:node-version:check - name: Mainnet readiness matches the committed manifest (recorded fixture, no RPC, no secrets) run: | diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 00000000..2bd5a0a9 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +22 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9c2310d6..07753155 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,7 +41,7 @@ Do not invent newer requirements. | Tool | Version | Notes | | --- | --- | --- | -| Node.js | `>= 22` | pinned by `engines.node` | +| Node.js | `>= 22` | `nvm use` reads `.nvmrc` to select Node 22; `engines.node` requires at least 22 | | pnpm | `10.13.1` | pinned by `packageManager`; `corepack enable` picks it up | | Rust | stable + `wasm32v1-none` target | pinned by `rust-toolchain.toml` | | Stellar CLI | latest | `cargo install stellar-cli --locked` | diff --git a/package.json b/package.json index 6a6794c0..029d5945 100644 --- a/package.json +++ b/package.json @@ -98,6 +98,8 @@ "errors:normalize:test": "pnpm --filter @sub-rosa/logging test && node --test scripts/check-error-normalization.test.mjs", "ci:pnpm-version:check": "node scripts/check-pnpm-version.mjs", "ci:pnpm-version:test": "node --test scripts/check-pnpm-version.test.mjs", + "ci:node-version:check": "node scripts/check-node-version.mjs", + "ci:node-version:test": "node --test scripts/check-node-version.test.mjs", "line-lengths:check": "node scripts/check-line-lengths.mjs", "line-lengths:test": "node --test scripts/check-line-lengths.test.mjs", "wf-creds:check": "node scripts/check-workflow-credentials.mjs", diff --git a/scripts/check-node-version.mjs b/scripts/check-node-version.mjs new file mode 100644 index 00000000..81bc703a --- /dev/null +++ b/scripts/check-node-version.mjs @@ -0,0 +1,69 @@ +import { readFileSync, readdirSync } from 'node:fs'; +import { join } from 'node:path'; +import { fileURLToPath, pathToFileURL } from 'node:url'; + +const root = fileURLToPath(new URL('..', import.meta.url)); +const NODE_MAJOR = '22'; + +export function validateNodeVersions(versionFile, packageJsonText, workflows) { + const errors = []; + const version = versionFile.trim(); + if (version !== NODE_MAJOR) { + errors.push(`.nvmrc must contain ${NODE_MAJOR}; found ${JSON.stringify(version)}`); + } + + const engine = JSON.parse(packageJsonText).engines?.node; + if (engine !== `>=${NODE_MAJOR}`) { + errors.push(`package.json engines.node must be >=${NODE_MAJOR}; found ${JSON.stringify(engine)}`); + } + + if (Object.keys(workflows).length === 0) { + errors.push('No GitHub Actions workflows found'); + } + for (const [name, content] of Object.entries(workflows)) { + const lines = content.split(/\r?\n/); + let setupCount = 0; + for (let i = 0; i < lines.length; i++) { + const step = lines[i].match(/^(\s*)-\s+uses:\s*actions\/setup-node@v\d+\s*$/); + if (!step) continue; + setupCount++; + let versionInStep; + for (let j = i + 1; j < lines.length; j++) { + const line = lines[j]; + if (line.trim() && line.match(/^\s*/)[0].length <= step[1].length) break; + const match = line.trim().match(/^node-version:\s*(.*)$/); + if (match) { + versionInStep = match[1].replace(/\s+#.*$/, '').trim().replace(/^['"]|['"]$/g, ''); + break; + } + } + if (versionInStep !== NODE_MAJOR) { + errors.push(`${name}: actions/setup-node must use node-version: ${NODE_MAJOR}; found ${JSON.stringify(versionInStep)}`); + } + } + if (setupCount === 0) { + errors.push(`${name}: missing actions/setup-node`); + } + } + return errors; +} + +if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) { + const workflowsDir = join(root, '.github/workflows'); + const workflows = Object.fromEntries( + readdirSync(workflowsDir) + .filter((name) => /\.ya?ml$/.test(name)) + .map((name) => [name, readFileSync(join(workflowsDir, name), 'utf8')]), + ); + const errors = validateNodeVersions( + readFileSync(join(root, '.nvmrc'), 'utf8'), + readFileSync(join(root, 'package.json'), 'utf8'), + workflows, + ); + if (errors.length > 0) { + process.stderr.write(`${errors.join('\n')}\n`); + process.exitCode = 1; + } else { + process.stdout.write('Node 22 matches .nvmrc, engines.node, and every workflow\n'); + } +} diff --git a/scripts/check-node-version.test.mjs b/scripts/check-node-version.test.mjs new file mode 100644 index 00000000..8e377ece --- /dev/null +++ b/scripts/check-node-version.test.mjs @@ -0,0 +1,43 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { validateNodeVersions } from './check-node-version.mjs'; + +const packageJson = JSON.stringify({ engines: { node: '>=22' } }); +const workflow = `jobs: + check: + steps: + - uses: actions/setup-node@v4 + with: + node-version: '22' +`; + +test('accepts Node 22 in the version file, engines, and every workflow', () => { + assert.deepEqual(validateNodeVersions('22\n', packageJson, { 'check.yml': workflow }), []); +}); + +test('rejects a different version file or engine minimum', () => { + const errors = validateNodeVersions('20\n', JSON.stringify({ engines: { node: '>=20' } }), { + 'check.yml': workflow, + }); + assert.match(errors[0], /\.nvmrc must contain 22/); + assert.match(errors[1], /engines\.node must be >=22/); +}); + +test('checks every setup-node step and reports missing versions', () => { + const workflows = { + 'good.yml': workflow, + 'wrong.yml': workflow.replace("node-version: '22'", 'node-version: "20"'), + 'missing.yml': workflow.replace("node-version: '22'", 'cache: pnpm'), + }; + const errors = validateNodeVersions('22\n', packageJson, workflows); + assert.equal(errors.length, 2); + assert.match(errors[0], /wrong\.yml.*found "20"/); + assert.match(errors[1], /missing\.yml.*found undefined/); +}); + +test('rejects a workflow without setup-node', () => { + const errors = validateNodeVersions('22\n', packageJson, { + 'rust.yml': 'jobs:\n check:\n steps:\n - uses: actions/checkout@v4\n', + }); + assert.deepEqual(errors, ['rust.yml: missing actions/setup-node']); +});