Try catch for async

pull/310/head
Frostebite 2021-11-21 17:20:11 +00:00
parent 1c232c49f5
commit 0c23ded1e9
8 changed files with 294 additions and 204 deletions

50
dist/index.js vendored
View File

@ -2261,6 +2261,7 @@ class CompressionStep {
} }
static CompressionStep(environmentVariables, secrets) { static CompressionStep(environmentVariables, secrets) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log('Starting step 3/4 build compression'); cloud_runner_logger_1.default.log('Starting step 3/4 build compression');
// Cleanup // Cleanup
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, 'alpine', [ yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, 'alpine', [
@ -2292,6 +2293,10 @@ class CompressionStep {
], ],
], secrets); ], secrets);
cloud_runner_logger_1.default.log('compression step complete'); cloud_runner_logger_1.default.log('compression step complete');
}
catch (error) {
throw error;
}
}); });
} }
} }
@ -2324,11 +2329,17 @@ const cloud_runner_state_1 = __webpack_require__(70912);
class DownloadRepositoryStep { class DownloadRepositoryStep {
run(cloudRunnerStepState) { run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield DownloadRepositoryStep.downloadRepositoryStep(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets); yield DownloadRepositoryStep.downloadRepositoryStep(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
}
catch (error) {
throw error;
}
}); });
} }
static downloadRepositoryStep(image, environmentVariables, secrets) { static downloadRepositoryStep(image, environmentVariables, secrets) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log('Starting step 1/4 clone and restore cache'); cloud_runner_logger_1.default.log('Starting step 1/4 clone and restore cache');
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [ yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [
` printenv ` printenv
@ -2347,6 +2358,10 @@ class DownloadRepositoryStep {
${cloud_runner_state_1.CloudRunnerState.getHandleCachingCommand()} ${cloud_runner_state_1.CloudRunnerState.getHandleCachingCommand()}
`, `,
], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}/`, environmentVariables, secrets); ], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}/`, environmentVariables, secrets);
}
catch (error) {
throw error;
}
}); });
} }
} }
@ -2384,11 +2399,17 @@ const custom_workflow_1 = __webpack_require__(3786);
class BuildAutomationWorkflow { class BuildAutomationWorkflow {
run(cloudRunnerStepState) { run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image); yield BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image);
}
catch (error) {
throw error;
}
}); });
} }
static standardBuildAutomation(baseImage) { static standardBuildAutomation(baseImage) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log(`Cloud Runner is running standard build automation`); cloud_runner_logger_1.default.log(`Cloud Runner is running standard build automation`);
yield new download_repository_step_1.DownloadRepositoryStep().run(new cloud_runner_step_state_1.CloudRunnerStepState('alpine/git', cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets)); yield new download_repository_step_1.DownloadRepositoryStep().run(new cloud_runner_step_state_1.CloudRunnerStepState('alpine/git', cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
cloud_runner_logger_1.default.logWithTime('Download repository step time'); cloud_runner_logger_1.default.logWithTime('Download repository step time');
@ -2405,6 +2426,10 @@ class BuildAutomationWorkflow {
} }
cloud_runner_logger_1.default.logWithTime('Post build step(s) time'); cloud_runner_logger_1.default.logWithTime('Post build step(s) time');
cloud_runner_logger_1.default.log(`Cloud Runner finished running standard build automation`); cloud_runner_logger_1.default.log(`Cloud Runner finished running standard build automation`);
}
catch (error) {
throw error;
}
}); });
} }
} }
@ -2438,6 +2463,7 @@ const yaml_1 = __importDefault(__webpack_require__(13552));
class CustomWorkflow { class CustomWorkflow {
static runCustomJob(buildSteps) { static runCustomJob(buildSteps) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`); cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`);
buildSteps = yaml_1.default.parse(buildSteps); buildSteps = yaml_1.default.parse(buildSteps);
for (const step of buildSteps) { for (const step of buildSteps) {
@ -2451,6 +2477,10 @@ class CustomWorkflow {
}); });
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, step['image'], step['commands'], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, cloud_runner_state_1.CloudRunnerState.defaultGitShaEnvironmentVariable, [...cloud_runner_state_1.CloudRunnerState.defaultSecrets, ...stepSecrets]); yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, step['image'], step['commands'], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, cloud_runner_state_1.CloudRunnerState.defaultGitShaEnvironmentVariable, [...cloud_runner_state_1.CloudRunnerState.defaultSecrets, ...stepSecrets]);
} }
}
catch (error) {
throw error;
}
}); });
} }
} }
@ -2483,14 +2513,24 @@ const cloud_runner_state_1 = __webpack_require__(70912);
class EphemeralGitHubRunnerWorkflow { class EphemeralGitHubRunnerWorkflow {
run(cloudRunnerStepState) { run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets); yield EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
}
catch (error) {
throw error;
}
}); });
} }
static runJobAsEphemeralGitHubRunner(image, environmentVariables, secrets) { static runJobAsEphemeralGitHubRunner(image, environmentVariables, secrets) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log(`Cloud Runner is running in ephemeral GitHub runner mode`); cloud_runner_logger_1.default.log(`Cloud Runner is running in ephemeral GitHub runner mode`);
const installAndStartRunner = ' cd .. & cd .. && ls && mkdir actions-runner && cd actions-runner && curl -O -L https://github.com/actions/runner/releases/download/v2.283.1/actions-runner-linux-x64-2.283.1.tar.gz && tar xzf ./actions-runner-linux-x64-2.283.1.tar.gz'; const installAndStartRunner = ' cd .. & cd .. && ls && mkdir actions-runner && cd actions-runner && curl -O -L https://github.com/actions/runner/releases/download/v2.283.1/actions-runner-linux-x64-2.283.1.tar.gz && tar xzf ./actions-runner-linux-x64-2.283.1.tar.gz';
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [installAndStartRunner], `/runner`, `/runner`, environmentVariables, secrets); yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [installAndStartRunner], `/runner`, `/runner`, environmentVariables, secrets);
}
catch (error) {
throw error;
}
}); });
} }
} }
@ -2544,11 +2584,17 @@ const build_automation_workflow_1 = __webpack_require__(94655);
class WorkflowCompositionRoot { class WorkflowCompositionRoot {
run(cloudRunnerStepState) { run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
yield WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString()); yield WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString());
}
catch (error) {
throw error;
}
}); });
} }
static runJob(baseImage) { static runJob(baseImage) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try {
core.info(`Custom build steps: ${cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps}`); core.info(`Custom build steps: ${cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps}`);
if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === '') { if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === '') {
yield new build_automation_workflow_1.BuildAutomationWorkflow().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets)); yield new build_automation_workflow_1.BuildAutomationWorkflow().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
@ -2562,6 +2608,10 @@ class WorkflowCompositionRoot {
else { else {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps); yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps);
} }
}
catch (error) {
throw error;
}
}); });
} }
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -14,6 +14,7 @@ export class CompressionStep implements StepInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
try {
CloudRunnerLogger.log('Starting step 3/4 build compression'); CloudRunnerLogger.log('Starting step 3/4 build compression');
// Cleanup // Cleanup
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
@ -53,5 +54,8 @@ export class CompressionStep implements StepInterface {
secrets, secrets,
); );
CloudRunnerLogger.log('compression step complete'); CloudRunnerLogger.log('compression step complete');
} catch (error) {
throw error;
}
} }
} }

