Skip to content

Commit

Permalink
chore: add check engines script to CI (#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Oct 28, 2023
1 parent 707927c commit 21a7249
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
41 changes: 41 additions & 0 deletions .github/scripts/check-engines.js
@@ -0,0 +1,41 @@
const { join } = require('path')
const semver = require('semver')
const Arborist = require('@npmcli/arborist')

const run = async (path, useEngines) => {
const pkgPath = join(path, 'package.json')
const pkg = require(pkgPath)

const engines = useEngines || pkg.engines.node

const arb = new Arborist({ path })
const tree = await arb.loadActual({ forceActual: true })
const deps = await tree.querySelectorAll(`#${pkg.name} > .prod:attr(engines, [node])`)

const invalid = []
for (const dep of deps) {
const depEngines = dep.target.package.engines.node
if (!semver.subset(engines, depEngines)) {
invalid.push({
name: `${dep.name}@${dep.version}`,
location: dep.location,
engines: depEngines
})
}
}

if (invalid.length) {
const msg = 'The following production dependencies are not compatible with ' +
`\`engines.node: ${engines}\` found in \`${pkgPath}\`:\n` + invalid.map((dep) => [
`${dep.name}:`,
` engines.node: ${dep.engines}`,
` location: ${dep.location}`
].join('\n')).join('\n')
throw new Error(msg)
}
}

run(process.cwd(), ...process.argv.slice(2)).then(() => console.log('Success')).catch((err) => {
console.error(err)
process.exitCode = 1
})
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Expand Up @@ -18,6 +18,23 @@ jobs:
- uses: actions/checkout@v4
- run: pip install --user ruff
- run: ruff --output-format=github --select="E,F,PLC,PLE,UP,W,YTT" --ignore="E721,PLC1901,S101,UP031" --target-version=py38 .
Engines:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Use Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Install Dependencies
run: |
npm install --no-progress
- name: Check Engines
run: |
# TODO: move this to its own action
npm install @npmcli/arborist@7 semver@7 --no-save
node .github/scripts/check-engines.js
Tests:
needs: Lint_Python # Lint_Python takes ~5 seconds, so wait for it to pass before running the full matrix of tests.
strategy:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -44,7 +44,7 @@
"standard": "^17.0.0"
},
"scripts": {
"lint": "standard */*.js test/**/*.js",
"lint": "standard \"*/*.js\" \"test/**/*.js\" \".github/**/*.js\"",
"test": "npm run lint && mocha --timeout 15000 --reporter=test/reporter.js test/test-download.js test/test-*"
}
}

0 comments on commit 21a7249

Please sign in to comment.