generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 98
fix(ci): remove invalid .npmrc config and add lockfile platform validation #2193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
markscott-ms
merged 3 commits into
finos:main
from
rocketstack-matt:fix/npmrc-warnings-lockfile-validation
Feb 28, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
5019ea2
fix(ci): remove invalid .npmrc config and add lockfile platform valid…
rocketstack-matt 53421d4
fix(ci): handle scoped packages with slash before OS segment
rocketstack-matt 9b28388
Merge branch 'main' into fix/npmrc-warnings-lockfile-validation
rocketstack-matt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Validate Lockfile Platforms | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - 'main' | ||
| - 'release*' | ||
| paths: | ||
| - 'package-lock.json' | ||
| push: | ||
| branches: | ||
| - 'main' | ||
| - 'release*' | ||
| paths: | ||
| - 'package-lock.json' | ||
|
|
||
| jobs: | ||
| validate-lockfile: | ||
| name: Validate Lockfile Platforms | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6 | ||
| with: | ||
| node-version: '22' | ||
|
|
||
| - name: Validate platform bindings in lockfile | ||
| run: node scripts/validate-lockfile-platforms.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| /** | ||
| * Validates that package-lock.json contains platform-specific optional | ||
| * dependencies for all platforms used in CI. | ||
| * | ||
| * npm has a known bug (https://github.com/npm/cli/issues/4828) where running | ||
| * `npm install` with an existing node_modules directory can prune optional | ||
| * platform-specific packages for platforms other than the current machine. | ||
| * This causes CI failures on Linux runners when the lockfile was regenerated | ||
| * on macOS without first deleting node_modules. | ||
| * | ||
| * This script catches the problem early by checking that every package with | ||
| * darwin variants also has corresponding linux-x64 variants. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
|
|
||
| const { readFileSync } = require('fs'); | ||
| const { join } = require('path'); | ||
|
|
||
| const lockfilePath = join(__dirname, '..', 'package-lock.json'); | ||
|
|
||
| let lockfile; | ||
| try { | ||
| lockfile = JSON.parse(readFileSync(lockfilePath, 'utf8')); | ||
| } catch (err) { | ||
| console.error(`Failed to read package-lock.json: ${err.message}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const packages = lockfile.packages || {}; | ||
|
|
||
| // Collect all platform-specific packages (those with both os and cpu fields) | ||
| // and group them by their base package name. | ||
| // | ||
| // Naming conventions: | ||
| // @esbuild/darwin-arm64 -> base: @esbuild (os after /) | ||
| // @rollup/rollup-darwin-arm64 -> base: @rollup/rollup (os after -) | ||
| // @tailwindcss/oxide-darwin-x64 -> base: @tailwindcss/oxide (os after -) | ||
| // lightningcss-darwin-arm64 -> base: lightningcss (os after -) | ||
| // | ||
| // We strip the trailing [-/]<os>-<cpu>[-<abi>] suffix to derive the base name. | ||
|
|
||
| const osPattern = 'linux|darwin|win32|android|freebsd|openbsd|netbsd|sunos|aix'; | ||
| const suffixRegex = new RegExp(`[-/](?:${osPattern})[-/].*$`); | ||
|
|
||
| const groups = new Map(); | ||
|
|
||
| for (const [key, meta] of Object.entries(packages)) { | ||
| if (!meta.os || !meta.cpu) continue; | ||
|
|
||
| // Normalise: strip leading node_modules/ (and nested node_modules/ paths) | ||
| const name = key.replace(/^(.+\/)?node_modules\//, ''); | ||
|
|
||
| // The os segment may follow a dash (@rollup/rollup-darwin-arm64) or a | ||
| // slash (@esbuild/darwin-arm64). The regex handles both separators. | ||
| const base = name.replace(suffixRegex, ''); | ||
| if (base === name) continue; // no recognisable platform suffix | ||
|
|
||
| if (!groups.has(base)) groups.set(base, []); | ||
| groups.get(base).push({ name, os: meta.os, cpu: meta.cpu }); | ||
| } | ||
|
|
||
| // For every group that contains darwin variants, verify that linux-x64 | ||
| // variants are also present (our CI runners are linux-x64). | ||
|
|
||
| const missing = []; | ||
|
|
||
| for (const [base, variants] of groups) { | ||
| const hasDarwin = variants.some(v => v.os.includes('darwin')); | ||
| if (!hasDarwin) continue; | ||
|
|
||
| const hasLinuxX64 = variants.some( | ||
| v => v.os.includes('linux') && v.cpu.includes('x64') | ||
| ); | ||
|
|
||
| if (!hasLinuxX64) { | ||
| const darwinNames = variants | ||
| .filter(v => v.os.includes('darwin')) | ||
| .map(v => v.name); | ||
| // Determine the separator used between base and os | ||
| // e.g. @esbuild/darwin-arm64 uses "/" while @rollup/rollup-darwin-arm64 uses "-" | ||
| const sep = darwinNames[0].startsWith(base + '/') ? '/' : '-'; | ||
| missing.push({ base, sep, darwinNames }); | ||
| } | ||
| } | ||
|
|
||
| if (missing.length > 0) { | ||
| console.error('Lockfile platform validation failed!\n'); | ||
| console.error( | ||
| 'The following packages have darwin variants but are missing linux-x64 variants.\n' + | ||
| 'This will cause CI failures on Linux runners.\n' | ||
| ); | ||
| for (const { base, sep, darwinNames } of missing) { | ||
| console.error(` ${base}`); | ||
| for (const name of darwinNames) { | ||
| console.error(` found: ${name}`); | ||
| } | ||
| console.error(` missing: ${base}${sep}linux-x64-*\n`); | ||
| } | ||
| console.error( | ||
| 'Fix: regenerate the lockfile from a clean state:\n\n' + | ||
| ' rm -rf node_modules package-lock.json && npm install\n' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log( | ||
| `Lockfile platform check passed: ${groups.size} platform-specific package groups validated.` | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.