diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index df59713..38e6d04 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -63,6 +63,22 @@ jobs: - name: Run jest with coverage run: npm test -- --ci + # The unit tests on the next Node LTS, ahead of moving production to it (#45). Not a + # required check: a failure here is a heads-up, not a blocker. + test-node22: + name: Test (Node 22) + runs-on: ubuntu-latest + timeout-minutes: 20 + container: node:22-bookworm@sha256:e13726ca604184d7a91fcacab1fc09eefd642dc28e79ac34e85540dd93b78cfb + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + with: + persist-credentials: false # no job pushes; keep the token out of .git/config + - name: Install dependencies (lockfile only) + run: npm ci + - name: Run jest + run: npx jest --ci + audit: name: Security (npm audit) runs-on: ubuntu-latest @@ -84,6 +100,12 @@ jobs: sleep 20 done exit 1 + - name: Install dependencies (lockfile only) + run: npm ci --ignore-scripts + - name: Registry signatures and provenance of every installed package + run: npm audit signatures + - name: Licences of production dependencies + run: node scripts/ci/licenses.js - name: Software bill of materials (production dependencies) run: npm sbom --sbom-format cyclonedx --omit dev --package-lock-only > sbom.cdx.json - name: Keep the SBOM for each main build diff --git a/scripts/ci/licenses.js b/scripts/ci/licenses.js new file mode 100755 index 0000000..5b8f452 --- /dev/null +++ b/scripts/ci/licenses.js @@ -0,0 +1,51 @@ +#!/usr/bin/env node +'use strict'; + +// Licence review for production dependencies (#45): every package that ships with Pulse +// must use a licence on the allowlist. Run after `npm ci`. The lockfile records most +// licences; for the rest, the installed package's own package.json is read. +// An SPDX "A OR B" passes when either side is allowed; "A AND B" needs both. + +const fs = require('fs'); +const path = require('path'); + +const ALLOWED = new Set([ + 'MIT', 'ISC', 'BSD-2-Clause', 'BSD-3-Clause', 'Apache-2.0', '0BSD', + 'BlueOak-1.0.0', 'CC0-1.0', 'Unlicense', 'Python-2.0', +]); + +const root = path.join(__dirname, '..', '..'); +const lock = JSON.parse(fs.readFileSync(path.join(root, 'package-lock.json'), 'utf8')); + +function licenceOf(key, entry) { + if (entry.license) return entry.license; + try { + const pkg = JSON.parse(fs.readFileSync(path.join(root, key, 'package.json'), 'utf8')); + if (typeof pkg.license === 'string') return pkg.license; + if (pkg.license && pkg.license.type) return pkg.license.type; + if (Array.isArray(pkg.licenses)) return pkg.licenses.map(l => l.type || l).join(' OR '); + } catch (e) { /* not installed or unreadable: reported below */ } + return null; +} + +function allowed(expr) { + const clean = expr.replace(/[()]/g, ' ').trim(); + return clean.split(/\s+OR\s+/).some(alt => alt.split(/\s+AND\s+/).every(id => ALLOWED.has(id.trim()))); +} + +const problems = []; +let checked = 0; +for (const [key, entry] of Object.entries(lock.packages || {})) { + if (!key || entry.dev || entry.link) continue; // the root, dev-only and workspace links + checked++; + const lic = licenceOf(key, entry); + if (!lic) problems.push(`${key}: no licence found`); + else if (!allowed(lic)) problems.push(`${key}: ${lic}`); +} + +if (problems.length) { + console.error(`Licences not on the allowlist (${[...ALLOWED].join(', ')}):`); + for (const p of problems) console.error(' ' + p); + process.exit(1); +} +console.log(`${checked} production packages, all with allowed licences.`);