Graceful exit to ensure outputs get set
parent
525526ba97
commit
f7d4ece67f
|
@ -69,6 +69,9 @@ async function runMain() {
|
||||||
await model_1.Output.setBuildVersion(buildParameters.buildVersion);
|
await model_1.Output.setBuildVersion(buildParameters.buildVersion);
|
||||||
await model_1.Output.setAndroidVersionCode(buildParameters.androidVersionCode);
|
await model_1.Output.setAndroidVersionCode(buildParameters.androidVersionCode);
|
||||||
await model_1.Output.setExitCode(exitCode);
|
await model_1.Output.setExitCode(exitCode);
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
core.setFailed(`Build failed with exit code ${exitCode}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
|
@ -3293,7 +3296,7 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
|
||||||
if (fs.existsSync(`${workspace}/cloud-runner-cache`)) {
|
if (fs.existsSync(`${workspace}/cloud-runner-cache`)) {
|
||||||
await cloud_runner_system_1.CloudRunnerSystem.Run(`ls ${workspace}/cloud-runner-cache && du -sh ${workspace}/cloud-runner-cache`);
|
await cloud_runner_system_1.CloudRunnerSystem.Run(`ls ${workspace}/cloud-runner-cache && du -sh ${workspace}/cloud-runner-cache`);
|
||||||
}
|
}
|
||||||
await docker_1.default.run(image, { workspace, actionFolder, ...this.buildParameters }, false, `chmod +x /github/workspace/${entrypointFilePath} && /github/workspace/${entrypointFilePath}`, content, {
|
const exitCode = await docker_1.default.run(image, { workspace, actionFolder, ...this.buildParameters }, false, `chmod +x /github/workspace/${entrypointFilePath} && /github/workspace/${entrypointFilePath}`, content, {
|
||||||
listeners: {
|
listeners: {
|
||||||
stdout: (data) => {
|
stdout: (data) => {
|
||||||
myOutput += data.toString();
|
myOutput += data.toString();
|
||||||
|
@ -3302,7 +3305,12 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
|
||||||
myOutput += `[LOCAL-DOCKER-ERROR]${data.toString()}`;
|
myOutput += `[LOCAL-DOCKER-ERROR]${data.toString()}`;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, true, false);
|
}, true);
|
||||||
|
// 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;
|
return myOutput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5895,14 +5903,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const exec_with_error_check_1 = __nccwpck_require__(3161);
|
|
||||||
const image_environment_factory_1 = __importDefault(__nccwpck_require__(25145));
|
const image_environment_factory_1 = __importDefault(__nccwpck_require__(25145));
|
||||||
const node_fs_1 = __nccwpck_require__(87561);
|
const node_fs_1 = __nccwpck_require__(87561);
|
||||||
const node_path_1 = __importDefault(__nccwpck_require__(49411));
|
const node_path_1 = __importDefault(__nccwpck_require__(49411));
|
||||||
|
const exec_1 = __nccwpck_require__(71514);
|
||||||
class Docker {
|
class Docker {
|
||||||
static async run(image, parameters, silent = false, overrideCommands = '', additionalVariables = [],
|
static async run(image, parameters, silent = false, overrideCommands = '', additionalVariables = [], options = {}, entrypointBash = false) {
|
||||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
||||||
options = undefined, entrypointBash = false, errorWhenMissingUnityBuildResults = false) {
|
|
||||||
let runCommand = '';
|
let runCommand = '';
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
case 'linux':
|
case 'linux':
|
||||||
|
@ -5911,13 +5917,9 @@ class Docker {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
runCommand = this.getWindowsCommand(image, parameters);
|
runCommand = this.getWindowsCommand(image, parameters);
|
||||||
}
|
}
|
||||||
if (options) {
|
options.silent = silent;
|
||||||
options.silent = silent;
|
options.ignoreReturnCode = true;
|
||||||
return await (0, exec_with_error_check_1.execWithErrorCheck)(runCommand, undefined, options, errorWhenMissingUnityBuildResults);
|
return await (0, exec_1.exec)(runCommand, undefined, options);
|
||||||
}
|
|
||||||
else {
|
|
||||||
return await (0, exec_with_error_check_1.execWithErrorCheck)(runCommand, undefined, { silent }, errorWhenMissingUnityBuildResults);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
static getLinuxCommand(image, parameters, overrideCommands = '', additionalVariables = [], entrypointBash = false) {
|
static getLinuxCommand(image, parameters, overrideCommands = '', additionalVariables = [], entrypointBash = false) {
|
||||||
const { workspace, actionFolder, runnerTempPath, sshAgent, sshPublicKeysDirectoryPath, gitPrivateToken, dockerWorkspacePath, dockerCpuLimit, dockerMemoryLimit, } = parameters;
|
const { workspace, actionFolder, runnerTempPath, sshAgent, sshPublicKeysDirectoryPath, gitPrivateToken, dockerWorkspacePath, dockerCpuLimit, dockerMemoryLimit, } = parameters;
|
||||||
|
@ -6017,38 +6019,6 @@ class ValidationError extends Error {
|
||||||
exports["default"] = ValidationError;
|
exports["default"] = ValidationError;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
|
||||||
|
|
||||||
/***/ 3161:
|
|
||||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
|
||||||
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
||||||
exports.execWithErrorCheck = void 0;
|
|
||||||
const exec_1 = __nccwpck_require__(71514);
|
|
||||||
async function execWithErrorCheck(commandLine, arguments_, options, errorWhenMissingUnityBuildResults = false) {
|
|
||||||
const result = await (0, exec_1.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;
|
|
||||||
}
|
|
||||||
exports.execWithErrorCheck = execWithErrorCheck;
|
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 83654:
|
/***/ 83654:
|
||||||
|
@ -6987,11 +6957,12 @@ exports["default"] = Input;
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
const exec_with_error_check_1 = __nccwpck_require__(3161);
|
const exec_1 = __nccwpck_require__(71514);
|
||||||
class MacBuilder {
|
class MacBuilder {
|
||||||
static async run(actionFolder, silent = false) {
|
static async run(actionFolder, silent = false) {
|
||||||
return await (0, exec_with_error_check_1.execWithErrorCheck)('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
return await (0, exec_1.exec)('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
||||||
silent,
|
silent,
|
||||||
|
ignoreReturnCode: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -40,6 +40,10 @@ async function runMain() {
|
||||||
await Output.setBuildVersion(buildParameters.buildVersion);
|
await Output.setBuildVersion(buildParameters.buildVersion);
|
||||||
await Output.setAndroidVersionCode(buildParameters.androidVersionCode);
|
await Output.setAndroidVersionCode(buildParameters.androidVersionCode);
|
||||||
await Output.setExitCode(exitCode);
|
await Output.setExitCode(exitCode);
|
||||||
|
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
core.setFailed(`Build failed with exit code ${exitCode}`);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed((error as Error).message);
|
core.setFailed((error as Error).message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
|
||||||
if (fs.existsSync(`${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 CloudRunnerSystem.Run(`ls ${workspace}/cloud-runner-cache && du -sh ${workspace}/cloud-runner-cache`);
|
||||||
}
|
}
|
||||||
await Docker.run(
|
const exitCode = await Docker.run(
|
||||||
image,
|
image,
|
||||||
{ workspace, actionFolder, ...this.buildParameters },
|
{ workspace, actionFolder, ...this.buildParameters },
|
||||||
false,
|
false,
|
||||||
|
@ -150,9 +150,14 @@ cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
true,
|
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;
|
return myOutput;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { execWithErrorCheck } from './exec-with-error-check';
|
|
||||||
import ImageEnvironmentFactory from './image-environment-factory';
|
import ImageEnvironmentFactory from './image-environment-factory';
|
||||||
import { existsSync, mkdirSync } from 'node:fs';
|
import { existsSync, mkdirSync } from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { ExecOptions } from '@actions/exec';
|
import { ExecOptions, exec } from '@actions/exec';
|
||||||
import { DockerParameters, StringKeyValuePair } from './shared-types';
|
import { DockerParameters, StringKeyValuePair } from './shared-types';
|
||||||
|
|
||||||
class Docker {
|
class Docker {
|
||||||
|
@ -12,10 +11,8 @@ class Docker {
|
||||||
silent: boolean = false,
|
silent: boolean = false,
|
||||||
overrideCommands: string = '',
|
overrideCommands: string = '',
|
||||||
additionalVariables: StringKeyValuePair[] = [],
|
additionalVariables: StringKeyValuePair[] = [],
|
||||||
// eslint-disable-next-line unicorn/no-useless-undefined
|
options: ExecOptions = {},
|
||||||
options: ExecOptions | undefined = undefined,
|
|
||||||
entrypointBash: boolean = false,
|
entrypointBash: boolean = false,
|
||||||
errorWhenMissingUnityBuildResults: boolean = false,
|
|
||||||
): Promise<number> {
|
): Promise<number> {
|
||||||
let runCommand = '';
|
let runCommand = '';
|
||||||
switch (process.platform) {
|
switch (process.platform) {
|
||||||
|
@ -25,13 +22,11 @@ class Docker {
|
||||||
case 'win32':
|
case 'win32':
|
||||||
runCommand = this.getWindowsCommand(image, parameters);
|
runCommand = this.getWindowsCommand(image, parameters);
|
||||||
}
|
}
|
||||||
if (options) {
|
|
||||||
options.silent = silent;
|
|
||||||
|
|
||||||
return await execWithErrorCheck(runCommand, undefined, options, errorWhenMissingUnityBuildResults);
|
options.silent = silent;
|
||||||
} else {
|
options.ignoreReturnCode = true;
|
||||||
return await execWithErrorCheck(runCommand, undefined, { silent }, errorWhenMissingUnityBuildResults);
|
|
||||||
}
|
return await exec(runCommand, undefined, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getLinuxCommand(
|
static getLinuxCommand(
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
import { ExecOptions, getExecOutput } from '@actions/exec';
|
|
||||||
|
|
||||||
export async function execWithErrorCheck(
|
|
||||||
commandLine: string,
|
|
||||||
arguments_?: string[],
|
|
||||||
options?: ExecOptions,
|
|
||||||
errorWhenMissingUnityBuildResults: boolean = false,
|
|
||||||
): 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(`There was an error building the project. Please read the logs for details.`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result.exitCode;
|
|
||||||
}
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { execWithErrorCheck } from './exec-with-error-check';
|
import { exec } from '@actions/exec';
|
||||||
|
|
||||||
class MacBuilder {
|
class MacBuilder {
|
||||||
public static async run(actionFolder: string, silent: boolean = false): Promise<number> {
|
public static async run(actionFolder: string, silent: boolean = false): Promise<number> {
|
||||||
return await execWithErrorCheck('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
return await exec('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
|
||||||
silent,
|
silent,
|
||||||
|
ignoreReturnCode: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue