2020-08-16 00:36:41 +02:00
|
|
|
import * as aexec from '@actions/exec';
|
|
|
|
import {ExecOptions} from '@actions/exec';
|
|
|
|
|
|
|
|
export interface ExecResult {
|
|
|
|
success: boolean;
|
|
|
|
stdout: string;
|
|
|
|
stderr: string;
|
|
|
|
}
|
|
|
|
|
2020-10-21 21:07:52 +02:00
|
|
|
export const exec = async (command: string, args: string[] = [], silent?: boolean): Promise<ExecResult> => {
|
2020-08-16 00:36:41 +02:00
|
|
|
let stdout: string = '';
|
|
|
|
let stderr: string = '';
|
|
|
|
|
|
|
|
const options: ExecOptions = {
|
|
|
|
silent: silent,
|
|
|
|
ignoreReturnCode: true
|
|
|
|
};
|
|
|
|
options.listeners = {
|
|
|
|
stdout: (data: Buffer) => {
|
|
|
|
stdout += data.toString();
|
|
|
|
},
|
|
|
|
stderr: (data: Buffer) => {
|
|
|
|
stderr += data.toString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const returnCode: number = await aexec.exec(command, args, options);
|
|
|
|
|
|
|
|
return {
|
|
|
|
success: returnCode === 0,
|
|
|
|
stdout: stdout.trim(),
|
|
|
|
stderr: stderr.trim()
|
|
|
|
};
|
|
|
|
};
|