Skip to content

Commit 5321de4

Browse files
committed
Adds exclude option
1 parent f4bc1d7 commit 5321de4

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Action that allows you to generate diff report between branches. This way you al
1010
| ---- | ----------- | -------- |
1111
| base_path | Path of base branch stats file | yes |
1212
| pr_path | Path of PR branch stats file | yes |
13+
| excluded_assets | Regex that will exclude some assets | no |
1314

1415
## Output
1516

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ inputs:
88
pr_path:
99
description: 'Path to PR stats file'
1010
required: true
11+
excluded_assets:
12+
description: 'Regex that will exclude some assets'
13+
required: false
1114
outputs:
1215
success:
1316
description: 'Reports back success, boolean as string'

dist/index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,34 @@ const { getStatsDiff } = __webpack_require__(493)
1212

1313
const getInputs = () => ({
1414
basePath: core.getInput('base_path'),
15-
prPath: core.getInput('pr_path')
15+
prPath: core.getInput('pr_path'),
16+
excludedAssets: core.getInput('excluded_assets')
1617
})
1718

1819
const checkPaths = async () => {
19-
const { basePath, prPath } = getInputs()
20+
const { basePath, prPath, excludedAssets } = getInputs()
2021
const base = path.resolve(process.cwd(), basePath)
2122
const pr = path.resolve(process.cwd(), prPath)
2223

2324
const baseInclude = require(base)
24-
const baseAssets = baseInclude && baseInclude.assets
25+
let baseAssets = baseInclude && baseInclude.assets
2526
if (!baseAssets) {
2627
throw new Error(`Base path is not correct. Current input: ${base}`)
2728
}
2829

2930
const prInclude = require(pr)
30-
const prAssets = prInclude && prInclude.assets
31+
let prAssets = prInclude && prInclude.assets
3132
if (!prAssets) {
3233
throw new Error(`Pr path is not correct. Current input: ${pr}`)
3334
}
3435

36+
if (excludedAssets) {
37+
const regex = new RegExp(excludedAssets)
38+
baseAssets = baseAssets.filter(asset => !asset.name.match(regex))
39+
prAssets = prAssets.filter(asset => !asset.name.match(regex))
40+
}
41+
42+
3543
return {
3644
base: baseAssets,
3745
pr: prAssets

index.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,34 @@ const { getStatsDiff } = require('webpack-stats-diff')
55

66
const getInputs = () => ({
77
basePath: core.getInput('base_path'),
8-
prPath: core.getInput('pr_path')
8+
prPath: core.getInput('pr_path'),
9+
excludedAssets: core.getInput('excluded_assets')
910
})
1011

1112
const checkPaths = async () => {
12-
const { basePath, prPath } = getInputs()
13+
const { basePath, prPath, excludedAssets } = getInputs()
1314
const base = path.resolve(process.cwd(), basePath)
1415
const pr = path.resolve(process.cwd(), prPath)
1516

1617
const baseInclude = require(base)
17-
const baseAssets = baseInclude && baseInclude.assets
18+
let baseAssets = baseInclude && baseInclude.assets
1819
if (!baseAssets) {
1920
throw new Error(`Base path is not correct. Current input: ${base}`)
2021
}
2122

2223
const prInclude = require(pr)
23-
const prAssets = prInclude && prInclude.assets
24+
let prAssets = prInclude && prInclude.assets
2425
if (!prAssets) {
2526
throw new Error(`Pr path is not correct. Current input: ${pr}`)
2627
}
2728

29+
if (excludedAssets) {
30+
const regex = new RegExp(excludedAssets)
31+
baseAssets = baseAssets.filter(asset => !asset.name.match(regex))
32+
prAssets = prAssets.filter(asset => !asset.name.match(regex))
33+
}
34+
35+
2836
return {
2937
base: baseAssets,
3038
pr: prAssets

0 commit comments

Comments
 (0)