From 815d0f3cbe44a78953cd7cf7f1f929d68469b5cf Mon Sep 17 00:00:00 2001 From: James Garbutt <43081j@users.noreply.github.com> Date: Sat, 27 Sep 2025 10:20:32 +0100 Subject: [PATCH] feat: add `exclude-packages` input Using this, you can specify a RegExp which will be used to exclude package names from metrics. --- README.md | 1 + action.yml | 3 +++ main.js | 57 ++++++++++++++++++++++++++++++++++++----------------- src/main.ts | 55 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 82 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 5ce9866..00aac2e 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ jobs: | `dependency-threshold` | Threshold for warning about significant increase in number of dependencies | No | `10` | | `size-threshold` | Threshold (in bytes) for warning about significant increase in package size | No | `100000` | | `duplicate-threshold` | Threshold for warning about packages with multiple versions | No | `1` | +| `exclude-packages` | Regular expression pattern to exclude packages from analysis | No | None | | `base-packages` | Glob pattern for base branch pack files (e.g., `"./base-packs/*.tgz"`) | No | None | | `source-packages` | Glob pattern for source branch pack files (e.g., `"./source-packs/*.tgz"`) | No | None | | `pack-size-threshold` | Threshold (in bytes) for warning about significant increase in total pack size | No | `50000` | diff --git a/action.yml b/action.yml index 3129bbe..3a4143d 100644 --- a/action.yml +++ b/action.yml @@ -40,6 +40,9 @@ inputs: description: 'Threshold for warning about packages with multiple versions' required: false default: '1' + exclude-packages: + description: 'Regular expression pattern to exclude packages from analysis' + required: false runs: using: node24 diff --git a/main.js b/main.js index b01edba..08c9656 100644 --- a/main.js +++ b/main.js @@ -19744,10 +19744,10 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``); (0, command_1.issueCommand)("error", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message); } exports.error = error; - function warning(message, properties = {}) { + function warning2(message, properties = {}) { (0, command_1.issueCommand)("warning", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message); } - exports.warning = warning; + exports.warning = warning2; function notice(message, properties = {}) { (0, command_1.issueCommand)("notice", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message); } @@ -24406,6 +24406,23 @@ async function run() { const lockfilePath = detectLockfile(workspacePath); const token = core4.getInput("github-token", { required: true }); const prNumber = parseInt(core4.getInput("pr-number", { required: true }), 10); + const dependencyThreshold = parseInt( + core4.getInput("dependency-threshold") || "10", + 10 + ); + const sizeThreshold = parseInt( + core4.getInput("size-threshold") || "100000", + 10 + ); + const duplicateThreshold = parseInt( + core4.getInput("duplicate-threshold") || "1", + 10 + ); + const packSizeThreshold = parseInt( + core4.getInput("pack-size-threshold") || "50000", + 10 + ); + const excludePackages = core4.getInput("exclude-packages"); if (Number.isNaN(prNumber) || prNumber < 1) { core4.info("No valid pull request number was found. Skipping."); return; @@ -24437,22 +24454,26 @@ async function run() { } const currentDeps = parseLockfile(lockfilePath, currentPackageLock); const baseDeps = parseLockfile(lockfilePath, basePackageLock); - const dependencyThreshold = parseInt( - core4.getInput("dependency-threshold") || "10", - 10 - ); - const sizeThreshold = parseInt( - core4.getInput("size-threshold") || "100000", - 10 - ); - const duplicateThreshold = parseInt( - core4.getInput("duplicate-threshold") || "1", - 10 - ); - const packSizeThreshold = parseInt( - core4.getInput("pack-size-threshold") || "50000", - 10 - ); + if (excludePackages) { + try { + const excludeRegex = new RegExp(excludePackages); + core4.info(`Excluding packages matching pattern: ${excludePackages}`); + for (const packageName of currentDeps.keys()) { + if (excludeRegex.test(packageName)) { + currentDeps.delete(packageName); + } + } + for (const packageName of baseDeps.keys()) { + if (excludeRegex.test(packageName)) { + baseDeps.delete(packageName); + } + } + } catch (err) { + core4.warning( + `Invalid exclude-packages regex pattern: ${excludePackages}` + ); + } + } core4.info(`Dependency threshold set to ${dependencyThreshold}`); core4.info(`Size threshold set to ${formatBytes(sizeThreshold)}`); core4.info(`Duplicate threshold set to ${duplicateThreshold}`); diff --git a/src/main.ts b/src/main.ts index ef9b90b..9b6481e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -47,6 +47,23 @@ async function run(): Promise { const lockfilePath = detectLockfile(workspacePath); const token = core.getInput('github-token', {required: true}); const prNumber = parseInt(core.getInput('pr-number', {required: true}), 10); + const dependencyThreshold = parseInt( + core.getInput('dependency-threshold') || '10', + 10 + ); + const sizeThreshold = parseInt( + core.getInput('size-threshold') || '100000', + 10 + ); + const duplicateThreshold = parseInt( + core.getInput('duplicate-threshold') || '1', + 10 + ); + const packSizeThreshold = parseInt( + core.getInput('pack-size-threshold') || '50000', + 10 + ); + const excludePackages = core.getInput('exclude-packages'); if (Number.isNaN(prNumber) || prNumber < 1) { core.info('No valid pull request number was found. Skipping.'); @@ -84,22 +101,28 @@ async function run(): Promise { const currentDeps = parseLockfile(lockfilePath, currentPackageLock); const baseDeps = parseLockfile(lockfilePath, basePackageLock); - const dependencyThreshold = parseInt( - core.getInput('dependency-threshold') || '10', - 10 - ); - const sizeThreshold = parseInt( - core.getInput('size-threshold') || '100000', - 10 - ); - const duplicateThreshold = parseInt( - core.getInput('duplicate-threshold') || '1', - 10 - ); - const packSizeThreshold = parseInt( - core.getInput('pack-size-threshold') || '50000', - 10 - ); + // Filter out excluded packages if pattern is provided + if (excludePackages) { + try { + const excludeRegex = new RegExp(excludePackages); + core.info(`Excluding packages matching pattern: ${excludePackages}`); + + for (const packageName of currentDeps.keys()) { + if (excludeRegex.test(packageName)) { + currentDeps.delete(packageName); + } + } + for (const packageName of baseDeps.keys()) { + if (excludeRegex.test(packageName)) { + baseDeps.delete(packageName); + } + } + } catch (err) { + core.warning( + `Invalid exclude-packages regex pattern: ${excludePackages}` + ); + } + } core.info(`Dependency threshold set to ${dependencyThreshold}`); core.info(`Size threshold set to ${formatBytes(sizeThreshold)}`);