-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add workflow for testing required Node.js semver range
- Loading branch information
Showing
4 changed files
with
71 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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,2 @@ | ||
--- | ||
--- |
This file contains 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,29 @@ | ||
name: Test & Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
test-node-range: | ||
name: Test Node.js version range | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
- uses: actions/cache@v4 | ||
id: cache-node_modules | ||
with: | ||
path: node_modules | ||
key: ubuntu-latest-20-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
ubuntu-latest-20-${{ hashFiles('**/package-lock.json') }} | ||
- if: steps.cache-node_modules.outputs.cache-hit != 'true' | ||
run: npm ci | ||
- run: node ./scripts/test-node-range.js |
This file was deleted.
Oops, something went wrong.
This file contains 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,40 @@ | ||
import { readFile } from 'node:fs/promises' | ||
import { fileURLToPath } from 'node:url' | ||
|
||
import chalk from 'chalk' | ||
import { execa } from 'execa' | ||
import { subset } from 'semver' | ||
|
||
const packageJson = JSON.parse( | ||
await readFile(fileURLToPath(new URL('../package.json', import.meta.url))) | ||
) | ||
|
||
const lintStagedRequires = packageJson.engines.node | ||
|
||
console.log(`Currently required Node.js version: ${lintStagedRequires}`) | ||
|
||
console.log(chalk.dim('-----------------------------')) | ||
console.log(chalk.dim('Testing current dependencies:')) | ||
console.log(chalk.dim('-----------------------------')) | ||
|
||
let allDependenciesSupported = true | ||
|
||
for (const dependency of Object.keys(packageJson.dependencies)) { | ||
const { stdout: dependencyRequires } = await execa('npm', ['info', dependency, 'engines.node']) | ||
|
||
/** True if currently-required range is inside the dependency's required range */ | ||
const isSubset = subset(lintStagedRequires, dependencyRequires) | ||
|
||
if (!isSubset) { | ||
allDependenciesSupported = false | ||
} | ||
|
||
const color = isSubset ? chalk.greenBright : chalk.redBright | ||
const symbol = isSubset ? `✓` : '×' | ||
|
||
console.log(`${color(`${symbol} ${dependency}`)}:`, dependencyRequires) | ||
} | ||
|
||
if (!allDependenciesSupported) { | ||
process.exit(1) | ||
} |