Skip to content

Commit

Permalink
stdline and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Uchkunev committed Feb 3, 2025
1 parent 1c006ef commit 04a52e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 73 deletions.
39 changes: 7 additions & 32 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

41 changes: 8 additions & 33 deletions src/execute.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { type ExecOptions, type ExecOutput, getExecOutput } from '@actions/exec'
import path from 'path'
import { internalActionVariables } from './piper'
import { error, notice } from '@actions/core'
import { error } from '@actions/core'

export interface piperExecResult {
output: string
Expand All @@ -20,44 +20,19 @@ export async function executePiper (

const piperPath = internalActionVariables.piperBinPath
const containerID = internalActionVariables.dockerContainerID

const piperError = ''
let piperError = ''
let options = {
listeners: {
stdline: (data: string) => {
if (data.includes('fatal')) error(`${data.toString()}`)
if (data.includes('fatal')) error(data)
piperError += data
},
errline: (data: string) => {
if (data.includes('fatal')) error(`${data.toString()}`)
if (data.includes('fatal')) {
error(data)
piperError += data
}
}
// stdout: (data: Buffer) => {
// let outString: string = ''
// const inString: string = data.toString()
// inString.split('\n').forEach(line => {
// if (line.includes('fatal')) {
// notice(`stdout line contains fatal: ${line}`)
// outString += `::error::${line}\n`
// } else {
// outString += `${line}\n`
// }
// })
// data = Buffer.from(outString)
// },
// stderr: (data: Buffer) => {
// let outString: string = ''
// const inString = data.toString()
// inString.split('\n').forEach(line => {
// if (line.includes('fatal')) {
// notice(` stderr line contains fatal: ${line}`)
// outString += `::error::${line}\n`
// piperError += `::error::${line}\n`
// } else {
// outString += `${line}\n`
// piperError += `${line}\n`
// }
// })
// data = Buffer.from(outString)
// }
}
}
options = Object.assign({}, options, execOptions)
Expand Down
14 changes: 7 additions & 7 deletions test/execute.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Execute', () => {
const stageNameArg = ['--stageName', 'units']

beforeEach(() => {
jest.spyOn(exec, 'exec').mockReturnValue(Promise.resolve(0))
jest.spyOn(exec, 'getExecOutput').mockReturnValue(Promise.resolve({ stdout: 'testout', stderr: 'testerr', exitCode: 0 }))

process.env.GITHUB_JOB = stageNameArg[1]

Expand All @@ -36,7 +36,7 @@ describe('Execute', () => {
const stepName = 'version'

const piperExec = await executePiper(stepName)
expect(exec.exec).toHaveBeenCalledWith(piperPath, [stepName, ...stageNameArg], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith(piperPath, [stepName, ...stageNameArg], expectedOptions)
expect(piperExec.exitCode).toBe(0)
})

Expand All @@ -45,7 +45,7 @@ describe('Execute', () => {
const piperFlags = ['--verbose']

const piperExec = await executePiper(stepName, piperFlags)
expect(exec.exec).toHaveBeenCalledWith(piperPath, [stepName, ...piperFlags], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith(piperPath, [stepName, ...piperFlags], expectedOptions)
expect(piperFlags).toEqual(expect.arrayContaining(stageNameArg))
expect(piperExec.exitCode).toBe(0)
})
Expand All @@ -55,7 +55,7 @@ describe('Execute', () => {
const piperFlags = ['--createBOM', '--globalSettingsFile', 'global_settings.xml']

const piperExec = await executePiper(stepName, piperFlags)
expect(exec.exec).toHaveBeenCalledWith(piperPath, [stepName, ...piperFlags], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith(piperPath, [stepName, ...piperFlags], expectedOptions)
expect(piperFlags).toEqual(expect.arrayContaining(stageNameArg))
expect(piperExec.exitCode).toBe(0)
})
Expand All @@ -66,7 +66,7 @@ describe('Execute', () => {
internalActionVariables.dockerContainerID = dockerContainerID

const piperExec = await executePiper(stepName, undefined)
expect(exec.exec).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...stageNameArg], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...stageNameArg], expectedOptions)
expect(piperExec.exitCode).toBe(0)
})

Expand All @@ -77,7 +77,7 @@ describe('Execute', () => {
internalActionVariables.dockerContainerID = dockerContainerID

const piperExec = await executePiper(stepName, piperFlags)
expect(exec.exec).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...piperFlags], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...piperFlags], expectedOptions)
expect(piperFlags).toEqual(expect.arrayContaining(stageNameArg))
expect(piperExec.exitCode).toBe(0)
})
Expand All @@ -89,7 +89,7 @@ describe('Execute', () => {
internalActionVariables.dockerContainerID = dockerContainerID

const piperExec = await executePiper(stepName, piperFlags)
expect(exec.exec).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...piperFlags], expectedOptions)
expect(exec.getExecOutput).toHaveBeenCalledWith('docker', ['exec', dockerContainerID, '/piper/piper', stepName, ...piperFlags], expectedOptions)
expect(piperFlags).toEqual(expect.arrayContaining(stageNameArg))
expect(piperExec.exitCode).toBe(0)
})
Expand Down

0 comments on commit 04a52e1

Please sign in to comment.