mirror of
https://github.com/actions/toolkit
synced 2025-05-10 17:12:54 +00:00
multiple glob patterns (#287)
This commit is contained in:
parent
683245ad5e
commit
1a2c592903
7 changed files with 547 additions and 380 deletions
|
@ -2,18 +2,16 @@ import * as path from 'path'
|
|||
import * as patternHelper from '../src/internal-pattern-helper'
|
||||
import {MatchKind} from '../src/internal-match-kind'
|
||||
import {IS_WINDOWS} from '../../io/src/io-util'
|
||||
import {Pattern} from '../src/internal-pattern'
|
||||
|
||||
describe('pattern-helper', () => {
|
||||
it('getSearchPaths omits negate search paths', () => {
|
||||
const root = IS_WINDOWS ? 'C:\\' : '/'
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
`${root}search1/foo/**`,
|
||||
`${root}search2/bar/**`,
|
||||
`!${root}search3/baz/**`
|
||||
],
|
||||
patternHelper.getOptions()
|
||||
)
|
||||
const patterns = [
|
||||
`${root}search1/foo/**`,
|
||||
`${root}search2/bar/**`,
|
||||
`!${root}search3/baz/**`
|
||||
].map(x => new Pattern(x))
|
||||
const searchPaths = patternHelper.getSearchPaths(patterns)
|
||||
expect(searchPaths).toEqual([
|
||||
`${root}search1${path.sep}foo`,
|
||||
|
@ -23,17 +21,14 @@ describe('pattern-helper', () => {
|
|||
|
||||
it('getSearchPaths omits search path when ancestor is also a search path', () => {
|
||||
if (IS_WINDOWS) {
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
'C:\\Search1\\Foo\\**',
|
||||
'C:\\sEARCH1\\fOO\\bar\\**',
|
||||
'C:\\sEARCH1\\foo\\bar',
|
||||
'C:\\Search2\\**',
|
||||
'C:\\Search3\\Foo\\Bar\\**',
|
||||
'C:\\sEARCH3\\fOO\\bAR\\**'
|
||||
],
|
||||
patternHelper.getOptions()
|
||||
)
|
||||
const patterns = [
|
||||
'C:\\Search1\\Foo\\**',
|
||||
'C:\\sEARCH1\\fOO\\bar\\**',
|
||||
'C:\\sEARCH1\\foo\\bar',
|
||||
'C:\\Search2\\**',
|
||||
'C:\\Search3\\Foo\\Bar\\**',
|
||||
'C:\\sEARCH3\\fOO\\bAR\\**'
|
||||
].map(x => new Pattern(x))
|
||||
const searchPaths = patternHelper.getSearchPaths(patterns)
|
||||
expect(searchPaths).toEqual([
|
||||
'C:\\Search1\\Foo',
|
||||
|
@ -41,17 +36,15 @@ describe('pattern-helper', () => {
|
|||
'C:\\Search3\\Foo\\Bar'
|
||||
])
|
||||
} else {
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
'/search1/foo/**',
|
||||
'/search1/foo/bar/**',
|
||||
'/search2/foo/bar',
|
||||
'/search2/**',
|
||||
'/search3/foo/bar/**',
|
||||
'/search3/foo/bar/**'
|
||||
],
|
||||
patternHelper.getOptions()
|
||||
)
|
||||
const patterns = [
|
||||
'/search1/foo/**',
|
||||
'/search1/foo/bar/**',
|
||||
'/search2/foo/bar',
|
||||
'/search2/**',
|
||||
'/search3/foo/bar/**',
|
||||
'/search3/foo/bar/**'
|
||||
].map(x => new Pattern(x))
|
||||
|
||||
const searchPaths = patternHelper.getSearchPaths(patterns)
|
||||
expect(searchPaths).toEqual([
|
||||
'/search1/foo',
|
||||
|
@ -75,16 +68,13 @@ describe('pattern-helper', () => {
|
|||
`${root}solution2/proj2/README.txt`,
|
||||
`${root}solution2/solution2.sln`
|
||||
]
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
`${root}**/*.proj`, // include all proj files
|
||||
`${root}**/README.txt`, // include all README files
|
||||
`!${root}**/solution2/**`, // exclude the solution 2 folder entirely
|
||||
`${root}**/*.sln`, // include all sln files
|
||||
`!${root}**/proj2/README.txt` // exclude proj2 README files
|
||||
],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
const patterns = [
|
||||
`${root}**/*.proj`, // include all proj files
|
||||
`${root}**/README.txt`, // include all README files
|
||||
`!${root}**/solution2/**`, // exclude the solution 2 folder entirely
|
||||
`${root}**/*.sln`, // include all sln files
|
||||
`!${root}**/proj2/README.txt` // exclude proj2 README files
|
||||
].map(x => new Pattern(x))
|
||||
const matched = itemPaths.filter(
|
||||
x => patternHelper.match(patterns, x) === MatchKind.All
|
||||
)
|
||||
|
@ -105,13 +95,10 @@ describe('pattern-helper', () => {
|
|||
`${root}foo/bar`,
|
||||
`${root}foo/bar/baz`
|
||||
]
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
`${root}foo/**`, // include all files and directories
|
||||
`!${root}foo/**/` // exclude directories
|
||||
],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
const patterns = [
|
||||
`${root}foo/**`, // include all files and directories
|
||||
`!${root}foo/**/` // exclude directories
|
||||
].map(x => new Pattern(x))
|
||||
const matchKinds = itemPaths.map(x => patternHelper.match(patterns, x))
|
||||
expect(matchKinds).toEqual([
|
||||
MatchKind.None,
|
||||
|
@ -129,12 +116,9 @@ describe('pattern-helper', () => {
|
|||
`${root}foo/bar`,
|
||||
`${root}foo/bar/baz`
|
||||
]
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
`${root}foo/**/` // include directories only
|
||||
],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
const patterns = [
|
||||
`${root}foo/**/` // include directories only
|
||||
].map(x => new Pattern(x))
|
||||
const matchKinds = itemPaths.map(x => patternHelper.match(patterns, x))
|
||||
expect(matchKinds).toEqual([
|
||||
MatchKind.None,
|
||||
|
@ -144,36 +128,14 @@ describe('pattern-helper', () => {
|
|||
])
|
||||
})
|
||||
|
||||
it('parse skips comments', () => {
|
||||
const patterns = patternHelper.parse(
|
||||
['# comment 1', ' # comment 2', '!#hello-world.txt'],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
expect(patterns).toHaveLength(1)
|
||||
expect(patterns[0].negate).toBeTruthy()
|
||||
expect(patterns[0].segments.reverse()[0]).toEqual('#hello-world.txt')
|
||||
})
|
||||
|
||||
it('parse skips empty patterns', () => {
|
||||
const patterns = patternHelper.parse(
|
||||
['', ' ', 'hello-world.txt'],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
expect(patterns).toHaveLength(1)
|
||||
expect(patterns[0].segments.reverse()[0]).toEqual('hello-world.txt')
|
||||
})
|
||||
|
||||
it('partialMatch skips negate patterns', () => {
|
||||
const root = IS_WINDOWS ? 'C:\\' : '/'
|
||||
const patterns = patternHelper.parse(
|
||||
[
|
||||
`${root}search1/foo/**`,
|
||||
`${root}search2/bar/**`,
|
||||
`!${root}search2/bar/**`,
|
||||
`!${root}search3/baz/**`
|
||||
],
|
||||
patternHelper.getOptions({implicitDescendants: false})
|
||||
)
|
||||
const patterns = [
|
||||
`${root}search1/foo/**`,
|
||||
`${root}search2/bar/**`,
|
||||
`!${root}search2/bar/**`,
|
||||
`!${root}search3/baz/**`
|
||||
].map(x => new Pattern(x))
|
||||
expect(patternHelper.partialMatch(patterns, `${root}search1`)).toBeTruthy()
|
||||
expect(
|
||||
patternHelper.partialMatch(patterns, `${root}search1/foo`)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue