Skip to content

Commit

Permalink
Graceful exit to ensure outputs get set
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKahr committed Nov 27, 2023
1 parent 525526b commit f7d4ece
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 92 deletions.
65 changes: 18 additions & 47 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 7 additions & 2 deletions src/model/cloud-runner/providers/docker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down
17 changes: 6 additions & 11 deletions src/model/docker.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<number> {
let runCommand = '';
switch (process.platform) {
Expand All @@ -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(
Expand Down
29 changes: 0 additions & 29 deletions src/model/exec-with-error-check.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/model/mac-builder.ts
Original file line number Diff line number Diff line change
@@ -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<number> {
return await execWithErrorCheck('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
return await exec('bash', [`${actionFolder}/platforms/mac/entrypoint.sh`], {
silent,
ignoreReturnCode: true,
});
}
}
Expand Down

0 comments on commit f7d4ece

Please sign in to comment.