View File

@ -7,11 +7,15 @@ import { StepInterface } from './step-interface';
export class DownloadRepositoryStep implements StepInterface { export class DownloadRepositoryStep implements StepInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await DownloadRepositoryStep.downloadRepositoryStep( await DownloadRepositoryStep.downloadRepositoryStep(
cloudRunnerStepState.image, cloudRunnerStepState.image,
cloudRunnerStepState.environment, cloudRunnerStepState.environment,
cloudRunnerStepState.secrets, cloudRunnerStepState.secrets,
); );
} catch (error) {
throw error;
}
} }
private static async downloadRepositoryStep( private static async downloadRepositoryStep(
@ -19,6 +23,7 @@ export class DownloadRepositoryStep implements StepInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
try {
CloudRunnerLogger.log('Starting step 1/4 clone and restore cache'); CloudRunnerLogger.log('Starting step 1/4 clone and restore cache');
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
CloudRunnerState.buildGuid, CloudRunnerState.buildGuid,
@ -45,5 +50,8 @@ export class DownloadRepositoryStep implements StepInterface {
environmentVariables, environmentVariables,
secrets, secrets,
); );
} catch (error) {
throw error;
}
} }
} }

View File

@ -9,10 +9,15 @@ import { WorkflowInterface } from './workflow-interface';
export class BuildAutomationWorkflow implements WorkflowInterface { export class BuildAutomationWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image); await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image);
} catch (error) {
throw error;
}
} }
private static async standardBuildAutomation(baseImage: any) { private static async standardBuildAutomation(baseImage: any) {
try {
CloudRunnerLogger.log(`Cloud Runner is running standard build automation`); CloudRunnerLogger.log(`Cloud Runner is running standard build automation`);
await new DownloadRepositoryStep().run( await new DownloadRepositoryStep().run(
@ -52,5 +57,8 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
CloudRunnerLogger.logWithTime('Post build step(s) time'); CloudRunnerLogger.logWithTime('Post build step(s) time');
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`); CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
} catch (error) {
throw error;
}
} }
} }

View File

@ -5,6 +5,7 @@ import YAML from 'yaml';
export class CustomWorkflow { export class CustomWorkflow {
public static async runCustomJob(buildSteps) { public static async runCustomJob(buildSteps) {
try {
CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`); CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`);
buildSteps = YAML.parse(buildSteps); buildSteps = YAML.parse(buildSteps);
for (const step of buildSteps) { for (const step of buildSteps) {
@ -26,5 +27,8 @@ export class CustomWorkflow {
[...CloudRunnerState.defaultSecrets, ...stepSecrets], [...CloudRunnerState.defaultSecrets, ...stepSecrets],
); );
} }
} catch (error) {
throw error;
}
} }
} }

View File

@ -7,11 +7,15 @@ import { WorkflowInterface } from './workflow-interface';
export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface { export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner( await EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(
cloudRunnerStepState.image, cloudRunnerStepState.image,
cloudRunnerStepState.environment, cloudRunnerStepState.environment,
cloudRunnerStepState.secrets, cloudRunnerStepState.secrets,
); );
} catch (error) {
throw error;
}
} }
private static async runJobAsEphemeralGitHubRunner( private static async runJobAsEphemeralGitHubRunner(
@ -19,6 +23,7 @@ export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
try {
CloudRunnerLogger.log(`Cloud Runner is running in ephemeral GitHub runner mode`); CloudRunnerLogger.log(`Cloud Runner is running in ephemeral GitHub runner mode`);
const installAndStartRunner = const installAndStartRunner =
' cd .. & cd .. && ls && mkdir actions-runner && cd actions-runner && curl -O -L https://github.com/actions/runner/releases/download/v2.283.1/actions-runner-linux-x64-2.283.1.tar.gz && tar xzf ./actions-runner-linux-x64-2.283.1.tar.gz'; ' cd .. & cd .. && ls && mkdir actions-runner && cd actions-runner && curl -O -L https://github.com/actions/runner/releases/download/v2.283.1/actions-runner-linux-x64-2.283.1.tar.gz && tar xzf ./actions-runner-linux-x64-2.283.1.tar.gz';
@ -31,5 +36,8 @@ export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
environmentVariables, environmentVariables,
secrets, secrets,
); );
} catch (error) {
throw error;
}
} }
} }

View File

@ -9,10 +9,15 @@ import { BuildAutomationWorkflow } from './build-automation-workflow';
export class WorkflowCompositionRoot implements WorkflowInterface { export class WorkflowCompositionRoot implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString()); await WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString());
} catch (error) {
throw error;
}
} }
private static async runJob(baseImage: any) { private static async runJob(baseImage: any) {
try {
core.info(`Custom build steps: ${CloudRunnerState.buildParams.customBuildSteps}`); core.info(`Custom build steps: ${CloudRunnerState.buildParams.customBuildSteps}`);
if (CloudRunnerState.buildParams.customBuildSteps === '') { if (CloudRunnerState.buildParams.customBuildSteps === '') {
await new BuildAutomationWorkflow().run( await new BuildAutomationWorkflow().run(
@ -41,5 +46,8 @@ export class WorkflowCompositionRoot implements WorkflowInterface {
} else { } else {
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.customBuildSteps); await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.customBuildSteps);
} }
} catch (error) {
throw error;
}
} }
} }