Skip to content

Commit

Permalink
Support reusable paths blocks via yaml anchors (#13)
Browse files Browse the repository at this point in the history
* Add support for nested arrays of path expressions

* Remove pull_request trigger type options

Default value is fine: opened, synchronize, reopened

* Add CHANGELOG

* Update README
  • Loading branch information
dorny authored Jun 19, 2020
1 parent 4eb15bc commit 7d20182
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
Expand All @@ -42,7 +42,7 @@
"@typescript-eslint/prefer-includes": "error",
"@typescript-eslint/prefer-interface": "error",
"@typescript-eslint/prefer-string-starts-ends-with": "error",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/promise-function-async": ["error", { "allowAny": true }],
"@typescript-eslint/require-array-sort-compare": "error",
"@typescript-eslint/restrict-plus-operands": "error",
"semi": "off",
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: "Pull Request Verification"
on:
pull_request:
types:
- opened
- synchronize
branches:
- master

Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Changelog

## v2.1.0
- [Support reusable paths blocks with yaml anchors](https://github.com/dorny/paths-filter/pull/13)

## v2.0.0
- [Added support for workflows triggered by push events](https://github.com/dorny/paths-filter/pull/10)
- Action and repository renamed to paths-filter - original name doesn't make sense anymore

## v1.1.0
- [Allows filters to be specified in own .yml file](https://github.com/dorny/paths-filter/pull/8)
- [Adds alternative change detection using git fetch and git diff-index](https://github.com/dorny/paths-filter/pull/9)

## v1.0.1
Updated dependencies - fixes github security alert

## v1.0.0
First official release uploaded to marketplace.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Output variables can be later used in the `if` clause to conditionally run speci
### Notes
- minimatch [dot](https://www.npmjs.com/package/minimatch#dot) option is set to true - therefore
globbing will match also paths where file or folder name starts with a dot.
- You can use YAML anchors to reuse path expression(s) inside another rule. See example in the tests.

### Example
```yaml
Expand All @@ -48,7 +49,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2.0.0
- uses: dorny/paths-filter@v2.1.0
id: filter
with:
# inline YAML or path to separate file (e.g.: .github/filters.yaml)
Expand Down
14 changes: 14 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,18 @@ describe('matching tests', () => {
const match = filter.match(['.test/.test.js'])
expect(match.dot).toBeTruthy()
})

test('matches path based on rules included using YAML anchor', () => {
const yaml = `
shared: &shared
- common/**/*
- config/**/*
src:
- *shared
- src/**/*
`
let filter = new Filter(yaml)
const match = filter.match(['config/settings.yml'])
expect(match.src).toBeTruthy()
})
})
10 changes: 8 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4654,10 +4654,11 @@ class Filter {
dot: true
};
for (const name of Object.keys(doc)) {
const patterns = doc[name];
if (!Array.isArray(patterns)) {
const patternsNode = doc[name];
if (!Array.isArray(patternsNode)) {
this.throwInvalidFormatError();
}
const patterns = flat(patternsNode);
if (!patterns.every(x => typeof x === 'string')) {
this.throwInvalidFormatError();
}
Expand All @@ -4678,6 +4679,11 @@ class Filter {
}
}
exports.default = Filter;
// Creates a new array with all sub-array elements recursively concatenated
// In future could be replaced by Array.prototype.flat (supported on Node.js 11+)
function flat(arr) {
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flat(val) : val), []);
}


/***/ }),
Expand Down
Loading

0 comments on commit 7d20182

Please sign in to comment.