mirror of
https://github.com/dorny/paths-filter.git
synced 2025-06-09 10:39:05 +00:00
Merge a87ec7a8d9
into de90cc6fb3
This commit is contained in:
commit
ef4283e929
2 changed files with 54 additions and 2 deletions
51
__tests__/export.test.ts
Normal file
51
__tests__/export.test.ts
Normal file
|
@ -0,0 +1,51 @@
|
|||
import * as core from '@actions/core'
|
||||
import {Filter} from '../src/filter'
|
||||
import {File, ChangeStatus} from '../src/file'
|
||||
import {exportResults} from '../src/main'
|
||||
|
||||
jest.mock('@actions/core', () => ({
|
||||
info: jest.fn(),
|
||||
setFailed: jest.fn(),
|
||||
startGroup: jest.fn(),
|
||||
setOutput: jest.fn(),
|
||||
endGroup: jest.fn()
|
||||
}))
|
||||
|
||||
describe('set output post filtering', () => {
|
||||
test('correctly sets output', () => {
|
||||
const yaml = `
|
||||
backend:
|
||||
- '!(**/*.tsx|**/*.less)'
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
exportResults(match, 'none')
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('changes', '["backend"]')
|
||||
})
|
||||
test('correctly filters out shared from output', () => {
|
||||
const yaml = `
|
||||
shared: &shared
|
||||
- common/**/*
|
||||
- config/**/*
|
||||
src:
|
||||
- *shared
|
||||
- src/**/*
|
||||
backend:
|
||||
- '!(**/*.tsx|**/*.less)'
|
||||
`
|
||||
const filter = new Filter(yaml)
|
||||
const files = modified(['config/settings.yml'])
|
||||
const match = filter.match(files)
|
||||
exportResults(match, 'none')
|
||||
|
||||
expect(core.setOutput).toHaveBeenCalledWith('changes', '["src","backend"]')
|
||||
})
|
||||
})
|
||||
|
||||
function modified(paths: string[]): File[] {
|
||||
return paths.map(filename => {
|
||||
return {filename, status: ChangeStatus.Modified}
|
||||
})
|
||||
}
|
|
@ -228,7 +228,7 @@ async function getChangedFilesFromApi(token: string, pullRequest: PullRequestEve
|
|||
}
|
||||
}
|
||||
|
||||
function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
export function exportResults(results: FilterResults, format: ExportFormat): void {
|
||||
core.info('Results:')
|
||||
const changes = []
|
||||
for (const [key, files] of Object.entries(results)) {
|
||||
|
@ -254,7 +254,8 @@ function exportResults(results: FilterResults, format: ExportFormat): void {
|
|||
}
|
||||
|
||||
if (results['changes'] === undefined) {
|
||||
const changesJson = JSON.stringify(changes)
|
||||
const filteredShared = changes.filter(change => change !== 'shared')
|
||||
const changesJson = JSON.stringify(filteredShared)
|
||||
core.info(`Changes output set to ${changesJson}`)
|
||||
core.setOutput('changes', changesJson)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue