From 6a588af9a7948a6e66f6be55d0364ee02442f850 Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Sun, 11 Apr 2021 18:53:28 +0200 Subject: [PATCH 1/2] Add getCommandOutput --- packages/exec/src/exec.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/exec/src/exec.ts b/packages/exec/src/exec.ts index 80a0363c49..a3cd1afde5 100644 --- a/packages/exec/src/exec.ts +++ b/packages/exec/src/exec.ts @@ -28,3 +28,36 @@ export async function exec( const runner: tr.ToolRunner = new tr.ToolRunner(toolPath, args, options) return runner.exec() } + +/** + * Get command output + * Returns promise with stdout + * + * @param commandLine command to execute (can include additional args). Must be correctly escaped. + * @param args optional arguments for tool. Escaping is handled by the lib. + * @param options optional exec options. See ExecOptions + * @returns Promise exit code + */ +export async function getCommandOutput( + commandLine: string, + args?: [], + options: Omit = {} +): Promise { + return new Promise((resolve, reject) => { + let out = '' + let err = '' + + const opts = { + ...options, + listeners: { + stdout: (data: Buffer) => (out += data.toString()), + stderr: (data: Buffer) => (err += data.toString()) + } + } + + exec(commandLine, args, opts).then(() => { + if (err) return reject(err) + resolve(out) + }) + }) +} From 2b42f70e3e8d92ca041c69ee78981fd939a32224 Mon Sep 17 00:00:00 2001 From: "Simen A. W. Olsen" Date: Sun, 11 Apr 2021 19:10:38 +0200 Subject: [PATCH 2/2] update releases.md --- packages/exec/RELEASES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/exec/RELEASES.md b/packages/exec/RELEASES.md index 0e99d15653..0dd2ead1c8 100644 --- a/packages/exec/RELEASES.md +++ b/packages/exec/RELEASES.md @@ -1,5 +1,9 @@ # @actions/exec Releases +### 1.1.0 + +- [Add `getCommandOutput`](https://github.com/actions/toolkit/pull/770) + ### 1.0.3 - [Add \"types\" to package.json](https://github.com/actions/toolkit/pull/221)