From f1b8ad7a12156779dcd2a4442d9cf10cebb02342 Mon Sep 17 00:00:00 2001 From: "Mountain/\\Ash" Date: Mon, 11 Mar 2024 22:30:51 +0100 Subject: [PATCH] :hammer: exec output refactor --- dist/index.js | 34 ++++++++++++++++++++++++++-------- src/helpers.js | 34 ++++++++++++++++++++++++++-------- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/dist/index.js b/dist/index.js index be8a4d1f..01856a29 100644 --- a/dist/index.js +++ b/dist/index.js @@ -32219,32 +32219,50 @@ module.exports = { /***/ 5946: /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { +const { StringDecoder } = __nccwpck_require__(1576) + const core = __nccwpck_require__(2186) const { exec } = __nccwpck_require__(1514) const execCmd = async (command, args, cwd) => { const options = {} let stdout = '' - let stderr = '🔺 ' + let stderr = '' + let exitCode = 0 + + const stdoutDecoder = new StringDecoder('utf8') + const stderrDecoder = new StringDecoder('utf8') options.listeners = { stdout: (data) => { - stdout += data.toString() + stdout += stdoutDecoder.write(data) }, stderr: (data) => { - stderr += data.toString() + stderr += stderrDecoder.write(data) } } - options.cwd = cwd + + if (cwd !== '') { + options.cwd = cwd + } + + options.silent = false core.info(`▻ EXEC: "${ command } ${ args }"`) - const exitCode = await exec(command, args, options) + + try { + exitCode = await exec(command, args, options) + } catch (error) { + exitCode = 1 + } + + stdout += stdoutDecoder.end() + stderr += stderrDecoder.end() if (exitCode === 0) - throw new Error(`${ stderr } - ${ stdout.trim() }`) + return stdout.trim() - core.info(stdout) - return stdout.trim() + throw new Error(`${ command } ${ args.join(' ') } returned code ${ exitCode } \nSTDOUT: ${ stdout }\nSTDERR: ${ stderr }`) } const addSchema = (url) => { diff --git a/src/helpers.js b/src/helpers.js index b8cfb872..688579b5 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -1,29 +1,47 @@ +const { StringDecoder } = require('string_decoder') + const core = require('@actions/core') const { exec } = require('@actions/exec') const execCmd = async (command, args, cwd) => { const options = {} let stdout = '' - let stderr = '🔺 ' + let stderr = '' + let exitCode = 0 + + const stdoutDecoder = new StringDecoder('utf8') + const stderrDecoder = new StringDecoder('utf8') options.listeners = { stdout: (data) => { - stdout += data.toString() + stdout += stdoutDecoder.write(data) }, stderr: (data) => { - stderr += data.toString() + stderr += stderrDecoder.write(data) } } - options.cwd = cwd + + if (cwd !== '') { + options.cwd = cwd + } + + options.silent = false core.info(`▻ EXEC: "${ command } ${ args }"`) - const exitCode = await exec(command, args, options) + + try { + exitCode = await exec(command, args, options) + } catch (error) { + exitCode = 1 + } + + stdout += stdoutDecoder.end() + stderr += stderrDecoder.end() if (exitCode === 0) - throw new Error(`${ stderr } - ${ stdout.trim() }`) + return stdout.trim() - core.info(stdout) - return stdout.trim() + throw new Error(`${ command } ${ args.join(' ') } returned code ${ exitCode } \nSTDOUT: ${ stdout }\nSTDERR: ${ stderr }`) } const addSchema = (url) => {