What is @actions/glob?
@actions/glob is an npm package designed to help with file matching and globbing patterns in GitHub Actions workflows. It allows users to find files and directories using glob patterns, which can be useful for tasks such as file manipulation, testing, and deployment.
What are @actions/glob's main functionalities?
Basic File Matching
This feature allows you to match files based on a glob pattern. In this example, it matches all JavaScript files in the directory and its subdirectories.
const glob = require('@actions/glob');
async function run() {
const pattern = '**/*.js';
const globber = await glob.create(pattern);
for await (const file of globber.globGenerator()) {
console.log(file);
}
}
run();
Excluding Files
This feature allows you to exclude certain files or directories from the matching process. In this example, it matches all JavaScript files except those in the node_modules directory.
const glob = require('@actions/glob');
async function run() {
const pattern = '**/*.js';
const excludePattern = '**/node_modules/**';
const globber = await glob.create(pattern, { ignore: [excludePattern] });
for await (const file of globber.globGenerator()) {
console.log(file);
}
}
run();
Matching Directories
This feature allows you to match directories based on a glob pattern. In this example, it matches all directories in the current directory and its subdirectories.
const glob = require('@actions/glob');
async function run() {
const pattern = '**/';
const globber = await glob.create(pattern);
for await (const dir of globber.globGenerator()) {
console.log(dir);
}
}
run();
Other packages similar to @actions/glob
glob
The 'glob' package is a popular library for file matching using glob patterns. It is widely used in the Node.js ecosystem and offers similar functionality to @actions/glob, such as pattern matching and file exclusion. However, @actions/glob is specifically optimized for use in GitHub Actions workflows.
fast-glob
The 'fast-glob' package is another alternative for file matching using glob patterns. It is known for its performance and efficiency, especially with large sets of files. Compared to @actions/glob, 'fast-glob' offers faster matching and additional options for customization.
minimatch
The 'minimatch' package provides a minimalistic approach to glob pattern matching. It is a lightweight library that focuses on simplicity and ease of use. While it offers similar functionality to @actions/glob, it may not have the same level of integration with GitHub Actions workflows.