2023-02-14 05:07:10 +00:00
|
|
|
import { getExecOutput, ExecOptions } from '@actions/exec';
|
|
|
|
|
|
|
|
|
|
export async function execWithErrorCheck(
|
|
|
|
|
commandLine: string,
|
|
|
|
|
arguments_?: string[],
|
|
|
|
|
options?: ExecOptions,
|
2023-03-27 11:14:23 +00:00
|
|
|
errorWhenMissingUnityBuildResults: boolean = true,
|
2023-02-14 05:07:10 +00:00
|
|
|
): Promise<number> {
|
|
|
|
|
const result = await getExecOutput(commandLine, arguments_, options);
|
|
|
|
|
|
2023-03-27 11:14:23 +00:00
|
|
|
if (!errorWhenMissingUnityBuildResults) {
|
|
|
|
|
return result.exitCode;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 05:07:10 +00:00
|
|
|
// Check for errors in the Build Results section
|
|
|
|
|
const match = result.stdout.match(/^#\s*Build results\s*#(.*)^Size:/ms);
|
|
|
|
|
|
|
|
|
|
if (match) {
|
|
|
|
|
const buildResults = match[1];
|
|
|
|
|
const errorMatch = buildResults.match(/^Errors:\s*(\d+)$/m);
|
|
|
|
|
if (errorMatch && Number.parseInt(errorMatch[1], 10) !== 0) {
|
|
|
|
|
throw new Error(`There was an error building the project. Please read the logs for details.`);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(`There was an error building the project. Please read the logs for details.`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result.exitCode;
|
|
|
|
|
}
|