Group version output in the worklflow

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-04-09 19:46:24 +05:30
parent 133ced04cc
commit a986183b13
4 changed files with 32 additions and 16 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -43,7 +43,7 @@ export class BuildahCli implements Buildah {
this.storageOptsEnv = `overlay.mount_program=${fuseOverlayfsPath}`; this.storageOptsEnv = `overlay.mount_program=${fuseOverlayfsPath}`;
} }
else { else {
core.warning(`"fuse-overlayfs" is not found. Install it before running this action.` core.warning(`"fuse-overlayfs" is not found. Install it before running this action. `
+ `For more detail see https://github.com/redhat-actions/buildah-build/issues/45`); + `For more detail see https://github.com/redhat-actions/buildah-build/issues/45`);
} }
} }
@ -163,7 +163,10 @@ export class BuildahCli implements Buildah {
return `${arrayAsString.slice(0, -1)}]`; return `${arrayAsString.slice(0, -1)}]`;
} }
async execute(args: string[], execOptions: exec.ExecOptions = {}): Promise<CommandResult> { async execute(
args: string[],
execOptions: exec.ExecOptions & { group?: boolean } = {},
): Promise<CommandResult> {
// ghCore.info(`${EXECUTABLE} ${args.join(" ")}`) // ghCore.info(`${EXECUTABLE} ${args.join(" ")}`)
let stdout = ""; let stdout = "";
@ -181,6 +184,11 @@ export class BuildahCli implements Buildah {
}, },
}; };
if (execOptions.group) {
const groupName = [ this.executable, ...args ].join(" ");
core.startGroup(groupName);
}
// To solve https://github.com/redhat-actions/buildah-build/issues/45 // To solve https://github.com/redhat-actions/buildah-build/issues/45
const execEnv: { [key: string] : string } = {}; const execEnv: { [key: string] : string } = {};
Object.entries(process.env).forEach(([ key, value ]) => { Object.entries(process.env).forEach(([ key, value ]) => {
@ -195,20 +203,28 @@ export class BuildahCli implements Buildah {
finalExecOptions.env = execEnv; finalExecOptions.env = execEnv;
const exitCode = await exec.exec(this.executable, args, finalExecOptions); try {
const exitCode = await exec.exec(this.executable, args, finalExecOptions);
if (execOptions.ignoreReturnCode !== true && exitCode !== 0) { if (execOptions.ignoreReturnCode !== true && exitCode !== 0) {
// Throwing the stderr as part of the Error makes the stderr // Throwing the stderr as part of the Error makes the stderr
// show up in the action outline, which saves some clicking when debugging. // show up in the action outline, which saves some clicking when debugging.
let error = `${path.basename(this.executable)} exited with code ${exitCode}`; let error = `${path.basename(this.executable)} exited with code ${exitCode}`;
if (stderr) { if (stderr) {
error += `\n${stderr}`; error += `\n${stderr}`;
}
throw new Error(error);
} }
throw new Error(error);
return {
exitCode, output: stdout, error: stderr,
};
} }
return { finally {
exitCode, output: stdout, error: stderr, if (execOptions.group) {
}; core.endGroup();
}
}
} }
} }

View file

@ -14,7 +14,7 @@ export async function run(): Promise<void> {
const cli: BuildahCli = new BuildahCli(buildahPath); const cli: BuildahCli = new BuildahCli(buildahPath);
// print buildah version // print buildah version
await cli.execute([ "version" ]); await cli.execute([ "version" ], { group: true });
// Check if fuse-overlayfs exists and find the storage driver // Check if fuse-overlayfs exists and find the storage driver
await cli.setStorageOptsEnv(); await cli.setStorageOptsEnv();