Skip to content
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

Add Command Wrapper for getExecOutput #5

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

Conversation

dusan-trickovic
Copy link

@dusan-trickovic dusan-trickovic commented Sep 1, 2023

Link to the corresponding issue: https://github.com/actions/setup-actions-team/issues/40

In the scope of this PR:

  • Added the logic for the new class called CommandHelper and a method that wraps the aforementioned exec method
  • Added some basic unit tests (for now they are only on Linux, but that will be expanded in further commits)

Update (September 21): The unit tests now include (work on) all platforms.

Update (October):
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()

packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
packages/helpers/src/exec-command-wrapper.ts Outdated Show resolved Hide resolved
@nikolai-laevskii nikolai-laevskii self-assigned this Oct 12, 2023
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.

4 participants