This is a reusable action for GitHub Actions. This action just runs a single command and captures the outputs. Easy to use and useful to capture multi-line outputs.
The way to capture a command's multi-line standard output / error is not intuitive on GitHub Actions.
- set-output Truncates Multiline Strings - #9 by andreasplesch - GitHub Actions - GitHub Community
- set-env truncates multiline strings Β· Issue #403 Β· actions/toolkit Β· GitHub
Use this action gh640/command-result-action
in your workflow with command
input.
uses: gh640/command-result-action@v1
with:
command: npm outdated
id: myaction
You can optionally change the working directory by passing cwd
as input:
uses: gh640/command-result-action@v1
with:
command: npm outdated
cwd: ./src
id: myaction
You can use the output in subsequent steps. In the above case, the following variables are available:
${{ steps.myaction.outputs.exitCode }}
${{ steps.myaction.outputs.stdout }}
${{ steps.myaction.outputs.stderr }}
name | required | description |
---|---|---|
command |
β | Command to run |
cwd |
Working directory |
name | description |
---|---|
exitCode |
Exit code of the command |
stdout |
Stdout of the command |
stderr |
Stderr of the command |
Change this
run: npm outdated
working-directory: ./src
id: myaction
to
uses: gh640/command-result-action@v1
with:
command: npm outdated
cwd: ./src
id: myaction
Please keep in mind that the run will not fail and subsequent steps will be executed even if the command exit code is not 0
when using gh640/command-result-action
.
This action uses @actions/exec
and @actions/core
. The behavior of this action is almost same as one of the following action with actions/github-script
:
uses: actions/github-script@v6
with:
script: |
const result = await exec.getExecOutput('npm outdated', [], {
ignoreReturnCode: true,
})
core.setOutput('exitCode', result.exitCode)
core.setOutput('stdout', result.stdout)
core.setOutput('stderr', result.stderr)
id: myaction
No. This action supports only one command.