Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

chore: add check engines script to CI #2922

Merged
merged 1 commit into from
Oct 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/scripts/check-engines.js
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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-*"
}
}