1
0
Fork 0
toolkit/packages/glob
Mike Pilgrem 099631638e Improve documentation of expansion for Windows
See actions/cache issue https://github.com/actions/cache/issues/705.
2022-06-11 18:02:16 +01:00
..
__tests__ Add HashFiles to the toolkit (#830) 2021-06-07 14:26:00 -04:00
src Added verbose mode in hashFiles (#1052) 2022-04-18 14:29:24 -04:00
LICENSE.md Add License.md to all npm packages (#548) 2020-08-25 16:26:50 -04:00
README.md Improve documentation of expansion for Windows 2022-06-11 18:02:16 +01:00
RELEASES.md Glob 0.3.0 release (#1056) 2022-04-18 15:49:18 -04:00
package-lock.json Update other packages to use http-client v2 (#1082) 2022-05-11 17:14:25 -04:00
package.json Glob 0.3.0 release (#1056) 2022-04-18 15:49:18 -04:00
tsconfig.json glob (#268) 2019-12-31 10:16:18 -05:00

README.md

@actions/glob

Usage

Basic

You can use this package to search for files matching glob patterns.

Relative paths and absolute paths are both allowed. Relative paths are rooted against the current working directory.

const glob = require('@actions/glob');

const patterns = ['**/tar.gz', '**/tar.bz']
const globber = await glob.create(patterns.join('\n'))
const files = await globber.glob()
const glob = require('@actions/glob');

const globber = await glob.create('**', {followSymbolicLinks: false})
const files = await globber.glob()

Iterator

When dealing with a large amount of results, consider iterating the results as they are returned:

const glob = require('@actions/glob');

const globber = await glob.create('**')
for await (const file of globber.globGenerator()) {
  console.log(file)
}

Glob follows symbolic links by default. Following is often appropriate unless deleting files.

Users may want to opt-out from following symbolic links for other reasons. For example, excessive amounts of symbolic links can create the appearance of very, very many files and slow the search.

When an action allows a user to specify input patterns, it is generally recommended to allow users to opt-out from following symbolic links.

Snippet from action.yml:

inputs:
  files:
    description: 'Files to print'
    required: true
  follow-symbolic-links:
    description: 'Indicates whether to follow symbolic links'
    default: true

And corresponding toolkit consumption:

const core = require('@actions/core')
const glob = require('@actions/glob')

const globOptions = {
  followSymbolicLinks: core.getInput('follow-symbolic-links').toUpper() !== 'FALSE'
}
const globber = glob.create(core.getInput('files'), globOptions)
for await (const file of globber.globGenerator()) {
  console.log(file)
}

Patterns

Glob behavior

Patterns *, ?, [...], ** (globstar) are supported.

With the following behaviors:

  • File names that begin with . may be included in the results
  • Case insensitive on Windows
  • Directory separator / and \ both supported on Windows

Tilde expansion

Supports basic tilde expansion, for current user HOME replacement only.

Example, for user johndoe on Unix-like operating systems:

  • ~ will expand to /Users/johndoe
  • ~/foo will expand to /Users/johndoe/foo

On Windows, environment variables such as %HOME%, %APPDATA% or %LOCALAPPDATA% will not be expanded. ~ can be used as an alternative to %HOME%, ~\AppData\Roaming as an alternative to %APPDATA%, and ~\AppData\Local as an alternative to %LOCALAPPDATA%.

Comments

Patterns that begin with # are treated as comments.

Exclude patterns

Leading ! changes the meaning of an include pattern to exclude.

Multiple leading ! flips the meaning.

Escaping

Wrapping special characters in [] can be used to escape literal glob characters in a file name. For example the literal file name hello[a-z] can be escaped as hello[[]a-z].

On Linux/macOS \ is also treated as an escape character.