mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-06-07 17:31:35 +00:00
Copy exec over from oc-login for better error reporting
Signed-off-by: Tim Etchells <tetchell@redhat.com>
This commit is contained in:
parent
00654bad07
commit
fd4cb345bf
3 changed files with 30 additions and 20 deletions
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
|
import * as path from "path";
|
||||||
|
|
||||||
interface Buildah {
|
interface Buildah {
|
||||||
buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean): Promise<CommandResult>;
|
buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean): Promise<CommandResult>;
|
||||||
|
@ -103,29 +104,38 @@ export class BuildahCli implements Buildah {
|
||||||
return `${arrayAsString.slice(0, -1)}]`;
|
return `${arrayAsString.slice(0, -1)}]`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async execute(args: string[]): Promise<CommandResult> {
|
private async execute(args: string[], execOptions: exec.ExecOptions = {}): Promise<CommandResult> {
|
||||||
if (!this.executable) {
|
|
||||||
throw new Error('Unable to call buildah executable');
|
|
||||||
}
|
|
||||||
|
|
||||||
let stdOut = '';
|
// ghCore.info(`${EXECUTABLE} ${args.join(" ")}`)
|
||||||
let stdErr = '';
|
|
||||||
|
|
||||||
const options: exec.ExecOptions = {};
|
let stdout = "";
|
||||||
options.listeners = {
|
let stderr = "";
|
||||||
stdout: (data: Buffer): void => {
|
|
||||||
stdOut += data.toString();
|
const finalExecOptions = { ...execOptions };
|
||||||
|
finalExecOptions.ignoreReturnCode = true; // the return code is processed below
|
||||||
|
|
||||||
|
finalExecOptions.listeners = {
|
||||||
|
stdline: (line) => {
|
||||||
|
stdout += line + "\n";
|
||||||
|
},
|
||||||
|
errline: (line) => {
|
||||||
|
stderr += line + "\n"
|
||||||
},
|
},
|
||||||
stderr: (data: Buffer): void => {
|
|
||||||
stdErr += data.toString();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const exitCode = await exec.exec(this.executable, args, options);
|
|
||||||
if (exitCode !== 0) {
|
|
||||||
throw new Error(`Buildah exited with code ${exitCode}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const exitCode = await exec.exec(this.executable, args, finalExecOptions);
|
||||||
|
|
||||||
|
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {
|
||||||
|
// Throwing the stderr as part of the Error makes the stderr show up in the action outline, which saves some clicking when debugging.
|
||||||
|
let error = `${path.basename(this.executable)} exited with code ${exitCode}`;
|
||||||
|
if (stderr) {
|
||||||
|
error += `\n${stderr}`;
|
||||||
|
}
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
exitCode, output: stdOut, error: stdErr
|
exitCode, output: stdout, error: stderr
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue