diff --git a/dist/index.js b/dist/index.js index 08c80b07..21d73e14 100644 Binary files a/dist/index.js and b/dist/index.js differ diff --git a/dist/index.js.map b/dist/index.js.map index 6266331f..dde444c0 100644 Binary files a/dist/index.js.map and b/dist/index.js.map differ diff --git a/src/index.ts b/src/index.ts index 413ace33..9e11f34c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,6 +40,10 @@ async function runMain() { await Output.setBuildVersion(buildParameters.buildVersion); await Output.setAndroidVersionCode(buildParameters.androidVersionCode); await Output.setExitCode(exitCode); + + if (exitCode !== 0) { + core.setFailed(`Build failed with exit code ${exitCode}`); + } } catch (error) { core.setFailed((error as Error).message); } diff --git a/src/model/cloud-runner/providers/docker/index.ts b/src/model/cloud-runner/providers/docker/index.ts index 6837b1a9..42044182 100644 --- a/src/model/cloud-runner/providers/docker/index.ts +++ b/src/model/cloud-runner/providers/docker/index.ts @@ -133,7 +133,7 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/ if (fs.existsSync(`${workspace}/cloud-runner-cache`)) { await CloudRunnerSystem.Run(`ls ${workspace}/cloud-runner-cache && du -sh ${workspace}/cloud-runner-cache`); } - await Docker.run( + const exitCode = await Docker.run( image, { workspace, actionFolder, ...this.buildParameters }, false, @@ -150,9 +150,14 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/ }, }, true, - false, ); + // Docker doesn't exit on fail now so adding this to ensure behavior is unchanged + // TODO: Is there a helpful way to consume the exit code or is it best to except + if (exitCode !== 0) { + throw new Error(`Build failed with exit code ${exitCode}`); + } + return myOutput; } } diff --git a/src/model/docker.ts b/src/model/docker.ts index 815bccae..6d7b2843 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -1,8 +1,7 @@ -import { execWithErrorCheck } from './exec-with-error-check'; import ImageEnvironmentFactory from './image-environment-factory'; import { existsSync, mkdirSync } from 'node:fs'; import path from 'node:path'; -import { ExecOptions } from '@actions/exec'; +import { ExecOptions, exec } from '@actions/exec'; import { DockerParameters, StringKeyValuePair } from './shared-types'; class Docker { @@ -12,10 +11,8 @@ class Docker { silent: boolean = false, overrideCommands: string = '', additionalVariables: StringKeyValuePair[] = [], - // eslint-disable-next-line unicorn/no-useless-undefined - options: ExecOptions | undefined = undefined, + options: ExecOptions = {}, entrypointBash: boolean = false, - errorWhenMissingUnityBuildResults: boolean = false, ): Promise { let runCommand = ''; switch (process.platform) { @@ -25,13 +22,11 @@ class Docker { case 'win32': runCommand = this.getWindowsCommand(image, parameters); } - if (options) { - options.silent = silent; - return await execWithErrorCheck(runCommand, undefined, options, errorWhenMissingUnityBuildResults); - } else { - return await execWithErrorCheck(runCommand, undefined, { silent }, errorWhenMissingUnityBuildResults); - } + options.silent = silent; + options.ignoreReturnCode = true; + + return await exec(runCommand, undefined, options); } static getLinuxCommand( diff --git a/src/model/exec-with-error-check.ts b/src/model/exec-with-error-check.ts deleted file mode 100644 index 3fe3030b..00000000 --- a/src/model/exec-with-error-check.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { ExecOptions, getExecOutput } from '@actions/exec'; - -export async function execWithErrorCheck( - commandLine: string, - arguments_?: string[], - options?: ExecOptions, - errorWhenMissingUnityBuildResults: boolean = false, -): Promise { - 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(`There was an error building the project. Please read the logs for details.`); - } - - return result.exitCode; -} diff --git a/src/model/mac-builder.ts b/src/model/mac-builder.ts index 7524f961..1d4ddecf 100644 --- a/src/model/mac-builder.ts +++ b/src/model/mac-builder.ts @@ -1,9 +1,10 @@ -import { execWithErrorCheck } from './exec-with-error-check'; +import { exec } from '@actions/exec'; class MacBuilder { public static async run(actionFolder: string, silent: boolean = false): Promise { - return await execWithErrorCheck('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], { + return await exec('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], { silent, + ignoreReturnCode: true, }); } }