Skip to content

Commit

Permalink
🔨 exec output refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mountainash committed Mar 11, 2024
1 parent b3cde51 commit f1b8ad7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 16 deletions.
34 changes: 26 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
34 changes: 26 additions & 8 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down

0 comments on commit f1b8ad7

Please sign in to comment.