Skip to content

Run a command with captured output and signal forwarding

License

Notifications You must be signed in to change notification settings

retailnext/exec-action

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Execute Command Action

Linter CI Check dist/ CodeQL Coverage

A GitHub Action that executes an arbitrary command and captures its output, including stdout, stderr, and exit code. The action streams command output in real-time and forwards signals to the command.

Features

  • Execute any single command
  • Capture standard output, standard error, and exit code as action outputs
  • Stream output in real-time to the workflow logs
  • Forward signals (SIGINT, SIGTERM, SIGQUIT, SIGHUP, SIGPIPE, SIGABRT) to the running command
  • Commands are executed directly without a shell (no shell operators like |, &&, >)

IMPORTANT: This action executes commands directly without a shell. This means shell features like pipes (|), redirects (>), command chaining (&&, ||), and glob expansion (*) are not available.

Usage

steps:
  - name: Checkout
    uses: actions/checkout@v6

  - name: Execute Command
    id: exec
    uses: retailnext/exec-action@main
    with:
      command: 'echo "Hello World"'

  - name: Print Output
    run: |
      echo "Exit Code: ${{ steps.exec.outputs.exit_code }}"
      echo "Stdout: ${{ steps.exec.outputs.stdout }}"
      echo "Stderr: ${{ steps.exec.outputs.stderr }}"

Inputs

command

Required The command to execute with its arguments.

The command is executed directly without a shell. Executables in your PATH can be used without specifying the full path (e.g., npm, ls, git).

success_exit_codes

Optional Exit codes that should be treated as success. Can be individual codes (e.g., "0,1,2") or ranges (e.g., "0-2,5,10-15"). Default is "0".

This is useful when your command may exit with non-zero codes that should still be considered successful. For example, some linters return specific exit codes for warnings vs errors, or you may want to accept multiple exit codes as valid outcomes.

Outputs

stdout

The standard output of the executed command.

stderr

The standard error of the executed command.

exit_code

The exit code of the executed command (as a string).

Examples

Run a build command

- name: Build Project
  id: build
  uses: retailnext/exec-action@main
  with:
    command: 'npm run build'

- name: Check Build Status
  if: steps.build.outputs.exit_code == '0'
  run: echo "Build succeeded!"

Handle errors

- name: Run Command
  id: run
  uses: retailnext/exec-action@main
  with:
    command: 'some-command-that-might-fail'
  continue-on-error: true

- name: Handle Failure
  if: steps.run.outputs.exit_code != '0'
  run: |
    echo "Command failed with exit code ${{ steps.run.outputs.exit_code }}"
    echo "Error output: ${{ steps.run.outputs.stderr }}"

Accept multiple exit codes as success

- name: Run Linter
  uses: retailnext/exec-action@main
  with:
    command: 'eslint .'
    # Treat exit codes 0 (no issues) and 1 (warnings only) as success
    success_exit_codes: '0,1'

Accept a range of exit codes

- name: Run Tests
  uses: retailnext/exec-action@main
  with:
    command: 'pytest'
    # Treat exit codes 0-5 as success
    success_exit_codes: '0-5'

Mix individual codes and ranges

- name: Complex Command
  uses: retailnext/exec-action@main
  with:
    command: 'some-tool --check'
    # Accept 0, any code from 10-15, and 20 as success
    success_exit_codes: '0,10-15,20'

About

Run a command with captured output and signal forwarding

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •