mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-07 16:49:03 +00:00
feat: add config parameter for predicate quantifier
Setting the new 'predicate-quantifier' configuration parameter to 'every' makes it so that all the patterns have to match a file for it to be considered changed. This can be leveraged to ensure that you only build & test software changes that have real impact on the behavior of the code, e.g. you can set up your build to run when Typescript/Rust/etc. files are changed but markdown changes in the diff will be ignored and you consume less resources to build. The default behavior does not change by the introduction of this feature so upgrading can be done safely knowing that existing workflows will not break. Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
This commit is contained in:
parent
ebc4d7e9eb
commit
f90d5265d6
4 changed files with 149 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
import {Filter} from '../src/filter'
|
||||
import {Filter, FilterConfig, PredicateQuantifier} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
|
||||
describe('yaml filter parsing tests', () => {
|
||||
|
@ -117,6 +117,37 @@ describe('matching tests', () => {
|
|||
expect(pyMatch.backend).toEqual(pyFiles)
|
||||
})
|
||||
|
||||
test('matches only files that are matching EVERY pattern when set to PredicateQuantifier.EVERY', () => {
|
||||
const yaml = `
|
||||
backend:
|
||||
- 'pkg/a/b/c/**'
|
||||
- '!**/*.jpeg'
|
||||
- '!**/*.md'
|
||||
`
|
||||
const filterConfig: FilterConfig = {predicateQuantifier: PredicateQuantifier.EVERY}
|
||||
const filter = new Filter(yaml, filterConfig)
|
||||
|
||||
const typescriptFiles = modified(['pkg/a/b/c/some-class.ts', 'pkg/a/b/c/src/main/some-class.ts'])
|
||||
const otherPkgTypescriptFiles = modified(['pkg/x/y/z/some-class.ts', 'pkg/x/y/z/src/main/some-class.ts'])
|
||||
const otherPkgJpegFiles = modified(['pkg/x/y/z/some-pic.jpeg', 'pkg/x/y/z/src/main/jpeg/some-pic.jpeg'])
|
||||
const docsFiles = modified([
|
||||
'pkg/a/b/c/some-pics.jpeg',
|
||||
'pkg/a/b/c/src/main/jpeg/some-pic.jpeg',
|
||||
'pkg/a/b/c/src/main/some-docs.md',
|
||||
'pkg/a/b/c/some-docs.md'
|
||||
])
|
||||
|
||||
const typescriptMatch = filter.match(typescriptFiles)
|
||||
const otherPkgTypescriptMatch = filter.match(otherPkgTypescriptFiles)
|
||||
const docsMatch = filter.match(docsFiles)
|
||||
const otherPkgJpegMatch = filter.match(otherPkgJpegFiles)
|
||||
|
||||
expect(typescriptMatch.backend).toEqual(typescriptFiles)
|
||||
expect(otherPkgTypescriptMatch.backend).toEqual([])
|
||||
expect(docsMatch.backend).toEqual([])
|
||||
expect(otherPkgJpegMatch.backend).toEqual([])
|
||||
})
|
||||
|
||||
test('matches path based on rules included using YAML anchor', () => {
|
||||
const yaml = `
|
||||
shared: &shared
|
||||
|
@ -186,3 +217,9 @@ function modified(paths: string[]): File[] {
|
|||
return {filename, status: ChangeStatus.Modified}
|
||||
})
|
||||
}
|
||||
|
||||
function renamed(paths: string[]): File[] {
|
||||
return paths.map(filename => {
|
||||
return {filename, status: ChangeStatus.Renamed}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue