@actions/glob

中文文档
0.7.0发布于 2026/04/22MITTypeScriptES Module构建来源已验证近 30 天下载 218.7万

Actions glob lib

原始使用文档
文档目录11 节
  1. Usage
  2. Basic
  3. Opt out of following symbolic links
  4. Iterator
  5. Recommended action inputs
  6. Patterns
  7. Glob behavior
  8. Tilde expansion
  9. Comments
  10. Exclude patterns
  11. Escaping

@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:

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

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.

版本与发布记录

@actions/glob 共发布 12 个版本,首次发布于 2020/01/11;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.7.0latest2026/04/226 个月前
0.6.12026/01/309 个月前
0.6.02026/01/309 个月前
0.5.12026/01/289 个月前
0.5.02024/08/162 年前
0.4.02023/01/253 年前

关于 @actions/glob 的常见问题

@actions/glob 是什么?

Actions glob lib

如何安装 @actions/glob?

在项目目录运行 npm install @actions/glob,或使用 pnpm add / yarn add / bun add。

@actions/glob 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@actions/glob 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@actions/glob 可以商用吗?

@actions/glob 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@actions/glob 的下载量有多少?

根据 npm 官方下载统计,@actions/glob 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,186,546 次,日均约 72,885 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@actions/glob 还在维护吗?

最新版本 0.7.0 发布于 2026/04/22(6 个月前);至今共发布 12 个版本,其中过去 12 个月发布了 4 个;首次发布于 2020/01/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。