From b89cf0a1f77c83d1bb37d2dcf2755c61812cb063 Mon Sep 17 00:00:00 2001 From: Valentin Uchkunev Date: Fri, 31 Jan 2025 12:33:08 +0200 Subject: [PATCH] add red printing --- .gitignore | 1 + src/execute.ts | 48 ++++++++++++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 60c14d10..57d09140 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ go*linux-amd64.tar.gz .idea/ reports/ **/.DS_store +pnpm-lock.yaml diff --git a/src/execute.ts b/src/execute.ts index d2d7c87f..739fd1e8 100644 --- a/src/execute.ts +++ b/src/execute.ts @@ -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 } } } @@ -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` }