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