From 2deb60f092cf5293c711347d0a3471daa4b71e86 Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:03:02 +0100 Subject: [PATCH 1/2] ci: gate Dependabot auto-merge on full CI and breaking/danger checks Dependency auto-merge version 2. A Dependabot patch/minor update is merged only when every other check on the PR head commit is green and the new dependency gate (.github/scripts/dependency-gate.mjs, byte-identical in all plugin repositories, dependency-free, 24 node:test tests with fixture lockfiles) finds nothing breaking or dangerous. Otherwise the PR gets the needs-review label and a comment with the reasons. Majors keep the major-update label and are never merged automatically. - surface job (read-only, runs PR code): builds merge base and head and records the npm pack file list, exports, peerDependencies, engines and the exports of the built entries. - gate job (trusted, script from the default branch, data only): engines, peerDependencies and peer floor, 0.x runtime minors, breaking-change wording, surface diff, dependency-review-action (moderate, license allowlist), npm audit signatures, install scripts, >15 new packages, non-registry or integrity-less resolutions. - merge job: waits for all workflow runs, check runs and statuses on the head SHA (two green polls, 75 min timeout), then merges with --match-head-commit. - CI runs the gate unit tests; docs describe the gate. Docs read (2026-11-19): GitHub Actions events (pull_request, workflow_run), Dependabot on Actions, GITHUB_TOKEN permissions, secure use; dependabot/fetch-metadata v3.1.0; dependency-review-action v5.0.0 (action.yml, README, src/main.ts, src/licenses.ts, src/purl.ts); upload-artifact v7, download-artifact v8; npm audit signatures (docs and npm 10.9.8 source); REST workflow runs, check runs, combined status, dependency-graph compare; gh pr merge --match-head-commit (gh 2.103.3). Co-Authored-By: Claude Opus 5.5 --- .github/scripts/.prettierrc.json | 7 + .github/scripts/dependency-gate.mjs | 1599 +++++++++++++++++ .github/scripts/dependency-gate.test.mjs | 302 ++++ .github/scripts/fixtures/base-lock.json | 88 + .github/scripts/fixtures/checks-failed.json | 50 + .github/scripts/fixtures/checks-green.json | 101 ++ .github/scripts/fixtures/checks-pending.json | 50 + .../scripts/fixtures/checks-superseded.json | 85 + .../scripts/fixtures/head-engines-lock.json | 100 ++ .../fixtures/head-install-script-lock.json | 108 ++ .github/scripts/fixtures/head-major-lock.json | 97 + .../fixtures/head-new-packages-lock.json | 212 +++ .github/scripts/fixtures/head-pass-lock.json | 100 ++ .../fixtures/head-peer-floor-lock.json | 101 ++ .github/scripts/fixtures/head-peer-lock.json | 100 ++ .../scripts/fixtures/head-registry-lock.json | 100 ++ .../fixtures/head-zero-minor-lock.json | 100 ++ .github/scripts/fixtures/plugin-package.json | 21 + .github/scripts/fixtures/review-hold.json | 33 + .github/scripts/fixtures/review-pass.json | 65 + .github/scripts/fixtures/surface-base.json | 55 + .../fixtures/surface-head-changed.json | 46 + .github/workflows/dependency-auto-merge.yml | 250 ++- .github/workflows/test.yml | 3 + README.md | 20 +- 25 files changed, 3780 insertions(+), 13 deletions(-) create mode 100644 .github/scripts/.prettierrc.json create mode 100644 .github/scripts/dependency-gate.mjs create mode 100644 .github/scripts/dependency-gate.test.mjs create mode 100644 .github/scripts/fixtures/base-lock.json create mode 100644 .github/scripts/fixtures/checks-failed.json create mode 100644 .github/scripts/fixtures/checks-green.json create mode 100644 .github/scripts/fixtures/checks-pending.json create mode 100644 .github/scripts/fixtures/checks-superseded.json create mode 100644 .github/scripts/fixtures/head-engines-lock.json create mode 100644 .github/scripts/fixtures/head-install-script-lock.json create mode 100644 .github/scripts/fixtures/head-major-lock.json create mode 100644 .github/scripts/fixtures/head-new-packages-lock.json create mode 100644 .github/scripts/fixtures/head-pass-lock.json create mode 100644 .github/scripts/fixtures/head-peer-floor-lock.json create mode 100644 .github/scripts/fixtures/head-peer-lock.json create mode 100644 .github/scripts/fixtures/head-registry-lock.json create mode 100644 .github/scripts/fixtures/head-zero-minor-lock.json create mode 100644 .github/scripts/fixtures/plugin-package.json create mode 100644 .github/scripts/fixtures/review-hold.json create mode 100644 .github/scripts/fixtures/review-pass.json create mode 100644 .github/scripts/fixtures/surface-base.json create mode 100644 .github/scripts/fixtures/surface-head-changed.json diff --git a/.github/scripts/.prettierrc.json b/.github/scripts/.prettierrc.json new file mode 100644 index 0000000..a6a6978 --- /dev/null +++ b/.github/scripts/.prettierrc.json @@ -0,0 +1,7 @@ +{ + "endOfLine": "lf", + "tabWidth": 2, + "printWidth": 100, + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/.github/scripts/dependency-gate.mjs b/.github/scripts/dependency-gate.mjs new file mode 100644 index 0000000..d2e208c --- /dev/null +++ b/.github/scripts/dependency-gate.mjs @@ -0,0 +1,1599 @@ +#!/usr/bin/env node +/** + * Dependency gate for Dependabot pull requests (version 2). + * + * One dependency-free script, byte-identical in every plugin repository. The workflow + * `.github/workflows/dependency-auto-merge.yml` calls it; the unit tests in + * `dependency-gate.test.mjs` cover every hold reason and the pass path. + * + * Subcommands: + * - `policy` prints the license policy for actions/dependency-review-action. + * - `surface` records the published surface of a built checkout (untrusted job, read-only). + * - `decide` compares base and head and decides `merge`, `major` or `hold` (trusted job). + * - `route` combines the gate decision with the Dependabot metadata and job results. + * - `wait-ci` waits until every other check on the head commit has finished green. + * + * The script never runs code from the pull request: `decide`, `route` and `wait-ci` read + * lockfiles, package.json files and JSON reports as data. Only `surface` loads built entry + * files, and the workflow runs it in a separate job without write permissions. + */ +import { execFileSync } from 'node:child_process'; +import { readFileSync, writeFileSync, appendFileSync, existsSync, statSync } from 'node:fs'; +import path from 'node:path'; +import process from 'node:process'; +import { setTimeout as sleep } from 'node:timers/promises'; +import { pathToFileURL } from 'node:url'; + +/** Licenses allowed for every dependency (SPDX identifiers). */ +export const ALLOWED_LICENSES = [ + '0BSD', + 'Apache-2.0', + 'BlueOak-1.0.0', + 'BSD-2-Clause', + 'BSD-2-Clause-Views', + 'BSD-3-Clause', + 'CC0-1.0', + 'ISC', + 'MIT', + 'MIT-0', + 'Python-2.0', + 'Unlicense', + 'Zlib', +]; + +/** Licenses allowed only for development dependencies (never shipped to a host). */ +export const DEV_ONLY_LICENSES = ['MPL-2.0', 'CC-BY-3.0', 'CC-BY-4.0']; + +/** + * Packages whose license metadata does not match the allowlist but that are accepted after + * review. Exact names only, matching the `allow-dependencies-licenses` purl semantics of + * actions/dependency-review-action. `@strapi/*` packages are matched by scope in this script + * because Strapi publishes them with `SEE LICENSE IN LICENSE` (MIT core plus an EE folder). + */ +export const LICENSE_EXCEPTIONS = [ + '@img/sharp-libvips-darwin-arm64', + '@img/sharp-libvips-darwin-x64', + '@img/sharp-libvips-linux-arm', + '@img/sharp-libvips-linux-arm64', + '@img/sharp-libvips-linux-ppc64', + '@img/sharp-libvips-linux-riscv64', + '@img/sharp-libvips-linux-s390x', + '@img/sharp-libvips-linux-x64', + '@img/sharp-libvips-linuxmusl-arm64', + '@img/sharp-libvips-linuxmusl-x64', + '@img/sharp-wasm32', + '@img/sharp-win32-arm64', + '@img/sharp-win32-ia32', + '@img/sharp-win32-x64', + 'json-schema', + 'normalize-package-data', + 'npm', +]; + +/** Package scopes accepted regardless of license metadata (see LICENSE_EXCEPTIONS). */ +export const LICENSE_EXCEPTION_SCOPES = ['@strapi/']; + +/** Hold when one update adds more brand-new package names than this. */ +export const MAX_NEW_PACKAGES = 15; + +/** The only registry the lockfile may resolve packages from. */ +export const REGISTRY_PREFIX = 'https://registry.npmjs.org/'; + +const SEVERITY_RANK = { low: 1, moderate: 2, high: 3, critical: 4 }; +const MAX_JSON_BYTES = 64 * 1024 * 1024; + +// --------------------------------------------------------------------------- +// Minimal semver (npm range grammar subset: x-ranges, ~, ^, hyphen, comparators, ||) +// --------------------------------------------------------------------------- + +const VERSION_RE = + /^v?(\d{1,9})\.(\d{1,9})\.(\d{1,9})(?:-([0-9A-Za-z.-]{1,128}))?(?:\+[0-9A-Za-z.-]{1,128})?$/; +const PART = '(\\d{1,9}|[xX*])'; +const TOKEN_RE = new RegExp( + `^(<=|>=|<|>|=|\\^|~>?)?v?${PART}(?:\\.${PART})?(?:\\.${PART})?` + + '(?:-([0-9A-Za-z.-]{1,128}))?(?:\\+[0-9A-Za-z.-]{1,128})?$' +); + +/** + * Parses an exact semver version. + * + * @param {string} input Version such as `1.2.3` or `1.2.3-beta.1`. + * @returns {{major: number, minor: number, patch: number, pre: string[]} | null} Parsed version, + * or null when the input is not an exact version. + */ +export function parseVersion(input) { + if (typeof input !== 'string' || input.length > 300) return null; + const match = VERSION_RE.exec(input.trim()); + if (!match) return null; + return { + major: Number(match[1]), + minor: Number(match[2]), + patch: Number(match[3]), + pre: match[4] ? match[4].split('.') : [], + }; +} + +/** + * Compares two parsed versions with semver precedence (prerelease lower than release). + * + * @param {{major: number, minor: number, patch: number, pre: string[]}} a First version. + * @param {{major: number, minor: number, patch: number, pre: string[]}} b Second version. + * @returns {number} Negative, zero or positive. + */ +export function compareVersions(a, b) { + for (const key of ['major', 'minor', 'patch']) { + if (a[key] !== b[key]) return a[key] - b[key]; + } + if (!a.pre.length || !b.pre.length) return b.pre.length - a.pre.length; + for (let i = 0; i < Math.max(a.pre.length, b.pre.length); i += 1) { + if (a.pre[i] === undefined) return -1; + if (b.pre[i] === undefined) return 1; + if (a.pre[i] === b.pre[i]) continue; + const an = /^\d+$/.test(a.pre[i]); + const bn = /^\d+$/.test(b.pre[i]); + if (an && bn) return Number(a.pre[i]) - Number(b.pre[i]); + if (an) return -1; + if (bn) return 1; + return a.pre[i] < b.pre[i] ? -1 : 1; + } + return 0; +} + +const v = (major, minor, patch, pre = []) => ({ major, minor, patch, pre }); +const isWild = (part) => part === undefined || part === 'x' || part === 'X' || part === '*'; + +/** + * Expands one range token (for example `^1.2`, `>=22`, `<=26.x.x`) into comparators. + * + * @param {string} token Token without spaces. + * @returns {{op: string, ver: object, bound?: boolean}[] | null} Comparators; an empty array + * matches everything, null matches nothing. + * @throws {RangeError} When the token is not valid range syntax. + */ +function expandToken(token) { + const match = TOKEN_RE.exec(token); + if (!match) throw new RangeError(`unsupported range token "${token}"`); + let op = match[1] || ''; + if (op === '~>') op = '~'; + const [maj, min, pat] = [match[2], match[3], match[4]]; + const pre = match[5] ? match[5].split('.') : []; + const M = isWild(maj) ? null : Number(maj); + const m = isWild(min) ? null : Number(min); + const p = isWild(pat) ? null : Number(pat); + const lo = (a, b, c) => ({ op: '>=', ver: v(a, b, c, pre) }); + const hi = (a, b, c) => ({ op: '<', ver: v(a, b, c, ['0']), bound: true }); + + if (op === '' || op === '=') { + if (M === null) return []; + if (m === null) return [lo(M, 0, 0), hi(M + 1, 0, 0)]; + if (p === null) return [lo(M, m, 0), hi(M, m + 1, 0)]; + return [{ op: '=', ver: v(M, m, p, pre) }]; + } + if (op === '~') { + if (M === null) return []; + if (m === null) return [lo(M, 0, 0), hi(M + 1, 0, 0)]; + return [lo(M, m, p ?? 0), hi(M, m + 1, 0)]; + } + if (op === '^') { + if (M === null) return []; + if (m === null) return [lo(M, 0, 0), hi(M + 1, 0, 0)]; + if (M > 0) return [lo(M, m, p ?? 0), hi(M + 1, 0, 0)]; + if (p === null || m > 0) return [lo(0, m, p ?? 0), hi(0, m + 1, 0)]; + return [lo(0, 0, p), hi(0, 0, p + 1)]; + } + if (M === null) return op === '<' || op === '>' ? null : []; + if (op === '>') { + if (m === null) return [lo(M + 1, 0, 0)]; + if (p === null) return [lo(M, m + 1, 0)]; + return [{ op: '>', ver: v(M, m, p, pre) }]; + } + if (op === '>=') return [lo(M, m ?? 0, p ?? 0)]; + if (op === '<') { + if (m === null) return [hi(M, 0, 0)]; + if (p === null) return [hi(M, m, 0)]; + return [{ op: '<', ver: v(M, m, p, pre) }]; + } + // op === '<=' + if (m === null) return [hi(M + 1, 0, 0)]; + if (p === null) return [hi(M, m + 1, 0)]; + return [{ op: '<=', ver: v(M, m, p, pre) }]; +} + +/** + * Parses an npm version range into comparator sets (OR of ANDs). + * + * @param {string} range Range such as `^22.22.2 || >=24.15.0` or `>=22.0.0 <=26.x.x`. + * @returns {Array>} Comparator sets. + * @throws {RangeError} When the range is not supported syntax or longer than 512 characters. + */ +export function parseRange(range) { + if (typeof range !== 'string' || range.length > 512) { + throw new RangeError('range must be a string of at most 512 characters'); + } + const sets = []; + for (const raw of range.split('||')) { + let part = raw.trim(); + const hyphen = /^(\S+)\s+-\s+(\S+)$/.exec(part); + if (hyphen) { + const upper = expandToken(hyphen[2]); + const isPartial = upper && upper.length === 2; + part = `>=${hyphen[1]} ${isPartial ? `<${fmt(upper[1].ver)}` : `<=${hyphen[2]}`}`; + } + part = part.replace(/(<=|>=|<|>|=|\^|~>?)\s+/g, '$1'); + const tokens = part === '' ? [] : part.split(/\s+/); + let set = []; + let empty = false; + for (const token of tokens) { + const expanded = expandToken(token); + if (expanded === null) empty = true; + else set = set.concat(expanded); + } + if (!empty) sets.push(set); + } + return sets; +} + +/** + * Formats a parsed version back into a string. + * + * @param {{major: number, minor: number, patch: number, pre: string[]}} ver Parsed version. + * @returns {string} Version string. + */ +function fmt(ver) { + const base = `${ver.major}.${ver.minor}.${ver.patch}`; + return ver.pre.length ? `${base}-${ver.pre.join('.')}` : base; +} + +/** + * Tests one comparator. + * + * @param {object} ver Parsed version. + * @param {{op: string, ver: object}} comp Comparator. + * @returns {boolean} True when the version satisfies the comparator. + */ +function testComparator(ver, comp) { + const c = compareVersions(ver, comp.ver); + switch (comp.op) { + case '=': + return c === 0; + case '>': + return c > 0; + case '>=': + return c >= 0; + case '<': + return c < 0; + default: + return c <= 0; + } +} + +/** + * Checks whether a version satisfies a range, with npm's prerelease rule: a prerelease only + * matches when a comparator in the same set names the same major.minor.patch with a prerelease. + * + * @param {string} version Exact version. + * @param {string} range npm range. + * @returns {boolean} True when satisfied. + * @throws {RangeError} When the version or range cannot be parsed. + */ +export function satisfies(version, range) { + const ver = parseVersion(version); + if (!ver) throw new RangeError(`invalid version "${version}"`); + return parseRange(range).some((set) => { + if (!set.every((comp) => testComparator(ver, comp))) return false; + if (!ver.pre.length) return true; + return set.some( + (comp) => + !comp.bound && + comp.ver.pre.length > 0 && + comp.ver.major === ver.major && + comp.ver.minor === ver.minor && + comp.ver.patch === ver.patch + ); + }); +} + +/** + * Returns the lowest release version that satisfies a range. + * + * @param {string} range npm range. + * @returns {string | null} Lowest version, or null when nothing satisfies the range. + * @throws {RangeError} When the range cannot be parsed. + */ +export function minVersion(range) { + let best = null; + for (const set of parseRange(range)) { + let low = v(0, 0, 0); + for (const comp of set) { + let candidate = null; + if (comp.op === '>=' || comp.op === '=') candidate = { ...comp.ver, pre: [] }; + if (comp.op === '>') candidate = v(comp.ver.major, comp.ver.minor, comp.ver.patch + 1); + if (candidate && compareVersions(candidate, low) > 0) low = candidate; + } + if (!set.every((comp) => testComparator(low, comp))) continue; + if (!best || compareVersions(low, best) < 0) best = low; + } + return best ? fmt(best) : null; +} + +/** + * Builds sample Node versions that a plugin's `engines.node` range supports: every major from + * the lowest bound to the highest bound (two majors past the highest named one when the range + * is open), at x.0.0, at each named bound and at a late minor of each major. + * + * @param {string} range The plugin's `engines.node`. + * @returns {string[]} Sorted sample versions that satisfy the range. + * @throws {RangeError} When the range cannot be parsed. + */ +export function nodeSamples(range) { + const sets = parseRange(range); + const named = []; + let open = false; + for (const set of sets) { + if (!set.some((comp) => comp.op === '<' || comp.op === '<=' || comp.op === '=')) open = true; + for (const comp of set) named.push(comp.ver); + } + if (!named.length) return []; + const majors = named.map((ver) => ver.major); + const lowest = Math.min(...majors); + const highest = Math.max(...majors) + (open ? 2 : 0); + const candidates = new Set(); + for (let major = lowest; major <= highest; major += 1) { + candidates.add(`${major}.0.0`); + candidates.add(`${major}.99.0`); + } + for (const ver of named) { + candidates.add(fmt({ ...ver, pre: [] })); + candidates.add(`${ver.major}.${ver.minor}.${ver.patch + 1}`); + } + return [...candidates] + .filter((sample) => satisfies(sample, range)) + .sort((a, b) => compareVersions(parseVersion(a), parseVersion(b))); +} + +// --------------------------------------------------------------------------- +// SPDX license expressions +// --------------------------------------------------------------------------- + +/** + * Evaluates an SPDX license expression against an allowlist. `OR` needs one allowed side, + * `AND` needs both, `WITH` exceptions are ignored, `+` is accepted as the same license. + * + * @param {string} expression SPDX expression, for example `(MIT OR Apache-2.0)`. + * @param {string[]} allowed Allowed SPDX identifiers. + * @returns {boolean} True when the expression is satisfied by the allowlist. + * @throws {SyntaxError} When the expression cannot be parsed. + */ +export function licenseAllowed(expression, allowed) { + if (typeof expression !== 'string' || expression.length > 512) { + throw new SyntaxError('license must be a string of at most 512 characters'); + } + const tokens = expression.match(/\(|\)|[^\s()]+/g) || []; + const allow = new Set(allowed.map((id) => id.toLowerCase())); + let pos = 0; + const peek = () => tokens[pos]; + const parsePrimary = () => { + const token = tokens[pos++]; + if (token === undefined) throw new SyntaxError('unexpected end of license expression'); + if (token === '(') { + const value = parseOr(); + if (tokens[pos++] !== ')') throw new SyntaxError('missing ) in license expression'); + return value; + } + if (/^(AND|OR|WITH|\))$/i.test(token)) throw new SyntaxError(`unexpected "${token}"`); + let value = allow.has(token.replace(/\+$/, '').toLowerCase()); + if (peek() && /^WITH$/i.test(peek())) { + pos += 2; + value = value && tokens[pos - 1] !== undefined; + } + return value; + }; + const parseAnd = () => { + let value = parsePrimary(); + while (peek() && /^AND$/i.test(peek())) { + pos += 1; + value = parsePrimary() && value; + } + return value; + }; + const parseOr = () => { + let value = parseAnd(); + while (peek() && /^OR$/i.test(peek())) { + pos += 1; + value = parseAnd() || value; + } + return value; + }; + const result = parseOr(); + if (pos !== tokens.length) throw new SyntaxError('trailing tokens in license expression'); + return result; +} + +/** + * Tells whether a package is exempt from the license allowlist. + * + * @param {string} name npm package name. + * @returns {boolean} True for the reviewed exceptions. + */ +export function licenseException(name) { + return ( + LICENSE_EXCEPTIONS.includes(name) || + LICENSE_EXCEPTION_SCOPES.some((scope) => name.startsWith(scope)) + ); +} + +// --------------------------------------------------------------------------- +// Lockfile helpers +// --------------------------------------------------------------------------- + +/** + * Derives the package name of a lockfile `packages` key. + * + * @param {string} key Key such as `node_modules/a/node_modules/@s/b`. + * @param {{name?: string}} entry Lockfile entry. + * @returns {string} Package name. + */ +export function packageName(key, entry) { + if (entry && typeof entry.name === 'string') return entry.name; + const index = key.lastIndexOf('node_modules/'); + return index === -1 ? key : key.slice(index + 'node_modules/'.length); +} + +/** + * Returns the `packages` map of a lockfile (v2 or v3). + * + * @param {object} lock Parsed package-lock.json. + * @returns {Record} Packages keyed by install path. + * @throws {Error} For lockfile version 1 or a missing `packages` map. + */ +export function lockPackages(lock) { + if (!lock || typeof lock.packages !== 'object' || lock.packages === null) { + throw new Error('package-lock.json has no "packages" map (lockfileVersion 2 or 3 needed)'); + } + return lock.packages; +} + +/** + * Finds the entry npm would resolve for `name` when required from the package at `fromKey`, + * walking up the node_modules folders like Node does. + * + * @param {Record} packages Lockfile packages map. + * @param {string} fromKey Install path of the requiring package ('' for the root). + * @param {string} name Package name to resolve. + * @returns {{key: string, entry: object} | null} Resolved entry, or null. + */ +export function resolveFrom(packages, fromKey, name) { + let dir = fromKey; + for (;;) { + const key = dir ? `${dir}/node_modules/${name}` : `node_modules/${name}`; + if (packages[key] && !packages[key].link) return { key, entry: packages[key] }; + if (packages[key] && packages[key].link && packages[packages[key].resolved]) { + return { key, entry: packages[packages[key].resolved] }; + } + if (!dir) return null; + const index = dir.lastIndexOf('/node_modules/'); + dir = index === -1 ? '' : dir.slice(0, index); + if (dir && !dir.includes('node_modules/')) dir = ''; + } +} + +/** + * Computes the difference between two lockfiles. + * + * @param {object} baseLock Parsed base package-lock.json. + * @param {object} headLock Parsed head package-lock.json. + * @returns {{added: Array, changed: Array, removed: string[], newNames: string[]}} Entries that + * were added or changed (with `key`, `name`, `entry`, `before`, `beforeKey`) and names new to + * the tree. For an added key, `before` is the base entry of the same name at another install + * path (same version preferred), so a package that only moved is compared with itself. + */ +export function diffLockfiles(baseLock, headLock) { + const base = lockPackages(baseLock); + const head = lockPackages(headLock); + const byName = new Map(); + for (const [key, entry] of Object.entries(base)) { + if (key === '') continue; + const name = packageName(key, entry); + if (!byName.has(name)) byName.set(name, []); + byName.get(name).push({ key, entry }); + } + const added = []; + const changed = []; + const newNames = new Set(); + for (const [key, entry] of Object.entries(head)) { + if (key === '') continue; + const name = packageName(key, entry); + if (!byName.has(name)) newNames.add(name); + const before = base[key]; + if (!before) { + const same = byName.get(name) || []; + const prev = same.find((item) => item.entry.version === entry.version) || same[0] || null; + added.push({ key, name, entry, before: prev && prev.entry, beforeKey: prev && prev.key }); + } else if ( + before.version !== entry.version || + before.resolved !== entry.resolved || + before.integrity !== entry.integrity + ) { + changed.push({ key, name, entry, before, beforeKey: key }); + } + } + const removed = Object.keys(base).filter((key) => key !== '' && !head[key]); + return { added, changed, removed, newNames: [...newNames].sort() }; +} + +/** + * Reads `engines.node` from a lockfile entry or registry manifest. + * + * @param {object} manifest Entry with an optional `engines` field. + * @returns {string | null} The node range, or null when none is declared. + */ +function enginesNode(manifest) { + const engines = manifest && manifest.engines; + if (engines && typeof engines === 'object' && !Array.isArray(engines)) { + return typeof engines.node === 'string' ? engines.node : null; + } + return null; +} + +/** + * Tells whether a lockfile entry is installed only for development. + * + * @param {object} entry Lockfile entry. + * @returns {boolean} True for `dev` entries. + */ +const isDev = (entry) => entry.dev === true; + +// --------------------------------------------------------------------------- +// Checks. Each returns a list of hold reasons: { code, message }. +// --------------------------------------------------------------------------- + +const reason = (code, message) => ({ code, message }); + +/** + * Supply-chain checks on the lockfile diff: install scripts, number of new packages and the + * registry every changed entry resolves from. + * + * @param {object} diff Result of diffLockfiles. + * @param {object} baseLock Parsed base lockfile. + * @param {{maxNewPackages?: number}} [options] Thresholds. + * @returns {{holds: object[], notes: string[]}} Hold reasons and informational notes. + */ +export function checkLockfileDanger(diff, baseLock, options = {}) { + const max = options.maxNewPackages ?? MAX_NEW_PACKAGES; + const base = lockPackages(baseLock); + const scripted = new Set( + Object.entries(base) + .filter(([, entry]) => entry.hasInstallScript) + .map(([key, entry]) => packageName(key, entry)) + ); + const holds = []; + const notes = []; + for (const item of [...diff.added, ...diff.changed]) { + const { entry, name } = item; + const label = `${name}@${entry.version ?? '?'}`; + if (entry.hasInstallScript) { + if (!scripted.has(name)) { + holds.push(reason('install-script', `${label} adds an install script (hasInstallScript).`)); + } else notes.push(`${label} keeps its existing install script.`); + } + if (entry.link || entry.inBundle) continue; + if (typeof entry.resolved !== 'string' || !entry.resolved.startsWith(REGISTRY_PREFIX)) { + holds.push( + reason('registry', `${label} does not resolve from ${REGISTRY_PREFIX} (${entry.resolved})`) + ); + } else if (typeof entry.integrity !== 'string' || !/^sha512-/.test(entry.integrity)) { + holds.push(reason('integrity', `${label} has no sha512 integrity hash in the lockfile.`)); + } + } + if (diff.newNames.length > max) { + holds.push( + reason( + 'new-packages', + `${diff.newNames.length} packages are new to the tree (limit ${max}): ` + + `${diff.newNames.slice(0, 20).join(', ')}${diff.newNames.length > 20 ? ', ...' : ''}` + ) + ); + } + return { holds, notes }; +} + +/** + * Compatibility checks for every added or changed entry: `engines.node` must keep covering the + * Node versions the plugin supports, and `peerDependencies` must stay satisfied by the installed + * tree and, for production packages, by the plugin's own peer floor. + * + * @param {object} diff Result of diffLockfiles. + * @param {object} context Inputs. + * @param {object} context.baseLock Parsed base lockfile. + * @param {object} context.headLock Parsed head lockfile. + * @param {object} context.headPkg Parsed head package.json of the plugin. + * @param {Record} [context.registry] Registry manifests keyed `name@version` + * (from `npm view`), preferred over lockfile fields when present. + * @returns {{holds: object[], notes: string[]}} Hold reasons and notes. + */ +export function checkCompatibility(diff, context) { + const { baseLock, headLock, headPkg } = context; + const registry = context.registry || {}; + const base = lockPackages(baseLock); + const head = lockPackages(headLock); + const holds = []; + const notes = []; + const supported = headPkg.engines && headPkg.engines.node; + let samples = []; + if (supported) { + try { + samples = nodeSamples(supported); + } catch (error) { + holds.push(reason('engines', `The plugin's engines.node cannot be parsed: ${error.message}`)); + } + } + const pluginPeers = headPkg.peerDependencies || {}; + const manifest = (name, entry) => ({ ...entry, ...(registry[`${name}@${entry.version}`] || {}) }); + + for (const item of [...diff.added, ...diff.changed]) { + const now = manifest(item.name, item.entry); + const before = item.before ? manifest(item.name, item.before) : null; + const label = `${item.name}@${now.version}`; + + // engines.node + const newRange = enginesNode(now); + const oldRange = before ? enginesNode(before) : null; + if (newRange && newRange !== oldRange && samples.length) { + try { + const lost = samples.filter((sample) => { + if (satisfies(sample, newRange)) return false; + if (!oldRange) return true; + try { + return satisfies(sample, oldRange); + } catch { + return true; + } + }); + if (lost.length) { + holds.push( + reason( + 'engines', + `${label} declares engines.node "${newRange}"` + + `${oldRange ? ` (was "${oldRange}")` : ''}, which excludes Node ` + + `${lost.join(', ')} supported by this plugin ("${supported}").` + ) + ); + } + } catch (error) { + holds.push(reason('engines', `${label} engines.node "${newRange}": ${error.message}`)); + } + } + + // peerDependencies + const peers = now.peerDependencies || {}; + const oldPeers = (before && before.peerDependencies) || {}; + const meta = now.peerDependenciesMeta || {}; + for (const [peer, range] of Object.entries(peers)) { + if (typeof range !== 'string') continue; + const optional = Boolean(meta[peer] && meta[peer].optional); + const installed = resolveFrom(head, item.key, peer); + const oldInstalled = item.before ? resolveFrom(base, item.beforeKey, peer) : null; + const oldRange2 = oldPeers[peer]; + let okNow; + let okBefore; + try { + okNow = installed ? satisfies(installed.entry.version, range) : optional; + } catch { + okNow = false; + } + try { + okBefore = + typeof oldRange2 === 'string' + ? oldInstalled + ? satisfies(oldInstalled.entry.version, oldRange2) + : Boolean(before.peerDependenciesMeta?.[peer]?.optional) + : false; + } catch { + okBefore = false; + } + if (!okNow && (okBefore || typeof oldRange2 !== 'string')) { + holds.push( + reason( + 'peer', + `${label} needs peer ${peer}@"${range}"` + + `${oldRange2 ? ` (was "${oldRange2}")` : ' (new peer)'}, but the tree has ` + + `${installed ? `${peer}@${installed.entry.version}` : 'none installed'}.` + ) + ); + continue; + } + if (!okNow) notes.push(`${label}: peer ${peer}@"${range}" was already unmet before.`); + if (isDev(item.entry) || typeof pluginPeers[peer] !== 'string' || range === oldRange2) { + continue; + } + try { + const floor = minVersion(pluginPeers[peer]); + const floorOk = floor ? satisfies(floor, range) : true; + const floorOkBefore = + floor && typeof oldRange2 === 'string' ? satisfies(floor, oldRange2) : true; + if (!floorOk && floorOkBefore) { + holds.push( + reason( + 'peer-floor', + `${label} is shipped to hosts and needs ${peer}@"${range}", above this ` + + `plugin's declared peer floor ${peer}@${floor} ("${pluginPeers[peer]}").` + ) + ); + } + } catch (error) { + holds.push(reason('peer-floor', `${label} peer ${peer}: ${error.message}`)); + } + } + } + return { holds, notes }; +} + +/** + * Direct dependency version changes, with major and 0.x checks. + * + * @param {object} context Inputs. + * @param {object} context.baseLock Parsed base lockfile. + * @param {object} context.headLock Parsed head lockfile. + * @param {object} context.headPkg Parsed head package.json. + * @returns {{holds: object[], majors: string[], direct: Array}} Hold reasons, major updates and + * the list of direct updates `{ name, type, from, to }`. + */ +export function checkDirectUpdates(context) { + const base = lockPackages(context.baseLock); + const head = lockPackages(context.headLock); + const holds = []; + const majors = []; + const direct = []; + const types = ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']; + const seen = new Set(); + for (const type of types) { + for (const name of Object.keys(context.headPkg[type] || {})) { + if (seen.has(name)) continue; + seen.add(name); + const before = base[`node_modules/${name}`]; + const after = head[`node_modules/${name}`]; + if (!before || !after || before.version === after.version) continue; + direct.push({ name, type, from: before.version, to: after.version }); + const a = parseVersion(before.version); + const b = parseVersion(after.version); + if (!a || !b) { + holds.push( + reason('version', `${name}: cannot compare ${before.version} -> ${after.version}`) + ); + continue; + } + if (a.major !== b.major) majors.push(`${name} ${before.version} -> ${after.version}`); + else if ( + type === 'dependencies' && + a.major === 0 && + (a.minor !== b.minor || (a.minor === 0 && a.patch !== b.patch)) + ) { + holds.push( + reason( + 'zero-minor', + `${name} ${before.version} -> ${after.version} is a runtime dependency on 0.x; ` + + 'a 0.x minor (or 0.0.x patch) bump is breaking by semver convention.' + ) + ); + } + } + } + return { holds, majors, direct }; +} + +const BREAKING_RE = /(? !before.has(file)); + const minus = [...before].filter((file) => !after.has(file)); + if (plus.length || minus.length) { + holds.push( + reason( + 'surface', + `npm pack file list changed: ${plus.map((f) => `+${f}`).join(', ')}` + + `${plus.length && minus.length ? ', ' : ''}${minus.map((f) => `-${f}`).join(', ')}` + ) + ); + } + } else if (stableStringify(a) !== stableStringify(b)) { + holds.push(reason('surface', `Published "${key}" changed between base and head.`)); + } + } + return holds; +} + +/** + * JSON.stringify with sorted object keys. + * + * @param {unknown} value Any JSON value. + * @returns {string} Canonical JSON. + */ +export function stableStringify(value) { + if (Array.isArray(value)) return `[${value.map(stableStringify).join(',')}]`; + if (value && typeof value === 'object') { + const keys = Object.keys(value).sort(); + return `{${keys.map((k) => `${JSON.stringify(k)}:${stableStringify(value[k])}`).join(',')}}`; + } + return JSON.stringify(value === undefined ? null : value); +} + +/** + * Danger checks on the dependency-graph comparison (the data behind + * actions/dependency-review-action): vulnerabilities of moderate or higher and licenses outside + * the allowlist. MPL-2.0 and CC-BY are accepted for development dependencies only. + * + * @param {Array | null} changes Response of `GET /repos/{repo}/dependency-graph/compare/{basehead}`. + * @returns {{holds: object[], notes: string[]}} Hold reasons and notes. + */ +export function checkDependencyReview(changes) { + if (!Array.isArray(changes)) { + return { + holds: [reason('dependency-review', 'The dependency-graph comparison is not available.')], + notes: [], + }; + } + const holds = []; + const notes = []; + for (const change of changes) { + if (change.change_type !== 'added') continue; + const label = `${change.name}@${change.version}`; + for (const vuln of change.vulnerabilities || []) { + if ((SEVERITY_RANK[vuln.severity] || 0) >= SEVERITY_RANK.moderate) { + holds.push( + reason( + 'vulnerability', + `${label} has a ${vuln.severity} advisory ${vuln.advisory_ghsa_id}: ${vuln.advisory_summary}` + ) + ); + } + } + const license = change.license; + if (licenseException(change.name)) continue; + if (license === null || license === undefined || license === 'NOASSERTION') { + notes.push(`${label}: no license detected (not blocking, as in dependency-review-action).`); + continue; + } + const dev = change.scope === 'development'; + const allowed = dev ? [...ALLOWED_LICENSES, ...DEV_ONLY_LICENSES] : ALLOWED_LICENSES; + let ok; + try { + ok = licenseAllowed(license, allowed); + } catch { + ok = false; + } + if (!ok) { + holds.push( + reason('license', `${label} (${change.scope || 'unknown'} scope) has license "${license}".`) + ); + } + } + return { holds, notes }; +} + +/** + * Runs every check and returns the decision. + * + * @param {object} input Inputs (all data, no code from the PR is executed). + * @param {object} input.baseLock Parsed merge-base package-lock.json. + * @param {object} input.headLock Parsed head package-lock.json. + * @param {object} input.basePkg Parsed merge-base package.json. + * @param {object} input.headPkg Parsed head package.json. + * @param {object | null} input.baseSurface Surface of the merge base, or null. + * @param {object | null} input.headSurface Surface of the head, or null. + * @param {string} input.prBody Dependabot PR body. + * @param {Array | null} input.reviewChanges Dependency-graph comparison, or null. + * @param {string} input.reviewOutcome Outcome of actions/dependency-review-action. + * @param {number} input.signaturesExit Exit code of `npm audit signatures`. + * @param {Record} [input.registry] `npm view` manifests keyed `name@version`. + * @param {number} [input.maxNewPackages] Threshold for new packages. + * @returns {{decision: 'merge' | 'hold' | 'major', reasons: object[], notes: string[], + * majors: string[], direct: Array}} Decision with reasons. + */ +export function decide(input) { + const reasons = []; + const notes = []; + let diff; + try { + diff = diffLockfiles(input.baseLock, input.headLock); + } catch (error) { + return { + decision: 'hold', + reasons: [reason('lockfile', error.message)], + notes, + majors: [], + direct: [], + }; + } + const direct = checkDirectUpdates(input); + reasons.push(...direct.holds); + const compat = checkCompatibility(diff, input); + reasons.push(...compat.holds); + notes.push(...compat.notes); + const danger = checkLockfileDanger(diff, input.baseLock, input); + reasons.push(...danger.holds); + notes.push(...danger.notes); + reasons.push(...checkBreakingText(input.prBody)); + reasons.push(...checkSurface(input.baseSurface, input.headSurface)); + const review = checkDependencyReview(input.reviewChanges); + reasons.push(...review.holds); + notes.push(...review.notes); + if (input.reviewOutcome !== 'success') { + reasons.push( + reason( + 'dependency-review', + `actions/dependency-review-action finished with "${input.reviewOutcome}" (see job summary).` + ) + ); + } + if (input.signaturesExit !== 0) { + reasons.push( + reason('signatures', '`npm audit signatures` reported missing or invalid signatures.') + ); + } + for (const field of ['peerDependencies', 'engines']) { + if (stableStringify(input.basePkg[field]) !== stableStringify(input.headPkg[field])) { + reasons.push(reason('surface', `package.json "${field}" changed in this update.`)); + } + } + const decision = direct.majors.length ? 'major' : reasons.length ? 'hold' : 'merge'; + return { decision, reasons, notes, majors: direct.majors, direct: direct.direct }; +} + +/** + * Combines the gate decision, the Dependabot metadata and the job results into one action. + * Only an explicit patch or minor update with a green verify job and a `merge` decision may go on + * to wait for CI and merge. + * + * @param {object} input Inputs. + * @param {string} input.updateType `update-type` from dependabot/fetch-metadata. + * @param {string} input.verifyResult Result of the verify job. + * @param {string} input.gateResult Result of the gate job. + * @param {string} input.decision Decision of the gate job. + * @param {object[]} input.reasons Hold reasons of the gate job. + * @returns {{action: 'merge' | 'hold' | 'major', reasons: object[]}} The action to take. + */ +export function route(input) { + if (input.updateType === 'version-update:semver-major' || input.decision === 'major') { + return { action: 'major', reasons: [] }; + } + const reasons = []; + if (input.verifyResult !== 'success') { + reasons.push(reason('verify', `The verify job finished with "${input.verifyResult}".`)); + } + if (input.gateResult !== 'success') { + reasons.push(reason('gate', `The dependency gate job finished with "${input.gateResult}".`)); + } + const known = ['version-update:semver-patch', 'version-update:semver-minor']; + if (!known.includes(input.updateType)) { + reasons.push( + reason('update-type', `Dependabot reported update-type "${input.updateType || 'none'}".`) + ); + } + if (input.gateResult === 'success' && input.decision !== 'merge') { + reasons.push(...(Array.isArray(input.reasons) ? input.reasons : [])); + if (!input.reasons || !input.reasons.length) { + reasons.push(reason('gate', `Gate decision "${input.decision}".`)); + } + } + return reasons.length ? { action: 'hold', reasons } : { action: 'merge', reasons }; +} + +// --------------------------------------------------------------------------- +// CI status evaluation for wait-ci +// --------------------------------------------------------------------------- + +const OK_CONCLUSIONS = new Set(['success', 'skipped', 'neutral']); + +/** + * Evaluates the state of every other check on the head commit. + * + * @param {object} input Data from the GitHub REST API. + * @param {Array} input.runs `workflow_runs` for the head SHA. + * @param {Array} input.checkRuns `check_runs` for the head SHA (latest per name). + * @param {{state?: string, total_count?: number, statuses?: Array}} [input.status] Combined status. + * @param {number} input.ownWorkflowId Workflow id of this gate workflow (excluded). + * @returns {{state: 'success' | 'pending' | 'failure', failing: string[], pending: string[], + * counted: number}} Evaluation. + */ +export function evaluateChecks(input) { + const own = (input.runs || []).filter((run) => run.workflow_id === input.ownWorkflowId); + const ownSuites = new Set(own.map((run) => run.check_suite_id)); + const latest = new Map(); + for (const run of input.runs || []) { + if (run.workflow_id === input.ownWorkflowId) continue; + const key = `${run.workflow_id}:${run.event}`; + const prev = latest.get(key); + const newer = + !prev || + run.run_number > prev.run_number || + (run.run_number === prev.run_number && (run.run_attempt || 1) > (prev.run_attempt || 1)); + if (newer) latest.set(key, run); + } + const latestSuites = new Set([...latest.values()].map((run) => run.check_suite_id)); + const actionsSuites = new Set((input.runs || []).map((run) => run.check_suite_id)); + const failing = []; + const pending = []; + for (const run of latest.values()) { + const label = `workflow "${run.name}" (${run.event})`; + if (run.status !== 'completed') pending.push(label); + else if (!OK_CONCLUSIONS.has(run.conclusion)) failing.push(`${label}: ${run.conclusion}`); + } + for (const check of input.checkRuns || []) { + const suite = check.check_suite && check.check_suite.id; + if (ownSuites.has(suite)) continue; + // Check runs of superseded workflow runs are represented by their latest run. + if (actionsSuites.has(suite) && !latestSuites.has(suite)) continue; + const label = `check "${check.name}"`; + if (check.status !== 'completed') pending.push(label); + else if (!OK_CONCLUSIONS.has(check.conclusion)) failing.push(`${label}: ${check.conclusion}`); + } + const status = input.status || {}; + if (status.total_count > 0) { + for (const item of status.statuses || []) { + if (item.state === 'pending') pending.push(`status "${item.context}"`); + else if (item.state !== 'success') failing.push(`status "${item.context}": ${item.state}`); + } + } + const counted = latest.size; + if (failing.length) return { state: 'failure', failing, pending, counted }; + if (pending.length || counted === 0) return { state: 'pending', failing, pending, counted }; + return { state: 'success', failing, pending, counted }; +} + +/** + * Calls the GitHub REST API. + * + * @param {string} route Path such as `/repos/o/r/actions/runs/1`. + * @param {string} token GITHUB_TOKEN. + * @returns {Promise} Parsed JSON. + * @throws {Error} When the response is not 2xx. + * @sideeffect Network request to api.github.com. + */ +async function githubApi(route, token) { + const base = process.env.GITHUB_API_URL || 'https://api.github.com'; + const response = await globalThis.fetch(`${base}${route}`, { + headers: { + accept: 'application/vnd.github+json', + authorization: `Bearer ${token}`, + 'x-github-api-version': '2022-11-28', + }, + }); + if (!response.ok) throw new Error(`GitHub API ${route} answered ${response.status}`); + return response.json(); +} + +/** + * Fetches all pages of a list endpoint. + * + * @param {string} route Path with query string, without page parameters. + * @param {string} key Array property of the response. + * @param {string} token GITHUB_TOKEN. + * @returns {Promise} All items (at most 1000). + * @sideeffect Network requests to api.github.com. + */ +async function githubList(route, key, token) { + const items = []; + for (let page = 1; page <= 10; page += 1) { + const sep = route.includes('?') ? '&' : '?'; + const body = await githubApi(`${route}${sep}per_page=100&page=${page}`, token); + const list = body[key] || []; + items.push(...list); + if (list.length < 100) break; + } + return items; +} + +/** + * Polls the head commit until every other workflow run, check run and commit status has + * finished. Success needs two consecutive green polls, so a workflow that starts late is seen. + * + * @param {object} options Options. + * @param {string} options.repo `owner/name`. + * @param {string} options.sha Head commit SHA. + * @param {number} options.runId This workflow run id. + * @param {string} options.token GITHUB_TOKEN with actions, checks and statuses read. + * @param {number} [options.timeoutMs] Give up after this long (default 60 minutes). + * @param {number} [options.intervalMs] Poll interval (default 30 seconds). + * @param {Function} [options.log] Logger. + * @returns {Promise<{state: string, failing: string[], pending: string[]}>} Final state: + * `success`, `failure` or `timeout`. + * @sideeffect Network requests to api.github.com; waits. + */ +export async function waitForChecks(options) { + const { repo, sha, runId, token } = options; + const log = options.log || (() => {}); + const timeoutMs = options.timeoutMs ?? 60 * 60 * 1000; + const intervalMs = options.intervalMs ?? 30 * 1000; + const self = await githubApi(`/repos/${repo}/actions/runs/${runId}`, token); + const deadline = Date.now() + timeoutMs; + let greens = 0; + let last = { state: 'pending', failing: [], pending: [] }; + while (Date.now() < deadline) { + const runs = await githubList( + `/repos/${repo}/actions/runs?head_sha=${sha}`, + 'workflow_runs', + token + ); + const checkRuns = await githubList( + `/repos/${repo}/commits/${sha}/check-runs`, + 'check_runs', + token + ); + const status = await githubApi(`/repos/${repo}/commits/${sha}/status`, token); + last = evaluateChecks({ runs, checkRuns, status, ownWorkflowId: self.workflow_id }); + log(`CI state ${last.state}; pending: ${last.pending.length}; failing: ${last.failing.length}`); + if (last.state === 'failure') return last; + greens = last.state === 'success' ? greens + 1 : 0; + if (greens >= 2) return last; + await sleep(intervalMs); + } + return { ...last, state: 'timeout' }; +} + +// --------------------------------------------------------------------------- +// Published surface (runs in the read-only surface job) +// --------------------------------------------------------------------------- + +/** + * Describes the shape of a loaded module: types of top-level exports and the keys of nested + * objects (two levels), without values. + * + * @param {unknown} value Module value. + * @param {number} [depth] Remaining depth. + * @returns {unknown} Shape. + */ +export function describeShape(value, depth = 2) { + if (Array.isArray(value)) return 'array'; + if (value === null) return 'null'; + const type = typeof value; + if ((type !== 'object' && type !== 'function') || depth === 0) return type; + const keys = Object.keys(value).sort().slice(0, 200); + if (type === 'function' && !keys.length) return 'function'; + const shape = {}; + for (const key of keys) shape[key] = describeShape(value[key], depth - 1); + return type === 'function' ? { '(function)': shape } : shape; +} + +/** + * Lists the static export names of an ES module file (bundler output). + * + * @param {string} source File content. + * @returns {string[]} Sorted export names. + */ +export function staticExports(source) { + const names = new Set(); + const text = source.slice(0, 5 * 1024 * 1024); + for (const match of text.matchAll(/^export\s*\{([^}]{0,5000})\}/gm)) { + for (const part of match[1].split(',')) { + const name = part + .trim() + .split(/\s+as\s+/) + .pop(); + if (name) names.add(name); + } + } + const declRe = + /^export\s+(?:default|(?:async\s+)?function\*?\s+(\w+)|class\s+(\w+)|(?:const|let|var)\s+(\w+))/gm; + for (const match of text.matchAll(declRe)) { + names.add(match[1] || match[2] || match[3] || 'default'); + } + if (/^export\s*\*\s*from/m.test(text)) names.add('*'); + return [...names].sort(); +} + +/** + * Collects the files referenced by a package.json `exports` map. + * + * @param {unknown} exportsField `exports` value. + * @returns {string[]} Relative file paths. + */ +function exportTargets(exportsField) { + const out = new Set(); + const walk = (value, condition) => { + if (typeof value === 'string') { + if (condition !== 'source' && condition !== 'types') out.add(value); + } else if (value && typeof value === 'object') { + for (const [key, inner] of Object.entries(value)) walk(inner, key); + } + }; + walk(exportsField, ''); + return [...out].sort(); +} + +/** + * Records the published surface of a built checkout: normalized `npm pack` file list, the + * package.json fields hosts depend on, static exports of every entry file and the runtime shape + * of every CommonJS entry. + * + * @param {string} dir Checkout directory (already installed and built). + * @returns {object} Surface description. + * @throws {Error} When `npm pack --dry-run` fails. + * @sideeffect Runs `npm pack --dry-run --ignore-scripts` and loads built entry files in child + * processes (code from the checkout runs here; the workflow gives this job no write access). + */ +export function recordSurface(dir) { + const pkg = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8')); + const packJson = execFileSync('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], { + cwd: dir, + encoding: 'utf8', + maxBuffer: 64 * 1024 * 1024, + }); + const packed = JSON.parse(packJson); + const files = [ + ...new Set(packed.flatMap((entry) => entry.files.map((f) => normalizePackPath(f.path)))), + ].sort(); + const fields = {}; + for (const key of ['main', 'module', 'types', 'type', 'bin', 'exports', 'files']) { + fields[key] = pkg[key] ?? null; + } + const entries = {}; + const shapes = {}; + for (const target of exportTargets(pkg.exports)) { + const file = path.join(dir, target); + if (!/\.(c|m)?js$/.test(target) || !existsSync(file) || statSync(file).size > 20e6) { + entries[target] = existsSync(file) ? 'not-js' : 'missing'; + continue; + } + entries[target] = staticExports(readFileSync(file, 'utf8')); + if (target.endsWith('.mjs')) continue; + shapes[target] = loadShape(dir, target); + } + return { + files, + package: fields, + peerDependencies: pkg.peerDependencies ?? null, + engines: pkg.engines ?? null, + entries, + shapes, + }; +} + +/** + * Loads one CommonJS entry in a child process and returns its shape, or an error code. + * + * @param {string} dir Checkout directory. + * @param {string} target Relative entry path. + * @returns {unknown} Shape or `{ error: }`. + * @sideeffect Starts a Node.js child process that requires the entry (60 s timeout). + */ +function loadShape(dir, target) { + const self = import.meta.url; + const code = + `import(${JSON.stringify(self)}).then(({ describeShape }) => {` + + `const mod = require(${JSON.stringify(path.resolve(dir, target))});` + + 'process.stdout.write(JSON.stringify(describeShape(mod)));' + + '}).catch((e) => { process.stdout.write(JSON.stringify({ error: e.code || e.name })); });'; + try { + const out = execFileSync(process.execPath, ['-e', code], { + cwd: dir, + encoding: 'utf8', + timeout: 60000, + stdio: ['ignore', 'pipe', 'ignore'], + env: { PATH: process.env.PATH, NODE_ENV: 'production' }, + }); + return JSON.parse(out.trim().split('\n').pop() || 'null'); + } catch (error) { + return { error: error.code || error.name || 'load-failed' }; + } +} + +// --------------------------------------------------------------------------- +// Report rendering +// --------------------------------------------------------------------------- + +/** + * Renders the PR comment for a hold. + * + * @param {object[]} reasons Hold reasons. + * @param {string[]} [notes] Informational notes. + * @returns {string} Markdown. + */ +export function renderHold(reasons, notes = []) { + const clean = (text) => + String(text) + .replace(/[\r\n]+/g, ' ') + .slice(0, 600); + const lines = [ + '**Dependency gate: held for review (not merged automatically).**', + '', + 'All of these must be checked by a person before this update is merged:', + '', + ...reasons.slice(0, 50).map((r) => `- \`${r.code}\`: ${clean(r.message)}`), + ]; + if (notes.length) { + lines.push('', '
Notes', ''); + lines.push(...notes.slice(0, 50).map((n) => `- ${clean(n)}`), '', '
'); + } + lines.push( + '', + 'Gate rules: `.github/scripts/dependency-gate.mjs`. ' + + 'After review, merge by hand or ask Dependabot to recreate the PR.' + ); + return lines.join('\n'); +} + +// --------------------------------------------------------------------------- +// CLI +// --------------------------------------------------------------------------- + +/** + * Parses `--key value` arguments. + * + * @param {string[]} argv Arguments after the subcommand. + * @returns {Record} Options. + * @throws {Error} For an option without a value. + */ +function parseArgs(argv) { + const out = {}; + for (let i = 0; i < argv.length; i += 2) { + if (!argv[i].startsWith('--') || argv[i + 1] === undefined) { + throw new Error(`bad argument ${argv[i]}`); + } + out[argv[i].slice(2)] = argv[i + 1]; + } + return out; +} + +/** + * Reads a JSON file with a size limit; returns null for a missing file. + * + * @param {string | undefined} file Path. + * @returns {any} Parsed JSON or null. + * @throws {Error} When the file is too large or not valid JSON. + */ +function readJson(file) { + if (!file || !existsSync(file)) return null; + if (statSync(file).size > MAX_JSON_BYTES) throw new Error(`${file} is too large`); + return JSON.parse(readFileSync(file, 'utf8')); +} + +/** + * Writes `key=value` lines (heredoc form for multi-line values) to $GITHUB_OUTPUT. + * + * @param {Record} values Outputs. + * @returns {void} + * @sideeffect Appends to the file named by $GITHUB_OUTPUT, or prints when it is not set. + */ +function setOutputs(values) { + const file = process.env.GITHUB_OUTPUT; + for (const [key, value] of Object.entries(values)) { + const text = String(value); + const line = text.includes('\n') ? `${key}<} direct Direct updates. + * @returns {Record} Manifests keyed `name@version`. + * @sideeffect Runs `npm view` (network access to the npm registry). + */ +function registryManifests(direct) { + const out = {}; + for (const { name, from, to } of direct.slice(0, 40)) { + for (const version of [from, to]) { + try { + const json = execFileSync( + 'npm', + [ + 'view', + `${name}@${version}`, + 'engines', + 'peerDependencies', + 'peerDependenciesMeta', + '--json', + ], + { encoding: 'utf8', timeout: 60000, stdio: ['ignore', 'pipe', 'ignore'] } + ); + const data = json.trim() ? JSON.parse(json) : {}; + out[`${name}@${version}`] = Array.isArray(data) ? data[data.length - 1] : data; + } catch { + // Fall back to the lockfile copy of the same fields. + } + } + } + return out; +} + +/** + * CLI entry point. + * + * @param {string[]} argv Process arguments after the script path. + * @returns {Promise} Exit code. + * @throws {Error} For unknown subcommands or invalid arguments. + * @sideeffect Reads and writes files, writes to $GITHUB_OUTPUT, may call the network. + */ +export async function main(argv) { + const [command, ...rest] = argv; + const args = parseArgs(rest); + const print = (text) => process.stdout.write(`${text}\n`); + if (command === 'policy') { + setOutputs({ + 'allow-licenses': [...ALLOWED_LICENSES, ...DEV_ONLY_LICENSES].join(', '), + 'allow-dependencies-licenses': LICENSE_EXCEPTIONS.map( + (name) => `pkg:npm/${name.replace('@', '%40')}` + ).join(', '), + }); + return 0; + } + if (command === 'surface') { + const surface = recordSurface(path.resolve(args.dir)); + writeFileSync(args.out, `${JSON.stringify(surface, null, 2)}\n`); + print(`surface: ${surface.files.length} files, ${Object.keys(surface.entries).length} entries`); + return 0; + } + if (command === 'decide') { + const input = { + baseLock: readJson(args['base-lock']), + headLock: readJson(args['head-lock']), + basePkg: readJson(args['base-pkg']) || {}, + headPkg: readJson(args['head-pkg']) || {}, + baseSurface: readJson(args['base-surface']), + headSurface: readJson(args['head-surface']), + prBody: args['pr-body'] ? readFileSync(args['pr-body'], 'utf8') : '', + reviewChanges: readJson(args['review-changes']), + reviewOutcome: args['review-outcome'] || 'missing', + signaturesExit: Number(args['signatures-exit'] ?? 1), + }; + if (args.registry !== 'off' && input.baseLock && input.headLock) { + try { + input.registry = registryManifests(checkDirectUpdates(input).direct); + } catch { + input.registry = {}; + } + } + const result = decide(input); + if (args.out) writeFileSync(args.out, `${JSON.stringify(result, null, 2)}\n`); + print(`decision: ${result.decision}`); + for (const r of result.reasons) print(` hold ${r.code}: ${r.message}`); + for (const n of result.notes) print(` note: ${n}`); + setOutputs({ + decision: result.decision, + reasons: JSON.stringify(result.reasons.slice(0, 50)), + notes: JSON.stringify(result.notes.slice(0, 50)), + }); + return 0; + } + if (command === 'route') { + const unreadable = [reason('gate', 'Gate reasons could not be read.')]; + const reasons = parseList(process.env.GATE_REASONS, unreadable); + const notes = parseList(process.env.GATE_NOTES, []); + const result = route({ + updateType: process.env.UPDATE_TYPE, + verifyResult: process.env.VERIFY_RESULT, + gateResult: process.env.GATE_RESULT, + decision: process.env.GATE_DECISION, + reasons, + }); + print(`action: ${result.action}`); + if (args.comment) writeFileSync(args.comment, `${renderHold(result.reasons, notes)}\n`); + setOutputs({ action: result.action }); + return 0; + } + if (command === 'wait-ci') { + const token = process.env.GITHUB_TOKEN; + if (!token) throw new Error('GITHUB_TOKEN is required'); + const result = await waitForChecks({ + repo: args.repo, + sha: args.sha, + runId: Number(args['run-id']), + token, + timeoutMs: Number(args['timeout-minutes'] ?? 60) * 60 * 1000, + intervalMs: Number(args['interval-seconds'] ?? 30) * 1000, + log: print, + }); + print(`CI result: ${result.state}`); + for (const item of result.failing) print(` failing: ${item}`); + for (const item of result.pending) print(` pending: ${item}`); + if (args.comment && result.state !== 'success') { + const reasons = [ + ...result.failing.map((item) => reason('ci', item)), + ...(result.state === 'timeout' + ? result.pending.map((item) => reason('ci-timeout', item)) + : []), + ]; + writeFileSync(args.comment, `${renderHold(reasons)}\n`); + } + setOutputs({ state: result.state }); + return 0; + } + if (command === 'review-changes') { + const token = process.env.GITHUB_TOKEN; + if (!token) throw new Error('GITHUB_TOKEN is required'); + const basehead = `${args.base}...${args.head}`; + try { + const changes = await githubApi( + `/repos/${args.repo}/dependency-graph/compare/${basehead}`, + token + ); + writeFileSync(args.out, `${JSON.stringify(changes)}\n`); + print(`dependency-graph compare: ${changes.length} changes`); + } catch (error) { + print(`dependency-graph compare failed: ${error.message}`); + } + return 0; + } + throw new Error(`unknown command "${command}"`); +} + +const invokedDirectly = + process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href; +if (invokedDirectly) { + main(process.argv.slice(2)).then( + (code) => { + process.exitCode = code; + }, + (error) => { + process.stderr.write(`dependency-gate: ${error.message}\n`); + process.exitCode = 1; + } + ); +} diff --git a/.github/scripts/dependency-gate.test.mjs b/.github/scripts/dependency-gate.test.mjs new file mode 100644 index 0000000..eb10203 --- /dev/null +++ b/.github/scripts/dependency-gate.test.mjs @@ -0,0 +1,302 @@ +/** + * Unit tests for the Dependabot dependency gate. Run with `node --test .github/scripts/`. + * Every hold reason has a fixture-based test, and the pass path is tested end to end. + */ +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import path from 'node:path'; +import test from 'node:test'; +import { fileURLToPath } from 'node:url'; + +import { + checkBreakingText, + decide, + evaluateChecks, + licenseAllowed, + minVersion, + nodeSamples, + normalizePackPath, + renderHold, + route, + satisfies, + staticExports, +} from './dependency-gate.mjs'; + +const fixtures = path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixtures'); +const load = (name) => JSON.parse(readFileSync(path.join(fixtures, name), 'utf8')); + +/** + * Builds a gate input from the fixtures; `overrides` replace single fields. + * + * @param {object} [overrides] Fields to replace. + * @returns {object} Input for decide(). + */ +function input(overrides = {}) { + return { + baseLock: load('base-lock.json'), + headLock: load('head-pass-lock.json'), + basePkg: load('plugin-package.json'), + headPkg: load('plugin-package.json'), + baseSurface: load('surface-base.json'), + headSurface: load('surface-base.json'), + prBody: 'Bumps tiny-lib from 1.2.0 to 1.3.0.\n\nRelease notes: fixes a typo.', + reviewChanges: load('review-pass.json'), + reviewOutcome: 'success', + signaturesExit: 0, + registry: {}, + ...overrides, + }; +} + +const codes = (result) => [...new Set(result.reasons.map((r) => r.code))].sort(); + +test('semver: ranges used by engines and peers', () => { + assert.equal(satisfies('22.22.2', '^22.22.2 || >=24.15.0'), true); + assert.equal(satisfies('23.1.0', '^22.22.2 || >=24.15.0'), false); + assert.equal(satisfies('26.99.0', '>=22.0.0 <=26.x.x'), true); + assert.equal(satisfies('27.0.0', '>=22.0.0 <=26.x.x'), false); + assert.equal(satisfies('20.19.0', '>= 18'), true); + assert.equal(satisfies('0.4.9', '^0.4.1'), true); + assert.equal(satisfies('0.5.0', '^0.4.1'), false); + assert.equal(satisfies('1.5.0', '1.2 - 2.3'), true); + assert.equal(satisfies('2.4.0', '1.2 - 2.3'), false); + assert.equal(satisfies('5.0.0-beta.1', '^5.0.0'), false); + assert.equal(satisfies('5.0.0-beta.2', '>=5.0.0-beta.1 <6'), true); + assert.equal(satisfies('3.0.0', '*'), true); + assert.equal(satisfies('1.2.3', '~1.2.0'), true); + assert.equal(satisfies('1.3.0', '~1.2.0'), false); + assert.throws(() => satisfies('1.0.0', 'latest'), RangeError); + assert.equal(minVersion('^5.50.0'), '5.50.0'); + assert.equal(minVersion('>=22.12.0 <=26.x.x'), '22.12.0'); + assert.equal(minVersion('^18.0.0 || ^19.0.0'), '18.0.0'); +}); + +test('node samples cover every supported major and the declared floors', () => { + assert.deepEqual(nodeSamples('^22.22.2 || >=24.15.0'), [ + '22.22.2', + '22.22.3', + '22.99.0', + '24.15.0', + '24.15.1', + '24.99.0', + '25.0.0', + '25.99.0', + '26.0.0', + '26.99.0', + ]); + assert.deepEqual(nodeSamples('>=22.12.0 <=26.x.x').slice(0, 3), [ + '22.12.0', + '22.12.1', + '22.99.0', + ]); +}); + +test('SPDX expressions are evaluated against the allowlist', () => { + const allow = ['MIT', 'Apache-2.0']; + assert.equal(licenseAllowed('MIT', allow), true); + assert.equal(licenseAllowed('(MPL-2.0 OR Apache-2.0)', allow), true); + assert.equal(licenseAllowed('Apache-2.0 AND LGPL-3.0-or-later', allow), false); + assert.equal(licenseAllowed('(MIT AND (Apache-2.0 OR GPL-2.0))', allow), true); + assert.throws(() => licenseAllowed('(MIT', allow), SyntaxError); +}); + +test('pass: a patch/minor update with nothing dangerous is merged', () => { + const result = decide(input()); + assert.deepEqual(result.reasons, []); + assert.equal(result.decision, 'merge'); + assert.deepEqual(result.direct, [ + { name: 'tiny-lib', type: 'dependencies', from: '1.2.0', to: '1.3.0' }, + { name: 'dev-tool', type: 'devDependencies', from: '3.1.0', to: '3.1.1' }, + { name: 'esbuild', type: 'devDependencies', from: '0.25.0', to: '0.25.1' }, + ]); + assert.ok( + result.notes.some((note) => note.includes('esbuild@0.25.1 keeps its existing install')) + ); + assert.ok(result.notes.some((note) => note.includes('mystery@1.0.0: no license detected'))); +}); + +test('hold: a new package with an install script', () => { + const result = decide(input({ headLock: load('head-install-script-lock.json') })); + assert.equal(result.decision, 'hold'); + assert.deepEqual(codes(result), ['install-script']); +}); + +test('hold: more than 15 brand-new packages in one update', () => { + const result = decide(input({ headLock: load('head-new-packages-lock.json') })); + assert.deepEqual(codes(result), ['new-packages']); + assert.match(result.reasons[0].message, /^17 packages are new to the tree \(limit 15\)/); + assert.equal( + decide(input({ headLock: load('head-new-packages-lock.json'), maxNewPackages: 20 })).decision, + 'merge' + ); +}); + +test('hold: a package resolved outside registry.npmjs.org', () => { + const result = decide(input({ headLock: load('head-registry-lock.json') })); + assert.deepEqual(codes(result), ['registry']); +}); + +test('hold: a package without a sha512 integrity hash', () => { + const headLock = load('head-pass-lock.json'); + delete headLock.packages['node_modules/tiny-helper'].integrity; + assert.deepEqual(codes(decide(input({ headLock }))), ['integrity']); +}); + +test('hold: engines.node no longer covers a supported Node version', () => { + const result = decide(input({ headLock: load('head-engines-lock.json') })); + assert.deepEqual(codes(result), ['engines']); + assert.match( + result.reasons[0].message, + /tiny-lib@1\.3\.0 declares engines.node ">=24" \(was ">=18"\)/ + ); + assert.match(result.reasons[0].message, /22\.22\.2/); +}); + +test('hold: npm view data wins over the lockfile copy for engines', () => { + const registry = { 'tiny-lib@1.3.0': { engines: { node: '^24.0.0' } } }; + const result = decide(input({ registry })); + assert.deepEqual(codes(result), ['engines']); + assert.match(result.reasons[0].message, /26\.0\.0/); +}); + +test('hold: a raised peer dependency the installed tree does not satisfy', () => { + const result = decide(input({ headLock: load('head-peer-lock.json') })); + assert.deepEqual(codes(result), ['peer']); + assert.match( + result.reasons[0].message, + /needs peer react@"\^19\.0\.0" \(was ">=17"\).*react@18\.3\.1/ + ); +}); + +test('pass: a package that only moved keeps its earlier engines and peer state', () => { + const odd = { + version: '1.0.0', + resolved: 'https://registry.npmjs.org/odd/-/odd-1.0.0.tgz', + integrity: 'sha512-b2RkQDEuMC4w', + dev: true, + engines: { node: '>=24' }, + peerDependencies: { react: '^17.0.0' }, + }; + const baseLock = load('base-lock.json'); + baseLock.packages['node_modules/dev-tool/node_modules/odd'] = odd; + const headLock = load('head-pass-lock.json'); + headLock.packages['node_modules/odd'] = odd; + const result = decide(input({ baseLock, headLock })); + assert.equal(result.decision, 'merge'); + assert.ok( + result.notes.some((note) => note.includes('odd@1.0.0: peer react@"^17.0.0" was already')) + ); +}); + +test('hold: a shipped package needs a peer above the plugin peer floor', () => { + const result = decide(input({ headLock: load('head-peer-floor-lock.json') })); + assert.deepEqual(codes(result), ['peer-floor']); + assert.match(result.reasons[0].message, /@strapi\/strapi@5\.50\.0/); +}); + +test('hold: a 0.x minor bump of a runtime dependency', () => { + const result = decide(input({ headLock: load('head-zero-minor-lock.json') })); + assert.deepEqual(codes(result), ['zero-minor']); +}); + +test('major: a direct dependency major bump is never merged', () => { + const result = decide(input({ headLock: load('head-major-lock.json') })); + assert.equal(result.decision, 'major'); + assert.deepEqual(result.majors, ['tiny-lib 1.2.0 -> 2.0.0']); +}); + +test('hold: breaking-change wording in the PR body', () => { + for (const body of [ + '## BREAKING CHANGES\n- drops x', + 'This is a breaking change.', + 'Breaking: y', + ]) { + assert.deepEqual(codes(decide(input({ prBody: body }))), ['breaking-text'], body); + } + assert.deepEqual(checkBreakingText('A non-breaking fix. Avoids breakingly long lines.'), []); +}); + +test('hold: the published surface changed', () => { + const result = decide(input({ headSurface: load('surface-head-changed.json') })); + assert.deepEqual(codes(result), ['surface']); + assert.match(result.reasons.map((r) => r.message).join('\n'), /\+dist\/server\/extra\.js/); + assert.match(result.reasons.map((r) => r.message).join('\n'), /"shapes" changed/); + assert.deepEqual(codes(decide(input({ headSurface: null }))), ['surface']); +}); + +test('hold: package.json peerDependencies or engines changed', () => { + const headPkg = load('plugin-package.json'); + headPkg.engines.node = '>=24.15.0'; + assert.deepEqual(codes(decide(input({ headPkg }))), ['surface']); +}); + +test('surface: content hashes in chunk names are ignored', () => { + assert.equal(normalizePackPath('dist/_chunks/App-BfA8aZ0A.mjs'), 'dist/_chunks/App-[hash].mjs'); + assert.equal( + normalizePackPath('dist/_chunks/en-Bn4C3_gQ.js.map'), + 'dist/_chunks/en-[hash].js.map' + ); + assert.equal(normalizePackPath('dist/server/index.js'), 'dist/server/index.js'); + assert.deepEqual( + staticExports('const a = 1;\nexport { a as default, b };\nexport const c = 2;'), + ['b', 'c', 'default'] + ); +}); + +test('hold: vulnerabilities >= moderate and licenses outside the allowlist', () => { + const result = decide(input({ reviewChanges: load('review-hold.json') })); + assert.deepEqual(codes(result), ['license', 'vulnerability']); + const text = result.reasons.map((r) => r.message).join('\n'); + assert.match(text, /GHSA-0000-0000-0002/); + assert.match(text, /copyleft-lib@2\.0\.0 \(development scope\) has license "GPL-3\.0-only"/); + assert.match(text, /mpl-runtime@1\.0\.0 \(runtime scope\) has license "MPL-2\.0"/); + assert.deepEqual(codes(decide(input({ reviewChanges: null }))), ['dependency-review']); +}); + +test('hold: dependency-review-action failed or npm audit signatures failed', () => { + assert.deepEqual(codes(decide(input({ reviewOutcome: 'failure' }))), ['dependency-review']); + assert.deepEqual(codes(decide(input({ signaturesExit: 1 }))), ['signatures']); +}); + +test('hold: lockfile version 1 cannot be evaluated', () => { + const result = decide(input({ headLock: { lockfileVersion: 1, dependencies: {} } })); + assert.deepEqual(codes(result), ['lockfile']); +}); + +test('route: only an explicit patch/minor with green jobs and a merge decision merges', () => { + const ok = { + updateType: 'version-update:semver-minor', + verifyResult: 'success', + gateResult: 'success', + decision: 'merge', + reasons: [], + }; + assert.equal(route(ok).action, 'merge'); + assert.equal(route({ ...ok, updateType: 'version-update:semver-patch' }).action, 'merge'); + assert.equal(route({ ...ok, updateType: 'version-update:semver-major' }).action, 'major'); + assert.equal(route({ ...ok, decision: 'major' }).action, 'major'); + assert.equal(route({ ...ok, updateType: '' }).action, 'hold'); + assert.equal(route({ ...ok, verifyResult: 'failure' }).action, 'hold'); + assert.equal(route({ ...ok, gateResult: 'failure', decision: '' }).action, 'hold'); + const held = route({ ...ok, decision: 'hold', reasons: [{ code: 'peer', message: 'x' }] }); + assert.deepEqual(held, { action: 'hold', reasons: [{ code: 'peer', message: 'x' }] }); + assert.match(renderHold(held.reasons, ['note']), /- `peer`: x/); +}); + +test('wait-ci: green only when every other workflow and check finished green', () => { + assert.equal(evaluateChecks(load('checks-green.json')).state, 'success'); + const pending = evaluateChecks(load('checks-pending.json')); + assert.equal(pending.state, 'pending'); + assert.deepEqual(pending.pending, ['workflow "CI" (pull_request)', 'check "multi-instance"']); + const failed = evaluateChecks(load('checks-failed.json')); + assert.equal(failed.state, 'failure'); + assert.ok(failed.failing.includes('check "Admin StrictMode tests on React 19": failure')); + assert.equal(evaluateChecks(load('checks-superseded.json')).state, 'success'); + const none = { ownWorkflowId: 1, runs: [], checkRuns: [], status: { total_count: 0 } }; + assert.equal(evaluateChecks(none).state, 'pending'); + const status = { + ...load('checks-green.json'), + status: { total_count: 1, statuses: [{ context: 'ext', state: 'failure' }] }, + }; + assert.equal(evaluateChecks(status).state, 'failure'); +}); diff --git a/.github/scripts/fixtures/base-lock.json b/.github/scripts/fixtures/base-lock.json new file mode 100644 index 0000000..814907b --- /dev/null +++ b/.github/scripts/fixtures/base-lock.json @@ -0,0 +1,88 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.0.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.0.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.2.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4yLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "react": ">=17" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + } + } +} diff --git a/.github/scripts/fixtures/checks-failed.json b/.github/scripts/fixtures/checks-failed.json new file mode 100644 index 0000000..b769ae5 --- /dev/null +++ b/.github/scripts/fixtures/checks-failed.json @@ -0,0 +1,50 @@ +{ + "ownWorkflowId": 1, + "runs": [ + { + "id": 100, + "workflow_id": 1, + "name": "Dependency auto-merge", + "event": "pull_request", + "status": "in_progress", + "conclusion": null, + "run_number": 100, + "run_attempt": 1, + "check_suite_id": 1000 + }, + { + "id": 101, + "workflow_id": 2, + "name": "CI", + "event": "pull_request", + "status": "completed", + "conclusion": "failure", + "run_number": 101, + "run_attempt": 1, + "check_suite_id": 1010 + } + ], + "checkRuns": [ + { + "name": "verify (22)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + }, + { + "name": "Admin StrictMode tests on React 19", + "status": "completed", + "conclusion": "failure", + "check_suite": { + "id": 1010 + } + } + ], + "status": { + "state": "pending", + "total_count": 0, + "statuses": [] + } +} diff --git a/.github/scripts/fixtures/checks-green.json b/.github/scripts/fixtures/checks-green.json new file mode 100644 index 0000000..94de2c7 --- /dev/null +++ b/.github/scripts/fixtures/checks-green.json @@ -0,0 +1,101 @@ +{ + "ownWorkflowId": 1, + "runs": [ + { + "id": 100, + "workflow_id": 1, + "name": "Dependency auto-merge", + "event": "pull_request", + "status": "in_progress", + "conclusion": null, + "run_number": 100, + "run_attempt": 1, + "check_suite_id": 1000 + }, + { + "id": 101, + "workflow_id": 2, + "name": "CI", + "event": "pull_request", + "status": "completed", + "conclusion": "success", + "run_number": 101, + "run_attempt": 1, + "check_suite_id": 1010 + }, + { + "id": 102, + "workflow_id": 3, + "name": "CodeQL", + "event": "dynamic", + "status": "completed", + "conclusion": "success", + "run_number": 102, + "run_attempt": 1, + "check_suite_id": 1020 + } + ], + "checkRuns": [ + { + "name": "merge", + "status": "in_progress", + "conclusion": null, + "check_suite": { + "id": 1000 + } + }, + { + "name": "verify (22)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + }, + { + "name": "verify (24)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + }, + { + "name": "peer-floor", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + }, + { + "name": "react-19", + "status": "completed", + "conclusion": "skipped", + "check_suite": { + "id": 1010 + } + }, + { + "name": "Analyze (javascript)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1020 + } + }, + { + "name": "CodeQL", + "status": "completed", + "conclusion": "neutral", + "check_suite": { + "id": 9999 + } + } + ], + "status": { + "state": "pending", + "total_count": 0, + "statuses": [] + } +} diff --git a/.github/scripts/fixtures/checks-pending.json b/.github/scripts/fixtures/checks-pending.json new file mode 100644 index 0000000..b233229 --- /dev/null +++ b/.github/scripts/fixtures/checks-pending.json @@ -0,0 +1,50 @@ +{ + "ownWorkflowId": 1, + "runs": [ + { + "id": 100, + "workflow_id": 1, + "name": "Dependency auto-merge", + "event": "pull_request", + "status": "in_progress", + "conclusion": null, + "run_number": 100, + "run_attempt": 1, + "check_suite_id": 1000 + }, + { + "id": 101, + "workflow_id": 2, + "name": "CI", + "event": "pull_request", + "status": "in_progress", + "conclusion": null, + "run_number": 101, + "run_attempt": 1, + "check_suite_id": 1010 + } + ], + "checkRuns": [ + { + "name": "verify (22)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + }, + { + "name": "multi-instance", + "status": "queued", + "conclusion": null, + "check_suite": { + "id": 1010 + } + } + ], + "status": { + "state": "pending", + "total_count": 0, + "statuses": [] + } +} diff --git a/.github/scripts/fixtures/checks-superseded.json b/.github/scripts/fixtures/checks-superseded.json new file mode 100644 index 0000000..e688758 --- /dev/null +++ b/.github/scripts/fixtures/checks-superseded.json @@ -0,0 +1,85 @@ +{ + "ownWorkflowId": 1, + "runs": [ + { + "id": 90, + "workflow_id": 1, + "name": "Dependency auto-merge", + "event": "pull_request", + "status": "completed", + "conclusion": "cancelled", + "run_number": 90, + "run_attempt": 1, + "check_suite_id": 900 + }, + { + "id": 100, + "workflow_id": 1, + "name": "Dependency auto-merge", + "event": "pull_request", + "status": "in_progress", + "conclusion": null, + "run_number": 100, + "run_attempt": 1, + "check_suite_id": 1000 + }, + { + "id": 91, + "workflow_id": 2, + "name": "CI", + "event": "pull_request", + "status": "completed", + "conclusion": "cancelled", + "run_number": 5, + "run_attempt": 1, + "check_suite_id": 910 + }, + { + "id": 101, + "workflow_id": 2, + "name": "CI", + "event": "pull_request", + "status": "completed", + "conclusion": "success", + "run_number": 6, + "run_attempt": 1, + "check_suite_id": 1010 + } + ], + "checkRuns": [ + { + "name": "merge", + "status": "completed", + "conclusion": "cancelled", + "check_suite": { + "id": 900 + } + }, + { + "name": "verify (22)", + "status": "completed", + "conclusion": "cancelled", + "check_suite": { + "id": 910 + } + }, + { + "name": "verify (22)", + "status": "completed", + "conclusion": "success", + "check_suite": { + "id": 1010 + } + } + ], + "status": { + "state": "success", + "total_count": 1, + "statuses": [ + { + "context": "external/ci", + "state": "success" + } + ] + } +} diff --git a/.github/scripts/fixtures/head-engines-lock.json b/.github/scripts/fixtures/head-engines-lock.json new file mode 100644 index 0000000..c9848c2 --- /dev/null +++ b/.github/scripts/fixtures/head-engines-lock.json @@ -0,0 +1,100 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=24" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-install-script-lock.json b/.github/scripts/fixtures/head-install-script-lock.json new file mode 100644 index 0000000..29b778a --- /dev/null +++ b/.github/scripts/fixtures/head-install-script-lock.json @@ -0,0 +1,108 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0", + "postinstall-thing": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/postinstall-thing": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/postinstall-thing/-/postinstall-thing-1.0.0.tgz", + "integrity": "sha512-cG9zdGluc3RhbGwtdGhpbmdAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "hasInstallScript": true + } + } +} diff --git a/.github/scripts/fixtures/head-major-lock.json b/.github/scripts/fixtures/head-major-lock.json new file mode 100644 index 0000000..da480ff --- /dev/null +++ b/.github/scripts/fixtures/head-major-lock.json @@ -0,0 +1,97 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-2.0.0.tgz", + "integrity": "sha512-dGlueS1saWJAMi4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-new-packages-lock.json b/.github/scripts/fixtures/head-new-packages-lock.json new file mode 100644 index 0000000..8631339 --- /dev/null +++ b/.github/scripts/fixtures/head-new-packages-lock.json @@ -0,0 +1,212 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.2.0.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4yLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/new-dep-1": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-1/-/new-dep-1-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xQDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-2": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-2/-/new-dep-2-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0yQDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-3": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-3/-/new-dep-3-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0zQDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-4": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-4/-/new-dep-4-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC00QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-5": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-5/-/new-dep-5-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC01QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-6": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-6/-/new-dep-6-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC02QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-7": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-7/-/new-dep-7-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC03QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-8": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-8/-/new-dep-8-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC04QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-9": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-9/-/new-dep-9-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC05QDEuMC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-10": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-10/-/new-dep-10-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xMEAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-11": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-11/-/new-dep-11-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xMUAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-12": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-12/-/new-dep-12-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xMkAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-13": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-13/-/new-dep-13-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xM0AxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-14": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-14/-/new-dep-14-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xNEAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-15": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-15/-/new-dep-15-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xNUAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + }, + "node_modules/new-dep-16": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/new-dep-16/-/new-dep-16-1.0.0.tgz", + "integrity": "sha512-bmV3LWRlcC0xNkAxLjAuMCMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true + } + } +} diff --git a/.github/scripts/fixtures/head-pass-lock.json b/.github/scripts/fixtures/head-pass-lock.json new file mode 100644 index 0000000..2a7c841 --- /dev/null +++ b/.github/scripts/fixtures/head-pass-lock.json @@ -0,0 +1,100 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-peer-floor-lock.json b/.github/scripts/fixtures/head-peer-floor-lock.json new file mode 100644 index 0000000..06275ac --- /dev/null +++ b/.github/scripts/fixtures/head-peer-floor-lock.json @@ -0,0 +1,101 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.61.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.61.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS42MS4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17", + "@strapi/strapi": "^5.60.0" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-peer-lock.json b/.github/scripts/fixtures/head-peer-lock.json new file mode 100644 index 0000000..eddbea2 --- /dev/null +++ b/.github/scripts/fixtures/head-peer-lock.json @@ -0,0 +1,100 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": "^19.0.0" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-registry-lock.json b/.github/scripts/fixtures/head-registry-lock.json new file mode 100644 index 0000000..f4e3677 --- /dev/null +++ b/.github/scripts/fixtures/head-registry-lock.json @@ -0,0 +1,100 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://packages.example.test/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.4.1.tgz", + "integrity": "sha512-emVyby1saWJAMC40LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/head-zero-minor-lock.json b/.github/scripts/fixtures/head-zero-minor-lock.json new file mode 100644 index 0000000..4a69869 --- /dev/null +++ b/.github/scripts/fixtures/head-zero-minor-lock.json @@ -0,0 +1,100 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "fixture-plugin", + "version": "1.0.0", + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + } + }, + "node_modules/@strapi/strapi": { + "version": "5.50.0", + "resolved": "https://registry.npmjs.org/@strapi/strapi/-/strapi-5.50.0.tgz", + "integrity": "sha512-QHN0cmFwaS9zdHJhcGlANS41MC4wIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "SEE LICENSE IN LICENSE", + "dev": true, + "engines": { + "node": ">=20.0.0 <=24.x.x" + } + }, + "node_modules/dev-tool": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/dev-tool/-/dev-tool-3.1.1.tgz", + "integrity": "sha512-ZGV2LXRvb2xAMy4xLjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=20" + } + }, + "node_modules/esbuild": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-ZXNidWlsZEAwLjI1LjEjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "hasInstallScript": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/react": { + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-cmVhY3RAMTguMy4xIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/tiny-lib": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/tiny-lib/-/tiny-lib-1.3.0.tgz", + "integrity": "sha512-dGlueS1saWJAMS4zLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "react": ">=17" + }, + "dependencies": { + "tiny-helper": "^1.0.0" + } + }, + "node_modules/zero-lib": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/zero-lib/-/zero-lib-0.5.0.tgz", + "integrity": "sha512-emVyby1saWJAMC41LjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT" + }, + "node_modules/tiny-helper": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/tiny-helper/-/tiny-helper-1.0.0.tgz", + "integrity": "sha512-dGlueS1oZWxwZXJAMS4wLjAjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIw==", + "license": "MIT", + "engines": { + "node": ">=18" + } + } + } +} diff --git a/.github/scripts/fixtures/plugin-package.json b/.github/scripts/fixtures/plugin-package.json new file mode 100644 index 0000000..ca3acd4 --- /dev/null +++ b/.github/scripts/fixtures/plugin-package.json @@ -0,0 +1,21 @@ +{ + "name": "fixture-plugin", + "version": "1.0.0", + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + }, + "dependencies": { + "tiny-lib": "^1.2.0", + "zero-lib": "^0.4.1" + }, + "devDependencies": { + "@strapi/strapi": "^5.50.0", + "dev-tool": "^3.1.0", + "esbuild": "^0.25.0", + "react": "^18.3.1" + } +} diff --git a/.github/scripts/fixtures/review-hold.json b/.github/scripts/fixtures/review-hold.json new file mode 100644 index 0000000..4bd89f1 --- /dev/null +++ b/.github/scripts/fixtures/review-hold.json @@ -0,0 +1,33 @@ +[ + { + "change_type": "added", + "name": "tiny-lib", + "version": "1.3.0", + "license": "MIT", + "scope": "runtime", + "vulnerabilities": [ + { + "severity": "moderate", + "advisory_ghsa_id": "GHSA-0000-0000-0002", + "advisory_summary": "Moderate severity example", + "advisory_url": "https://github.com/advisories/GHSA-0000-0000-0002" + } + ] + }, + { + "change_type": "added", + "name": "copyleft-lib", + "version": "2.0.0", + "license": "GPL-3.0-only", + "scope": "development", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "mpl-runtime", + "version": "1.0.0", + "license": "MPL-2.0", + "scope": "runtime", + "vulnerabilities": [] + } +] diff --git a/.github/scripts/fixtures/review-pass.json b/.github/scripts/fixtures/review-pass.json new file mode 100644 index 0000000..f40a8b7 --- /dev/null +++ b/.github/scripts/fixtures/review-pass.json @@ -0,0 +1,65 @@ +[ + { + "change_type": "removed", + "name": "tiny-lib", + "version": "1.2.0", + "license": "MIT", + "scope": "runtime", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "tiny-lib", + "version": "1.3.0", + "license": "MIT", + "scope": "runtime", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "tiny-helper", + "version": "1.0.0", + "license": "(MPL-2.0 OR Apache-2.0)", + "scope": "runtime", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "dev-tool", + "version": "3.1.1", + "license": "MPL-2.0", + "scope": "development", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "esbuild", + "version": "0.25.1", + "license": "MIT", + "scope": "development", + "vulnerabilities": [ + { + "severity": "low", + "advisory_ghsa_id": "GHSA-0000-0000-0001", + "advisory_summary": "Low severity example", + "advisory_url": "https://github.com/advisories/GHSA-0000-0000-0001" + } + ] + }, + { + "change_type": "added", + "name": "@strapi/utils", + "version": "5.61.0", + "license": "LicenseRef-bad-see-license-in-license", + "scope": "runtime", + "vulnerabilities": [] + }, + { + "change_type": "added", + "name": "mystery", + "version": "1.0.0", + "license": null, + "scope": "development", + "vulnerabilities": [] + } +] diff --git a/.github/scripts/fixtures/surface-base.json b/.github/scripts/fixtures/surface-base.json new file mode 100644 index 0000000..239ccae --- /dev/null +++ b/.github/scripts/fixtures/surface-base.json @@ -0,0 +1,55 @@ +{ + "files": [ + "CHANGELOG.md", + "LICENSE", + "README.md", + "dist/_chunks/App-[hash].mjs", + "dist/admin/index.js", + "dist/admin/index.mjs", + "dist/server/index.js", + "dist/server/index.mjs", + "package.json", + "strapi-admin.js", + "strapi-server.js" + ], + "package": { + "main": null, + "module": null, + "types": null, + "type": "commonjs", + "bin": null, + "exports": { + "./strapi-server": { + "require": "./dist/server/index.js", + "import": "./dist/server/index.mjs" + } + }, + "files": ["dist", "strapi-admin.js", "strapi-server.js"] + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "entries": { + "./dist/server/index.js": [], + "./dist/server/index.mjs": ["default"] + }, + "shapes": { + "./dist/server/index.js": { + "bootstrap": "function", + "controllers": { + "settings": "function" + }, + "register": "function", + "routes": { + "admin": { + "routes": "array", + "type": "string" + } + } + } + } +} diff --git a/.github/scripts/fixtures/surface-head-changed.json b/.github/scripts/fixtures/surface-head-changed.json new file mode 100644 index 0000000..ef96322 --- /dev/null +++ b/.github/scripts/fixtures/surface-head-changed.json @@ -0,0 +1,46 @@ +{ + "files": [ + "CHANGELOG.md", + "LICENSE", + "README.md", + "dist/_chunks/App-[hash].mjs", + "dist/admin/index.js", + "dist/admin/index.mjs", + "dist/server/index.js", + "dist/server/index.mjs", + "package.json", + "strapi-admin.js", + "strapi-server.js", + "dist/server/extra.js" + ], + "package": { + "main": null, + "module": null, + "types": null, + "type": "commonjs", + "bin": null, + "exports": { + "./strapi-server": { + "require": "./dist/server/index.js", + "import": "./dist/server/index.mjs" + } + }, + "files": ["dist", "strapi-admin.js", "strapi-server.js"] + }, + "peerDependencies": { + "@strapi/strapi": "^5.50.0", + "react": "^18.0.0" + }, + "engines": { + "node": "^22.22.2 || >=24.15.0" + }, + "entries": { + "./dist/server/index.js": [], + "./dist/server/index.mjs": ["default"] + }, + "shapes": { + "./dist/server/index.js": { + "error": "ERR_REQUIRE_ESM" + } + } +} diff --git a/.github/workflows/dependency-auto-merge.yml b/.github/workflows/dependency-auto-merge.yml index 0763d14..dea9fbe 100644 --- a/.github/workflows/dependency-auto-merge.yml +++ b/.github/workflows/dependency-auto-merge.yml @@ -1,6 +1,14 @@ -# Verifies every Dependabot PR and merges it automatically when it is safe: -# - patch/minor updates: merged after lint, format check, tests, type checks, build and verify pass; -# - major updates: never merged automatically; the PR is labelled and left for review. +# Dependency auto-merge, version 2. Runs only for pull requests that Dependabot opened and +# updated (author and actor dependabot[bot]); for every other pull request all jobs are skipped. +# +# - verify: this repository's own checks on the Dependabot branch. +# - surface: builds merge base and head and records the published surface (read-only token). +# - gate: .github/scripts/dependency-gate.mjs from the default branch decides merge, hold or +# major from data only (lockfiles, package.json, surface reports, dependency review, +# npm audit signatures). It never runs code from the pull request. +# - merge: patch/minor updates with a "merge" decision wait until every other check on the +# head commit is green, then are squash-merged with --match-head-commit. Holds get the +# `needs-review` label and a comment with the reasons; majors get `major-update`. # Merges made with GITHUB_TOKEN do not trigger release.yml, so no npm release is published # automatically. Updates ship with the next regular release. name: Dependency auto-merge @@ -16,9 +24,14 @@ concurrency: group: dependency-auto-merge-${{ github.event.pull_request.number }} cancel-in-progress: true +env: + # Extra flags for npm ci in the surface and gate jobs (same install as the verify job). + NPM_CI_FLAGS: '--legacy-peer-deps' + jobs: + # This repository's own checks, unchanged from version 1. verify: - if: github.event.pull_request.user.login == 'dependabot[bot]' + if: github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]' runs-on: ubuntu-latest timeout-minutes: 30 steps: @@ -52,30 +65,243 @@ jobs: - name: Production audit (high and critical) run: npm audit --omit=dev --audit-level=critical - auto-merge: - needs: verify - if: github.event.pull_request.user.login == 'dependabot[bot]' + # Builds the merge base and the head and records what the package publishes. This job runs + # code from the pull request (install without lifecycle scripts, then the build), so it gets + # the read-only token only and its report is treated as data by the gate job. + surface: + name: Published surface (${{ matrix.side }}) + if: github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]' runs-on: ubuntu-latest + timeout-minutes: 30 + strategy: + fail-fast: false + matrix: + side: [base, head] + steps: + - name: Checkout gate script (default branch) + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.repository.default_branch }} + path: trusted + sparse-checkout: .github/scripts + persist-credentials: false + - name: Checkout pull request + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: pr + fetch-depth: 0 + persist-credentials: false + - name: Switch to the merge base + if: matrix.side == 'base' + working-directory: pr + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: git checkout --detach "$(git merge-base "$BASE_SHA" "$HEAD_SHA")" + - name: Setup Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '22' + - name: Install (no lifecycle scripts) + working-directory: pr + run: | + read -ra flags <<< "$NPM_CI_FLAGS" + npm ci --ignore-scripts "${flags[@]}" + - name: Build + working-directory: pr + run: npm run build + - name: Record the published surface + env: + SIDE: ${{ matrix.side }} + run: node trusted/.github/scripts/dependency-gate.mjs surface --dir pr --out "surface-$SIDE.json" + - name: Upload the surface report + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 + with: + name: surface-${{ matrix.side }} + path: surface-${{ matrix.side }}.json + if-no-files-found: error + retention-days: 3 + + # Trusted decision. Runs the gate script from the default branch on data only: lockfiles and + # package.json files of merge base and head, the surface reports, the dependency-graph + # comparison, actions/dependency-review-action and `npm audit signatures`. No code from the + # pull request runs here (the install skips lifecycle scripts). + gate: + name: Dependency gate + needs: surface + if: ${{ !cancelled() && github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]' }} + runs-on: ubuntu-latest + timeout-minutes: 20 + outputs: + decision: ${{ steps.decide.outputs.decision }} + reasons: ${{ steps.decide.outputs.reasons }} + notes: ${{ steps.decide.outputs.notes }} + steps: + - name: Checkout gate script (default branch) + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.repository.default_branch }} + path: trusted + sparse-checkout: .github/scripts + persist-credentials: false + - name: Checkout pull request + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.pull_request.head.sha }} + path: pr + fetch-depth: 0 + persist-credentials: false + - name: Setup Node.js + uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 + with: + node-version: '22' + - name: Gate self-test + run: node --test trusted/.github/scripts/dependency-gate.test.mjs + - name: Read the merge base + id: base + working-directory: pr + env: + BASE_SHA: ${{ github.event.pull_request.base.sha }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + run: | + merge_base="$(git merge-base "$BASE_SHA" "$HEAD_SHA")" + echo "sha=$merge_base" >> "$GITHUB_OUTPUT" + mkdir -p ../gate-input + git show "$merge_base:package.json" > ../gate-input/base-package.json + git show "$merge_base:package-lock.json" > ../gate-input/base-lock.json + - name: Install head (no lifecycle scripts) + working-directory: pr + run: | + read -ra flags <<< "$NPM_CI_FLAGS" + npm ci --ignore-scripts "${flags[@]}" + - name: Registry signatures and provenance attestations + id: signatures + working-directory: pr + run: | + set +e + npm audit signatures + echo "exit=$?" >> "$GITHUB_OUTPUT" + - name: License policy + id: policy + run: node trusted/.github/scripts/dependency-gate.mjs policy + - name: Dependency review + id: review + continue-on-error: true + uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v5.0.0 + with: + base-ref: ${{ steps.base.outputs.sha }} + head-ref: ${{ github.event.pull_request.head.sha }} + fail-on-severity: moderate + fail-on-scopes: runtime, development, unknown + allow-licenses: ${{ steps.policy.outputs.allow-licenses }} + allow-dependencies-licenses: ${{ steps.policy.outputs.allow-dependencies-licenses }} + comment-summary-in-pr: never + show-openssf-scorecard: false + - name: Dependency-graph comparison + env: + GITHUB_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + BASE: ${{ steps.base.outputs.sha }} + HEAD: ${{ github.event.pull_request.head.sha }} + run: >- + node trusted/.github/scripts/dependency-gate.mjs review-changes --repo "$REPO" + --base "$BASE" --head "$HEAD" --out gate-input/review-changes.json + - name: Download the surface reports + continue-on-error: true + uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 + with: + pattern: surface-* + path: gate-input + merge-multiple: true + - name: Decide + id: decide + env: + PR_BODY: ${{ github.event.pull_request.body }} + REVIEW_OUTCOME: ${{ steps.review.outcome }} + SIGNATURES_EXIT: ${{ steps.signatures.outputs.exit }} + run: | + printf '%s' "$PR_BODY" > gate-input/pr-body.txt + node trusted/.github/scripts/dependency-gate.mjs decide \ + --base-lock gate-input/base-lock.json --head-lock pr/package-lock.json \ + --base-pkg gate-input/base-package.json --head-pkg pr/package.json \ + --base-surface gate-input/surface-base.json --head-surface gate-input/surface-head.json \ + --review-changes gate-input/review-changes.json --review-outcome "$REVIEW_OUTCOME" \ + --signatures-exit "$SIGNATURES_EXIT" --pr-body gate-input/pr-body.txt \ + --out gate-input/decision.json + + # Acts on the decision. Holds and majors are labelled and commented. A patch or minor update + # with a "merge" decision waits until every other workflow run, check run and commit status + # on the head commit is green (all CI jobs and matrix entries, CodeQL where present), then + # squash-merges exactly that commit. This job checks out no code from the pull request. + merge: + name: Merge or hold + needs: [verify, gate] + if: ${{ !cancelled() && github.event.pull_request.user.login == 'dependabot[bot]' && github.actor == 'dependabot[bot]' }} + runs-on: ubuntu-latest + timeout-minutes: 90 permissions: + actions: read + checks: read contents: write pull-requests: write + statuses: read steps: - name: Read update metadata id: meta uses: dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0 with: github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Merge patch and minor updates - if: steps.meta.outputs.update-type != 'version-update:semver-major' - run: gh pr merge "$PR_URL" --squash --delete-branch + - name: Checkout gate script (default branch) + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ github.event.repository.default_branch }} + path: trusted + sparse-checkout: .github/scripts + persist-credentials: false + - name: Route + id: route + env: + UPDATE_TYPE: ${{ steps.meta.outputs.update-type }} + VERIFY_RESULT: ${{ needs.verify.result }} + GATE_RESULT: ${{ needs.gate.result }} + GATE_DECISION: ${{ needs.gate.outputs.decision }} + GATE_REASONS: ${{ needs.gate.outputs.reasons }} + GATE_NOTES: ${{ needs.gate.outputs.notes }} + run: node trusted/.github/scripts/dependency-gate.mjs route --comment hold-comment.md + - name: Wait for the full CI on the head commit + id: ci + if: steps.route.outputs.action == 'merge' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + REPO: ${{ github.repository }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + RUN_ID: ${{ github.run_id }} + run: >- + node trusted/.github/scripts/dependency-gate.mjs wait-ci --repo "$REPO" --sha "$HEAD_SHA" + --run-id "$RUN_ID" --timeout-minutes 75 --comment ci-comment.md + - name: Merge exactly the verified commit + if: steps.route.outputs.action == 'merge' && steps.ci.outputs.state == 'success' + run: gh pr merge "$PR_URL" --squash --delete-branch --match-head-commit "$HEAD_SHA" + env: + PR_URL: ${{ github.event.pull_request.html_url }} + HEAD_SHA: ${{ github.event.pull_request.head.sha }} + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Hold for review + if: steps.route.outputs.action == 'hold' || (steps.route.outputs.action == 'merge' && steps.ci.outputs.state != 'success') + run: | + body=hold-comment.md + if [ -f ci-comment.md ]; then body=ci-comment.md; fi + gh pr edit "$PR_URL" --add-label "needs-review" || true + gh pr comment "$PR_URL" --body-file "$body" env: PR_URL: ${{ github.event.pull_request.html_url }} GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Flag major updates for review - if: steps.meta.outputs.update-type == 'version-update:semver-major' + if: steps.route.outputs.action == 'major' run: | gh pr edit "$PR_URL" --add-label "major-update" || true - gh pr comment "$PR_URL" --body "Major update: all checks passed, but this PR is not merged automatically. Review the changelog of ${DEPS} for breaking changes before merging." + gh pr comment "$PR_URL" --body "Major update: this PR is not merged automatically. Review the changelog of ${DEPS} for breaking changes before merging." env: PR_URL: ${{ github.event.pull_request.html_url }} DEPS: ${{ steps.meta.outputs.dependency-names }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2022abe..a89d7b2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,6 +51,9 @@ jobs: - name: Run regression test suite run: npm test + - name: Dependency gate unit tests + run: node --test .github/scripts/dependency-gate.test.mjs + - name: Admin StrictMode tests (React 18) run: npm run test:admin diff --git a/README.md b/README.md index 8849e78..84cc86d 100644 --- a/README.md +++ b/README.md @@ -1000,7 +1000,7 @@ Issues and pull requests are welcome. ## Maintenance status -Actively maintained for the Strapi 5 line. Releases are cut by semantic-release from `main` using Conventional Commits and published to npm with npm Trusted Publishing (GitHub OIDC). Dependabot proposes weekly dependency updates; patch and minor updates are merged only after lint, tests, both type checks, build and `verify` pass. +Actively maintained for the Strapi 5 line. Releases are cut by semantic-release from `main` using Conventional Commits and published to npm with npm Trusted Publishing (GitHub OIDC). Dependabot proposes weekly dependency updates. See [Dependency updates and the auto-merge gate](#dependency-updates-and-the-auto-merge-gate). Dependency advisories (checked 2026-11-17, Strapi 5.62.0 dev baseline): `npm audit --omit=dev` on the plugin lockfile reports 5 high findings. All of them are one advisory in the Strapi 5 core dependency chain, picomatch [GHSA-fc5q-39xc-vjpf](https://github.com/advisories/GHSA-fc5q-39xc-vjpf) through `@strapi/utils` > `preferred-pm` > `find-yarn-workspace-root2` > `micromatch`. The plugin cannot fix findings in that chain; the forced npm fix would downgrade to Strapi 4, so it is not applied. They clear when Strapi ships an updated `@strapi/utils`. @@ -1010,6 +1010,24 @@ Report bugs at https://github.com/Schero94/Magic-Sessionmanager/issues. --- +### Dependency updates and the auto-merge gate + +Dependabot proposes updates weekly, after a cooldown (7 days, 14 for majors). `.github/workflows/dependency-auto-merge.yml` handles its pull requests with the rules in `.github/scripts/dependency-gate.mjs`. The script is the same in every Magic plugin repository; its unit tests run with `node --test .github/scripts/dependency-gate.test.mjs` and in CI. + +- **Merged automatically** (squash merge by `github-actions`): an explicit patch or minor update, after the repository's own checks pass, the gate finds nothing below, and every other check on the PR head commit has finished green: every CI job and matrix entry (for example Node versions, peer floor, React 19 StrictMode) and CodeQL where present. The merge is bound to that exact commit (`--match-head-commit`). +- **Held for review** (label `needs-review` plus a comment with the reasons, never merged automatically) when: + - a changed package's `engines.node` no longer covers a Node version this plugin supports, or its `peerDependencies` no longer match the installed tree or this plugin's peer floor; + - the PR body or release notes mention a breaking change; + - the published surface changes: the `npm pack` file list (content hashes ignored), `exports`, `peerDependencies`, `engines`, or the exports of the built entry files; + - a runtime dependency on 0.x gets a minor bump; + - dependency review reports a vulnerability of moderate or higher, or a license outside the allowlist (MIT, MIT-0, ISC, BSD, Apache-2.0, 0BSD, BlueOak-1.0.0, CC0-1.0, Unlicense, Python-2.0, Zlib; MPL-2.0 and CC-BY for development dependencies only); + - `npm audit signatures` reports a missing or invalid registry signature or provenance attestation; + - the lockfile adds a package with an install script, more than 15 packages that are new to the tree, or a package that does not resolve from `registry.npmjs.org`; + - a check fails, or the CI does not finish within 75 minutes. +- **Major updates** get the `major-update` label and a comment; a person reads the changelog and merges by hand. + +The gate script runs from the default branch and reads lockfiles and reports as data; it never runs code from the pull request. Only the surface job installs (without lifecycle scripts) and builds the pull request, with a read-only token. Merges made with `GITHUB_TOKEN` do not start `release.yml`, so a dependency update ships with the next regular release. + ## Languages The admin interface is available in English, German (formal "Sie"), French, Spanish and Portuguese, and follows the Strapi admin language. Dates use the admin locale. From ece2c79487c31eee9da3add1d60e49e4124f72ea Mon Sep 17 00:00:00 2001 From: Schero94 <64200582+Schero94@users.noreply.github.com> Date: Fri, 20 Nov 2026 00:23:50 +0100 Subject: [PATCH 2/2] ci: encode only the scope @ in license exception purls CodeQL js/incomplete-sanitization flagged replace('@', ...). npm names carry at most one leading @, so the result was already correct; make the intent explicit. Co-Authored-By: Claude Opus 5.5 --- .github/scripts/dependency-gate.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/dependency-gate.mjs b/.github/scripts/dependency-gate.mjs index d2e208c..582b6f7 100644 --- a/.github/scripts/dependency-gate.mjs +++ b/.github/scripts/dependency-gate.mjs @@ -1479,7 +1479,7 @@ export async function main(argv) { setOutputs({ 'allow-licenses': [...ALLOWED_LICENSES, ...DEV_ONLY_LICENSES].join(', '), 'allow-dependencies-licenses': LICENSE_EXCEPTIONS.map( - (name) => `pkg:npm/${name.replace('@', '%40')}` + (name) => `pkg:npm/${name.startsWith('@') ? `%40${name.slice(1)}` : name}` ).join(', '), }); return 0;