Skip to content

Commit

Permalink
Adds exclude option
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 7, 2021
1 parent f4bc1d7 commit 5321de4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Action that allows you to generate diff report between branches. This way you al
| ---- | ----------- | -------- |
| base_path | Path of base branch stats file | yes |
| pr_path | Path of PR branch stats file | yes |
| excluded_assets | Regex that will exclude some assets | no |

## Output

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
pr_path:
description: 'Path to PR stats file'
required: true
excluded_assets:
description: 'Regex that will exclude some assets'
required: false
outputs:
success:
description: 'Reports back success, boolean as string'
Expand Down
16 changes: 12 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,34 @@ const { getStatsDiff } = __webpack_require__(493)

const getInputs = () => ({
basePath: core.getInput('base_path'),
prPath: core.getInput('pr_path')
prPath: core.getInput('pr_path'),
excludedAssets: core.getInput('excluded_assets')
})

const checkPaths = async () => {
const { basePath, prPath } = getInputs()
const { basePath, prPath, excludedAssets } = getInputs()
const base = path.resolve(process.cwd(), basePath)
const pr = path.resolve(process.cwd(), prPath)

const baseInclude = require(base)
const baseAssets = baseInclude && baseInclude.assets
let baseAssets = baseInclude && baseInclude.assets
if (!baseAssets) {
throw new Error(`Base path is not correct. Current input: ${base}`)
}

const prInclude = require(pr)
const prAssets = prInclude && prInclude.assets
let prAssets = prInclude && prInclude.assets
if (!prAssets) {
throw new Error(`Pr path is not correct. Current input: ${pr}`)
}

if (excludedAssets) {
const regex = new RegExp(excludedAssets)
baseAssets = baseAssets.filter(asset => !asset.name.match(regex))
prAssets = prAssets.filter(asset => !asset.name.match(regex))
}


return {
base: baseAssets,
pr: prAssets
Expand Down
16 changes: 12 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,34 @@ const { getStatsDiff } = require('webpack-stats-diff')

const getInputs = () => ({
basePath: core.getInput('base_path'),
prPath: core.getInput('pr_path')
prPath: core.getInput('pr_path'),
excludedAssets: core.getInput('excluded_assets')
})

const checkPaths = async () => {
const { basePath, prPath } = getInputs()
const { basePath, prPath, excludedAssets } = getInputs()
const base = path.resolve(process.cwd(), basePath)
const pr = path.resolve(process.cwd(), prPath)

const baseInclude = require(base)
const baseAssets = baseInclude && baseInclude.assets
let baseAssets = baseInclude && baseInclude.assets
if (!baseAssets) {
throw new Error(`Base path is not correct. Current input: ${base}`)
}

const prInclude = require(pr)
const prAssets = prInclude && prInclude.assets
let prAssets = prInclude && prInclude.assets
if (!prAssets) {
throw new Error(`Pr path is not correct. Current input: ${pr}`)
}

if (excludedAssets) {
const regex = new RegExp(excludedAssets)
baseAssets = baseAssets.filter(asset => !asset.name.match(regex))
prAssets = prAssets.filter(asset => !asset.name.match(regex))
}


return {
base: baseAssets,
pr: prAssets
Expand Down

0 comments on commit 5321de4

Please sign in to comment.