Skip to content

Commit

Permalink
add red printing
Browse files Browse the repository at this point in the history
  • Loading branch information
bitmaskit committed Jan 31, 2025
1 parent abab7f5 commit b89cf0a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ go*linux-amd64.tar.gz
.idea/
reports/
**/.DS_store
pnpm-lock.yaml
48 changes: 28 additions & 20 deletions src/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export async function executePiper (
let options = {
listeners: {
stdout: (data: Buffer) => {
piperOutput += data.toString()
const outString = data.toString()
piperOutput += outString.includes('fatal') ? toRedConsole(outString) : outString
},
stderr: (data: Buffer) => {
piperError += data.toString()
const outString = data.toString()
piperError += outString.includes('fatal') ? toRedConsole(outString) : outString
}
}
}
Expand All @@ -39,33 +41,39 @@ export async function executePiper (

const piperPath = internalActionVariables.piperBinPath
const containerID = internalActionVariables.dockerContainerID
if (containerID === '') {
return await exec(piperPath, [
stepName,
...flags
],
options)
.then(exitCode => {
return { output: piperOutput, error: piperError, exitCode }
})
.catch(err => {
throw new Error(`Piper execution error: ${err as string}: ${piperError}`)
})
} else {
return await exec('docker', [
if (containerID !== '') { // Running in a container
const args: string[] = [
'exec',
containerID,
`/piper/${path.basename(piperPath)}`,
stepName,
...flags
], options).then(exitCode => {

]
return await exec('docker', args, options)
.then(exitCode => {
return {
output: piperOutput,
error: piperError,
exitCode
}
})
.catch(err => { throw new Error(`Piper execution error: ${err as string}: ${piperError}`) })
}

const args: string[] = [stepName, ...flags]

return await exec(piperPath, args, options)
.then(exitCode => {
return {
output: piperOutput,
error: piperError,
exitCode
}
}).catch(err => {
throw new Error(`Piper execution error: ${err as string}: ${piperError}`)
})
}
.catch(err => { throw new Error(`Piper execution error: ${err as string}: ${piperError}`) })
}

function toRedConsole (message: string): string {
return `\x1b[31m${message}\x1b[0m`
}

0 comments on commit b89cf0a

Please sign in to comment.