Skip to content

Commit

Permalink
actions/exec: add timeout option to exec function
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Jul 28, 2024
1 parent 49927e4 commit f528bc2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/exec/__tests__/exec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,15 @@ describe('@actions/exec', () => {
expect(stdout).toBe('©')
})

it('allows to specify timeouts on running the child process', async () => {
const options = getExecOptions()
// The `cat` command will be killed after 100ms
options.timeout = 100
await expect(exec.exec('cat', [], options)).rejects.toThrowError(
'failed with exit code null'
)
})

if (IS_WINDOWS) {
it('Exec roots relative tool path using process.cwd (Windows path separator)', async () => {
let exitCode: number
Expand Down
3 changes: 3 additions & 0 deletions packages/exec/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export interface ExecOptions {
/** optional. How long in ms to wait for STDIO streams to close after the exit event of the process before terminating. defaults to 10000 */
delay?: number

/** optional. Timeout in ms for the child process */
timeout?: number

/** optional. input to write to the process on STDIN. */
input?: Buffer

Expand Down
1 change: 1 addition & 0 deletions packages/exec/src/toolrunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export class ToolRunner extends events.EventEmitter {
const result = <child.SpawnOptions>{}
result.cwd = options.cwd
result.env = options.env
result.timeout = options.timeout
result['windowsVerbatimArguments'] =
options.windowsVerbatimArguments || this._isCmdFile()
if (options.windowsVerbatimArguments) {
Expand Down

0 comments on commit f528bc2

Please sign in to comment.