1
0
Fork 0

actions/exec: add `timeout` option to `exec` function

Fixes #1777
pull/1778/head
rhysd 2024-07-28 19:13:02 +09:00
parent 49927e464a
commit f528bc2d18
3 changed files with 13 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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) {