mirror of https://github.com/actions/toolkit
Add directory filtering to globber (#728)
Co-authored-by: Thomas Boop <52323235+thboop@users.noreply.github.com>pull/827/head
parent
51dc07a106
commit
439eaced07
|
@ -97,6 +97,23 @@ describe('globber', () => {
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('defaults to matchDirectories=true', async () => {
|
||||||
|
// Create the following layout:
|
||||||
|
// <root>
|
||||||
|
// <root>/folder-a
|
||||||
|
// <root>/folder-a/file
|
||||||
|
const root = path.join(getTestTemp(), 'defaults-to-match-directories-true')
|
||||||
|
await fs.mkdir(path.join(root, 'folder-a'), {recursive: true})
|
||||||
|
await fs.writeFile(path.join(root, 'folder-a', 'file'), 'test file content')
|
||||||
|
|
||||||
|
const itemPaths = await glob(root, {})
|
||||||
|
expect(itemPaths).toEqual([
|
||||||
|
root,
|
||||||
|
path.join(root, 'folder-a'),
|
||||||
|
path.join(root, 'folder-a', 'file')
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('does not match file with trailing slash when implicitDescendants=true', async () => {
|
it('does not match file with trailing slash when implicitDescendants=true', async () => {
|
||||||
// Create the following layout:
|
// Create the following layout:
|
||||||
// <root>
|
// <root>
|
||||||
|
@ -361,6 +378,34 @@ describe('globber', () => {
|
||||||
expect(itemPaths).toEqual([])
|
expect(itemPaths).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('does not return directories when match directories false', async () => {
|
||||||
|
// Create the following layout:
|
||||||
|
// <root>/file-1
|
||||||
|
// <root>/dir-1
|
||||||
|
// <root>/dir-1/file-2
|
||||||
|
// <root>/dir-1/dir-2
|
||||||
|
// <root>/dir-1/dir-2/file-3
|
||||||
|
const root = path.join(
|
||||||
|
getTestTemp(),
|
||||||
|
'does-not-return-directories-when-match-directories-false'
|
||||||
|
)
|
||||||
|
await fs.mkdir(path.join(root, 'dir-1', 'dir-2'), {recursive: true})
|
||||||
|
await fs.writeFile(path.join(root, 'file-1'), '')
|
||||||
|
await fs.writeFile(path.join(root, 'dir-1', 'file-2'), '')
|
||||||
|
await fs.writeFile(path.join(root, 'dir-1', 'dir-2', 'file-3'), '')
|
||||||
|
|
||||||
|
const pattern = `${root}${path.sep}**`
|
||||||
|
expect(
|
||||||
|
await glob(pattern, {
|
||||||
|
matchDirectories: false
|
||||||
|
})
|
||||||
|
).toEqual([
|
||||||
|
path.join(root, 'dir-1', 'dir-2', 'file-3'),
|
||||||
|
path.join(root, 'dir-1', 'file-2'),
|
||||||
|
path.join(root, 'file-1')
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it('does not search paths that are not partial matches', async () => {
|
it('does not search paths that are not partial matches', async () => {
|
||||||
// Create the following layout:
|
// Create the following layout:
|
||||||
// <root>
|
// <root>
|
||||||
|
|
|
@ -8,6 +8,7 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
|
||||||
const result: GlobOptions = {
|
const result: GlobOptions = {
|
||||||
followSymbolicLinks: true,
|
followSymbolicLinks: true,
|
||||||
implicitDescendants: true,
|
implicitDescendants: true,
|
||||||
|
matchDirectories: true,
|
||||||
omitBrokenSymbolicLinks: true
|
omitBrokenSymbolicLinks: true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +23,11 @@ export function getOptions(copy?: GlobOptions): GlobOptions {
|
||||||
core.debug(`implicitDescendants '${result.implicitDescendants}'`)
|
core.debug(`implicitDescendants '${result.implicitDescendants}'`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof copy.matchDirectories === 'boolean') {
|
||||||
|
result.matchDirectories = copy.matchDirectories
|
||||||
|
core.debug(`matchDirectories '${result.matchDirectories}'`)
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof copy.omitBrokenSymbolicLinks === 'boolean') {
|
if (typeof copy.omitBrokenSymbolicLinks === 'boolean') {
|
||||||
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
|
result.omitBrokenSymbolicLinks = copy.omitBrokenSymbolicLinks
|
||||||
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
|
core.debug(`omitBrokenSymbolicLinks '${result.omitBrokenSymbolicLinks}'`)
|
||||||
|
|
|
@ -21,6 +21,14 @@ export interface GlobOptions {
|
||||||
*/
|
*/
|
||||||
implicitDescendants?: boolean
|
implicitDescendants?: boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether matching directories should be included in the
|
||||||
|
* result set.
|
||||||
|
*
|
||||||
|
* @default true
|
||||||
|
*/
|
||||||
|
matchDirectories?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether broken symbolic should be ignored and omitted from the
|
* Indicates whether broken symbolic should be ignored and omitted from the
|
||||||
* result set. Otherwise an error will be thrown.
|
* result set. Otherwise an error will be thrown.
|
||||||
|
|
|
@ -131,7 +131,7 @@ export class DefaultGlobber implements Globber {
|
||||||
// Directory
|
// Directory
|
||||||
if (stats.isDirectory()) {
|
if (stats.isDirectory()) {
|
||||||
// Matched
|
// Matched
|
||||||
if (match & MatchKind.Directory) {
|
if (match & MatchKind.Directory && options.matchDirectories) {
|
||||||
yield item.path
|
yield item.path
|
||||||
}
|
}
|
||||||
// Descend?
|
// Descend?
|
||||||
|
|
Loading…
Reference in New Issue