Skip to content

Commit

Permalink
Merge pull request #1 from AurorNZ/use-micromatch
Browse files Browse the repository at this point in the history
Use micromatch
  • Loading branch information
Obi-Dann authored Mar 1, 2022
2 parents 1ec7035 + 5af776f commit fa09eba
Show file tree
Hide file tree
Showing 6 changed files with 18,306 additions and 832 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/pull-request-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,44 +94,3 @@ jobs:
- name: count-test
if: steps.filter.outputs.local_count != 1
run: exit 1

test-change-type:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: configure GIT user
run: git config user.email "[email protected]" && git config user.name "John Doe"
- name: modify working tree
run: touch add.txt && rm README.md && echo "TEST" > LICENSE
- name: commit changes
run: git add -A && git commit -a -m 'testing this action'
- uses: ./
id: filter
with:
token: ''
list-files: shell
filters: |
added:
- added: "add.txt"
deleted:
- deleted: "README.md"
modified:
- modified: "LICENSE"
any:
- added|deleted|modified: "*"
- name: Print 'added_files'
run: echo ${{steps.filter.outputs.added_files}}
- name: Print 'modified_files'
run: echo ${{steps.filter.outputs.modified_files}}
- name: Print 'deleted_files'
run: echo ${{steps.filter.outputs.deleted_files}}
- name: filter-test
if: |
steps.filter.outputs.added != 'true'
|| steps.filter.outputs.deleted != 'true'
|| steps.filter.outputs.modified != 'true'
|| steps.filter.outputs.any != 'true'
|| steps.filter.outputs.added_files != 'add.txt'
|| steps.filter.outputs.modified_files != 'LICENSE'
|| steps.filter.outputs.deleted_files != 'README.md'
run: exit 1
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ For more information, see [CHANGELOG](https://github.com/dorny/paths-filter/blob
# Each filter has a name and a list of rules.
# Rule is a glob expression - paths of all changed
# files are matched against it.
# Rule can optionally specify if the file
# should be added, modified, or deleted.
# For each filter, there will be a corresponding output variable to
# indicate if there's a changed file matching any of the rules.
# Optionally, there can be a second output variable
Expand Down
63 changes: 23 additions & 40 deletions __tests__/filter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,65 +117,48 @@ describe('matching tests', () => {
expect(pyMatch.backend).toEqual(pyFiles)
})

test('matches path based on rules included using YAML anchor', () => {
test('matches single rule with negation', () => {
const yaml = `
shared: &shared
- common/**/*
- config/**/*
src:
- *shared
- src/**/*
- '!src/**/*.js'
`
const filter = new Filter(yaml)
const files = modified(['config/settings.yml'])
const files = modified(['src/app/module/file.js'])
const match = filter.match(files)
expect(match.src).toEqual(files)
expect(match.src).toEqual([])
})
})

describe('matching specific change status', () => {
test('does not match modified file as added', () => {
test('matches multiple rules with negation', () => {
const yaml = `
add:
- added: "**/*"
src:
- 'src/**/*.ts'
- '!src/**/*.test.ts'
`
let filter = new Filter(yaml)
const match = filter.match(modified(['file.js']))
expect(match.add).toEqual([])
})
const filter = new Filter(yaml)
const jsFiles = modified(['src/app/module/file.js'])
const tsFiles = modified(['src/app/module/file.ts'])
const tsTestFiles = modified(['src/app/module/file.test.ts'])

test('match added file as added', () => {
const yaml = `
add:
- added: "**/*"
`
let filter = new Filter(yaml)
const files = [{status: ChangeStatus.Added, filename: 'file.js'}]
const match = filter.match(files)
expect(match.add).toEqual(files)
})
const jsMatch = filter.match(jsFiles)
const tsMatch = filter.match(tsFiles)
const tsTestMatch = filter.match(tsTestFiles)

test('matches when multiple statuses are configured', () => {
const yaml = `
addOrModify:
- added|modified: "**/*"
`
let filter = new Filter(yaml)
const files = [{status: ChangeStatus.Modified, filename: 'file.js'}]
const match = filter.match(files)
expect(match.addOrModify).toEqual(files)
expect(jsMatch.src).toEqual([])
expect(tsMatch.src).toEqual(tsFiles)
expect(tsTestMatch.src).toEqual([])
})

test('matches when using an anchor', () => {
test('matches path based on rules included using YAML anchor', () => {
const yaml = `
shared: &shared
- common/**/*
- config/**/*
src:
- modified: *shared
- *shared
- src/**/*
`
let filter = new Filter(yaml)
const files = modified(['config/file.js', 'common/anotherFile.js'])
const filter = new Filter(yaml)
const files = modified(['config/settings.yml'])
const match = filter.match(files)
expect(match.src).toEqual(files)
})
Expand Down
Loading

0 comments on commit fa09eba

Please sign in to comment.