|
| 1 | +name: 'Validate codebase' |
| 2 | +description: >- |
| 3 | + Run the standard npm CI gates against the calling repo: `npm ci`, |
| 4 | + then `npm run lint`, `npm run typecheck`, `npm test`. Each is |
| 5 | + expected to be defined as a script in the repo's package.json (or to |
| 6 | + fan out via npm workspaces to per-workspace scripts). |
| 7 | +
|
| 8 | +# This composite is the "does the codebase pass the org-standard |
| 9 | +# checks?" assertion. It's one of three validate-* actions: |
| 10 | +# |
| 11 | +# validate-containers-spec static check of the deploy `containers` JSON |
| 12 | +# validate-codebase (this) lint + typecheck + test against the repo |
| 13 | +# validate-build docker build of every container that declares build: |
| 14 | +# |
| 15 | +# Each is invocable independently; callers pick the subset that |
| 16 | +# matches what their workflow needs to check. |
| 17 | +# |
| 18 | +# Does its own checkout + setup-node so it's self-contained — invoke |
| 19 | +# directly from a job's `steps:` with just `uses:` and the npm-token. |
| 20 | + |
| 21 | +# Vendored from pncit/shared-actions@v2 (59e838b) because this repo is PUBLIC |
| 22 | +# and shared-actions is PRIVATE — a public repo can't `uses:` a private |
| 23 | +# action. Byte-for-byte identical to upstream apart from this comment; re-copy |
| 24 | +# when upstream changes (see .github/actions/README.md). |
| 25 | + |
| 26 | +inputs: |
| 27 | + npm-token: |
| 28 | + description: 'npm token used for `npm ci` (NODE_AUTH_TOKEN in the install step).' |
| 29 | + required: true |
| 30 | + npm-scope: |
| 31 | + description: 'npm scope (for private packages).' |
| 32 | + required: false |
| 33 | + default: '@pncit' |
| 34 | + registry-url: |
| 35 | + description: 'npm registry URL.' |
| 36 | + required: false |
| 37 | + default: 'https://registry.npmjs.org' |
| 38 | + |
| 39 | + npm-version: |
| 40 | + description: >- |
| 41 | + Exact npm version to pin after setup-node, e.g. "12.0.2". `.nvmrc` |
| 42 | + pins a Node *major*, so setup-node resolves to whatever 24.x is |
| 43 | + newest on the day — which is how npm crossed the 11 -> 12 boundary |
| 44 | + (and started blocking unapproved install scripts) with nothing |
| 45 | + committed on either side. Pinning here makes that upgrade a |
| 46 | + deliberate, reviewed edit to one default instead of a surprise. |
| 47 | + Set to the empty string to opt out and take the bundled npm. |
| 48 | + required: false |
| 49 | + default: '12.0.2' |
| 50 | + node-major-version: |
| 51 | + description: >- |
| 52 | + Optional. Required Node major, e.g. "24" — typically |
| 53 | + vars.NODE_MAJOR_VERSION. When this and npm-major-version are both |
| 54 | + set, verify-node-toolchain runs *after* setup-node, so it measures |
| 55 | + the toolchain that actually runs `npm ci`. Callers that invoke |
| 56 | + verify-node-toolchain as a top-level step are measuring the |
| 57 | + runner's system Node/npm, which is not what this action uses. |
| 58 | + required: false |
| 59 | + default: '' |
| 60 | + npm-major-version: |
| 61 | + description: 'Optional. Required npm major, e.g. "12". See node-major-version.' |
| 62 | + required: false |
| 63 | + default: '' |
| 64 | + |
| 65 | +runs: |
| 66 | + using: composite |
| 67 | + steps: |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@v7 |
| 70 | + |
| 71 | + - name: Setup Node |
| 72 | + uses: actions/setup-node@v7 |
| 73 | + with: |
| 74 | + node-version-file: .nvmrc |
| 75 | + cache: npm |
| 76 | + registry-url: ${{ inputs.registry-url }} |
| 77 | + scope: ${{ inputs.npm-scope }} |
| 78 | + # actions/setup-node@v6 dropped `always-auth: true` — it was a |
| 79 | + # v4-era flag and is no longer needed. Specifying it produced an |
| 80 | + # "Unexpected input" warning during the first real deploy run. |
| 81 | + |
| 82 | + # Pin npm before anything reads it. setup-node gives us whatever npm |
| 83 | + # its Node bundles; this makes the version an explicit, reviewable |
| 84 | + # input instead of a moving target. |
| 85 | + - name: Pin npm |
| 86 | + if: inputs.npm-version != '' |
| 87 | + shell: bash |
| 88 | + run: | |
| 89 | + npm i -g "npm@${NPM_VERSION}" |
| 90 | + echo "npm pinned to $(npm --version) ($(command -v npm))" |
| 91 | + env: |
| 92 | + NPM_VERSION: ${{ inputs.npm-version }} |
| 93 | + |
| 94 | + # Runs here, after Setup Node and the pin, so it asserts against the |
| 95 | + # toolchain `npm ci` will actually use. |
| 96 | + - name: Verify Node toolchain |
| 97 | + if: inputs.node-major-version != '' && inputs.npm-major-version != '' |
| 98 | + uses: pncit/shared-actions/.github/actions/verify-node-toolchain@main |
| 99 | + with: |
| 100 | + node-major-version: ${{ inputs.node-major-version }} |
| 101 | + npm-major-version: ${{ inputs.npm-major-version }} |
| 102 | + |
| 103 | + - name: Install dependencies |
| 104 | + shell: bash |
| 105 | + env: |
| 106 | + NODE_AUTH_TOKEN: ${{ inputs.npm-token }} |
| 107 | + run: npm ci 2>&1 | tee "${RUNNER_TEMP}/npm-ci.log" |
| 108 | + |
| 109 | + # npm 11.16.0 added per-package install-script allowlists (the |
| 110 | + # `allowScripts` field in package.json). npm 11 warns and still runs |
| 111 | + # them; npm 12 blocks them -- and `npm ci` exits 0 either way, so a |
| 112 | + # native module can silently never build. That is what took |
| 113 | + # documentation-server's whole suite down with 262 "Could not locate |
| 114 | + # the bindings file" errors against a green `npm ci`. |
| 115 | + # |
| 116 | + # Both the warn-phase and block-phase messages contain the literal |
| 117 | + # string `allowScripts`, so matching that catches the block and also |
| 118 | + # gives early warning on a runner still effectively on npm 11. |
| 119 | + # |
| 120 | + # Warning, not error, on purpose: most pncit repos have no |
| 121 | + # `allowScripts` field yet, and failing here would red them all at |
| 122 | + # once. Flip to ::error:: once the org-wide rollout lands. |
| 123 | + - name: Audit skipped install scripts |
| 124 | + shell: bash |
| 125 | + run: | |
| 126 | + if grep -q 'allowScripts' "${RUNNER_TEMP}/npm-ci.log"; then |
| 127 | + grep 'allowScripts' "${RUNNER_TEMP}/npm-ci.log" >&2 |
| 128 | + echo "::warning::npm flagged or skipped one or more install scripts. If any is a native module, it did not build and the install still reported success. Approve with: npx npm@${NPM_VERSION:-12} install-scripts approve <pkg>, then commit the package.json allowScripts change." |
| 129 | + fi |
| 130 | + env: |
| 131 | + NPM_VERSION: ${{ inputs.npm-version }} |
| 132 | + |
| 133 | + - name: Lint |
| 134 | + shell: bash |
| 135 | + run: npm run lint |
| 136 | + |
| 137 | + - name: Typecheck |
| 138 | + shell: bash |
| 139 | + run: npm run typecheck |
| 140 | + |
| 141 | + - name: Test |
| 142 | + shell: bash |
| 143 | + run: npm test |
0 commit comments