@actions/glob
使用量
基础
您可以使用此软件包搜索匹配 glob 模式的文件 .
相对路径和绝对路径都是允许的. 相对路径根植于当前工作目录.
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()
显示器
在处理大量结果时,考虑在返回时延长结果:
const glob = require('@actions/glob');
const globber = await glob.create('**')
for await (const file of globber.globGenerator()) {
console.log(file)
}
建议的行动投入
Glob默认跟随符号链接. 除非删除文件,以下内容往往适当.
由于其他原因,用户可能希望选择退出跟随符号链接. 譬如说, 过多的符号链接可以创建非常,非常多文件的外观 并放慢搜索速度.
当一个动作允许用户指定输入模式时,一般建议 允许用户选择退出遵循符号链接.
片断来自 action.yml数字 :
inputs:
files:
description: 'Files to print'
required: true
follow-symbolic-links:
description: 'Indicates whether to follow symbolic links'
default: true
以及相应的工具包消费量:
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)
}
模式
Glob 行为
模式 *, (中文(简体) ), ?, (中文(简体) ), [...], (中文(简体) ), ** (globstar) 被支持.
具有以下行为: 1
- 开始的文件名
.可列入结果 - Windows 上的大小写不敏感
- 目录分隔符
/财务报告和审定财务报表\两者都支持在 Windows 上
提尔德扩展
支持基本的平面扩展, 只用于当前用户 Home 替换 .
示例
~可能扩展为/用户/johndoe~/foo可能扩展为/用户/johndoe/foo
评论
开始的模式 # 将作为评论处理.
排除图案
领导 ! 改变包含模式的含义以排除.
多个线索 ! 翻出意义.
逃跑
环绕特殊字符 [] 可用于从字面上擦去字符
在文件名中。 例如文字文件名称 hello[a-z] 可以逃脱为 hello[[]a-z]。 。 。 .
在 Linux/ macOS 上 \ 也被视为逃跑的角色.