mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-07 20:35:33 -04:00
30 lines
947 B
TypeScript
30 lines
947 B
TypeScript
import { getExecOutput, ExecOptions } from '@actions/exec';
|
|
|
|
export async function execWithErrorCheck(
|
|
commandLine: string,
|
|
arguments_?: string[],
|
|
options?: ExecOptions,
|
|
errorWhenMissingUnityBuildResults: boolean = true,
|
|
): Promise<number> {
|
|
const result = await getExecOutput(commandLine, arguments_, options);
|
|
|
|
if (!errorWhenMissingUnityBuildResults) {
|
|
return result.exitCode;
|
|
}
|
|
|
|
// 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(`Could not find Build Results. Please read the logs for details.`);
|
|
}
|
|
|
|
return result.exitCode;
|
|
}
|