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

actions/exec: add timeout option to exec function #1778

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading