Skip to content

Add CommandRunner utility to @actions/exec #1562

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

nikolai-laevskii
Copy link
Contributor

Provides more feature-rich alternative for getExecOutput in order to to provide shortcuts for the most common use-cases.

  • encourages writing clean and readable code by allowing to chain different effects related to command executions
  • provides shorthands for the most common use-cases such as: failing action on command fail, throwing error on command fail, producing a specific log when command failed to execute
  • provides instruments to distinguish between different types of errors such as error during command execution (exitcode !== 0) and error to execute command itself
  • extended functionality allows to set different behavior for any amount of arbitrary types of errors or outputs (specific exitcode, output matching certain pattern, empty output, etc.)
  • can be tailored to specific needs on an individual project level or easily adjusted on a library level without breaking the backwards compatability
  • command arguments or options can be overwritten for a specific run which allows to create easily readable and extensible functions which correspond to different commands
const {stdout} = await exec.createCommandRunner(arbitraryCommand, [], {cwd})
  .onExitCode('> 0', 'throw') // default message will be autogenerated 
  .onEmptyOutput('throw')
  .on(['stderr', 'execerr'], 'throw') // can separately cover all other errors
  .run()

or even

const {stdout} = await exec.createCommandRunner(arbitraryCommand, [], {cwd})
  .on('!ok', 'throw') // will automatically figure out default message
  .run()

@nikolai-laevskii nikolai-laevskii requested a review from a team as a code owner October 16, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants