Skip to content

Commit 815d0f3

Browse files
committed
feat: add exclude-packages input
Using this, you can specify a RegExp which will be used to exclude package names from metrics.
1 parent 32b0adb commit 815d0f3

4 files changed

Lines changed: 82 additions & 34 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
| `dependency-threshold` | Threshold for warning about significant increase in number of dependencies | No | `10` |
4545
| `size-threshold` | Threshold (in bytes) for warning about significant increase in package size | No | `100000` |
4646
| `duplicate-threshold` | Threshold for warning about packages with multiple versions | No | `1` |
47+
| `exclude-packages` | Regular expression pattern to exclude packages from analysis | No | None |
4748
| `base-packages` | Glob pattern for base branch pack files (e.g., `"./base-packs/*.tgz"`) | No | None |
4849
| `source-packages` | Glob pattern for source branch pack files (e.g., `"./source-packs/*.tgz"`) | No | None |
4950
| `pack-size-threshold` | Threshold (in bytes) for warning about significant increase in total pack size | No | `50000` |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ inputs:
4040
description: 'Threshold for warning about packages with multiple versions'
4141
required: false
4242
default: '1'
43+
exclude-packages:
44+
description: 'Regular expression pattern to exclude packages from analysis'
45+
required: false
4346

4447
runs:
4548
using: node24

main.js

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19744,10 +19744,10 @@ Support boolean input list: \`true | True | TRUE | false | False | FALSE\``);
1974419744
(0, command_1.issueCommand)("error", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message);
1974519745
}
1974619746
exports.error = error;
19747-
function warning(message, properties = {}) {
19747+
function warning2(message, properties = {}) {
1974819748
(0, command_1.issueCommand)("warning", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message);
1974919749
}
19750-
exports.warning = warning;
19750+
exports.warning = warning2;
1975119751
function notice(message, properties = {}) {
1975219752
(0, command_1.issueCommand)("notice", (0, utils_1.toCommandProperties)(properties), message instanceof Error ? message.toString() : message);
1975319753
}
@@ -24406,6 +24406,23 @@ async function run() {
2440624406
const lockfilePath = detectLockfile(workspacePath);
2440724407
const token = core4.getInput("github-token", { required: true });
2440824408
const prNumber = parseInt(core4.getInput("pr-number", { required: true }), 10);
24409+
const dependencyThreshold = parseInt(
24410+
core4.getInput("dependency-threshold") || "10",
24411+
10
24412+
);
24413+
const sizeThreshold = parseInt(
24414+
core4.getInput("size-threshold") || "100000",
24415+
10
24416+
);
24417+
const duplicateThreshold = parseInt(
24418+
core4.getInput("duplicate-threshold") || "1",
24419+
10
24420+
);
24421+
const packSizeThreshold = parseInt(
24422+
core4.getInput("pack-size-threshold") || "50000",
24423+
10
24424+
);
24425+
const excludePackages = core4.getInput("exclude-packages");
2440924426
if (Number.isNaN(prNumber) || prNumber < 1) {
2441024427
core4.info("No valid pull request number was found. Skipping.");
2441124428
return;
@@ -24437,22 +24454,26 @@ async function run() {
2443724454
}
2443824455
const currentDeps = parseLockfile(lockfilePath, currentPackageLock);
2443924456
const baseDeps = parseLockfile(lockfilePath, basePackageLock);
24440-
const dependencyThreshold = parseInt(
24441-
core4.getInput("dependency-threshold") || "10",
24442-
10
24443-
);
24444-
const sizeThreshold = parseInt(
24445-
core4.getInput("size-threshold") || "100000",
24446-
10
24447-
);
24448-
const duplicateThreshold = parseInt(
24449-
core4.getInput("duplicate-threshold") || "1",
24450-
10
24451-
);
24452-
const packSizeThreshold = parseInt(
24453-
core4.getInput("pack-size-threshold") || "50000",
24454-
10
24455-
);
24457+
if (excludePackages) {
24458+
try {
24459+
const excludeRegex = new RegExp(excludePackages);
24460+
core4.info(`Excluding packages matching pattern: ${excludePackages}`);
24461+
for (const packageName of currentDeps.keys()) {
24462+
if (excludeRegex.test(packageName)) {
24463+
currentDeps.delete(packageName);
24464+
}
24465+
}
24466+
for (const packageName of baseDeps.keys()) {
24467+
if (excludeRegex.test(packageName)) {
24468+
baseDeps.delete(packageName);
24469+
}
24470+
}
24471+
} catch (err) {
24472+
core4.warning(
24473+
`Invalid exclude-packages regex pattern: ${excludePackages}`
24474+
);
24475+
}
24476+
}
2445624477
core4.info(`Dependency threshold set to ${dependencyThreshold}`);
2445724478
core4.info(`Size threshold set to ${formatBytes(sizeThreshold)}`);
2445824479
core4.info(`Duplicate threshold set to ${duplicateThreshold}`);

src/main.ts

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ async function run(): Promise<void> {
4747
const lockfilePath = detectLockfile(workspacePath);
4848
const token = core.getInput('github-token', {required: true});
4949
const prNumber = parseInt(core.getInput('pr-number', {required: true}), 10);
50+
const dependencyThreshold = parseInt(
51+
core.getInput('dependency-threshold') || '10',
52+
10
53+
);
54+
const sizeThreshold = parseInt(
55+
core.getInput('size-threshold') || '100000',
56+
10
57+
);
58+
const duplicateThreshold = parseInt(
59+
core.getInput('duplicate-threshold') || '1',
60+
10
61+
);
62+
const packSizeThreshold = parseInt(
63+
core.getInput('pack-size-threshold') || '50000',
64+
10
65+
);
66+
const excludePackages = core.getInput('exclude-packages');
5067

5168
if (Number.isNaN(prNumber) || prNumber < 1) {
5269
core.info('No valid pull request number was found. Skipping.');
@@ -84,22 +101,28 @@ async function run(): Promise<void> {
84101
const currentDeps = parseLockfile(lockfilePath, currentPackageLock);
85102
const baseDeps = parseLockfile(lockfilePath, basePackageLock);
86103

87-
const dependencyThreshold = parseInt(
88-
core.getInput('dependency-threshold') || '10',
89-
10
90-
);
91-
const sizeThreshold = parseInt(
92-
core.getInput('size-threshold') || '100000',
93-
10
94-
);
95-
const duplicateThreshold = parseInt(
96-
core.getInput('duplicate-threshold') || '1',
97-
10
98-
);
99-
const packSizeThreshold = parseInt(
100-
core.getInput('pack-size-threshold') || '50000',
101-
10
102-
);
104+
// Filter out excluded packages if pattern is provided
105+
if (excludePackages) {
106+
try {
107+
const excludeRegex = new RegExp(excludePackages);
108+
core.info(`Excluding packages matching pattern: ${excludePackages}`);
109+
110+
for (const packageName of currentDeps.keys()) {
111+
if (excludeRegex.test(packageName)) {
112+
currentDeps.delete(packageName);
113+
}
114+
}
115+
for (const packageName of baseDeps.keys()) {
116+
if (excludeRegex.test(packageName)) {
117+
baseDeps.delete(packageName);
118+
}
119+
}
120+
} catch (err) {
121+
core.warning(
122+
`Invalid exclude-packages regex pattern: ${excludePackages}`
123+
);
124+
}
125+
}
103126

104127
core.info(`Dependency threshold set to ${dependencyThreshold}`);
105128
core.info(`Size threshold set to ${formatBytes(sizeThreshold)}`);

0 commit comments

Comments
 (0)