
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
@actions/exec
Advanced tools
@actions/exec is an npm package designed to facilitate the execution of shell commands within GitHub Actions workflows. It provides a simple and flexible API to run commands, capture their output, and handle errors.
Basic Command Execution
This feature allows you to execute basic shell commands. In this example, the 'echo' command is used to print 'Hello, world!' to the console.
const exec = require('@actions/exec');
async function run() {
await exec.exec('echo', ['Hello, world!']);
}
run();
Capture Output
This feature allows you to capture the output and error streams of the executed command. In this example, the 'node -v' command is executed, and its output and error streams are captured and printed to the console.
const exec = require('@actions/exec');
async function run() {
let myOutput = '';
let myError = '';
const options = {};
options.listeners = {
stdout: (data) => {
myOutput += data.toString();
},
stderr: (data) => {
myError += data.toString();
}
};
await exec.exec('node', ['-v'], options);
console.log('Output:', myOutput);
console.log('Error:', myError);
}
run();
Command with Options
This feature allows you to execute commands with additional options such as the working directory and environment variables. In this example, the 'ls -la' command is executed in a specified working directory with a custom environment variable.
const exec = require('@actions/exec');
async function run() {
const options = {
cwd: '/path/to/working/directory',
env: { MY_VAR: 'value' }
};
await exec.exec('ls', ['-la'], options);
}
run();
The 'child_process' module is a built-in Node.js module that provides the ability to spawn child processes. It offers similar functionalities to @actions/exec, such as executing shell commands and capturing their output. However, it is more low-level and requires more boilerplate code to achieve the same tasks.
ShellJS is a popular npm package that provides portable Unix shell commands for Node.js. It offers a higher-level API compared to 'child_process' and includes additional utilities for file system operations. While it is not specifically designed for GitHub Actions, it can be used to achieve similar command execution functionalities.
Execa is a modern npm package for executing shell commands in Node.js. It provides a promise-based API, better error handling, and more features compared to 'child_process'. Execa is a good alternative to @actions/exec for general-purpose command execution in Node.js applications.
@actions/exec
You can use this package to execute tools in a cross platform way:
const exec = require('@actions/exec');
await exec.exec('node index.js');
You can also pass in arg arrays:
const exec = require('@actions/exec');
await exec.exec('node', ['index.js', 'foo=bar']);
Capture output or specify other options:
const exec = require('@actions/exec');
let myOutput = '';
let myError = '';
const options = {};
options.listeners = {
stdout: (data: Buffer) => {
myOutput += data.toString();
},
stderr: (data: Buffer) => {
myError += data.toString();
}
};
options.cwd = './lib';
await exec.exec('node', ['index.js', 'foo=bar'], options);
You can specify the full path for tools not in the PATH:
const exec = require('@actions/exec');
await exec.exec('"/path/to/my-tool"', ['arg1']);
FAQs
Actions exec lib
We found that @actions/exec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.