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) {
return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log('Starting step 3/4 build compression');
// Cleanup
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, 'alpine', [
@ -2292,6 +2293,10 @@ class CompressionStep {
],
], secrets);
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 {
run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield DownloadRepositoryStep.downloadRepositoryStep(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
}
catch (error) {
throw error;
}
});
}
static downloadRepositoryStep(image, environmentVariables, secrets) {
return __awaiter(this, void 0, void 0, function* () {
try {
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, [
` printenv
@ -2347,6 +2358,10 @@ class DownloadRepositoryStep {
${cloud_runner_state_1.CloudRunnerState.getHandleCachingCommand()}
`,
], `/${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 {
run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image);
}
catch (error) {
throw error;
}
});
}
static standardBuildAutomation(baseImage) {
return __awaiter(this, void 0, void 0, function* () {
try {
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));
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.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 {
static runCustomJob(buildSteps) {
return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`);
buildSteps = yaml_1.default.parse(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]);
}
}
catch (error) {
throw error;
}
});
}
}
@ -2483,14 +2513,24 @@ const cloud_runner_state_1 = __webpack_require__(70912);
class EphemeralGitHubRunnerWorkflow {
run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
}
catch (error) {
throw error;
}
});
}
static runJobAsEphemeralGitHubRunner(image, environmentVariables, secrets) {
return __awaiter(this, void 0, void 0, function* () {
try {
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';
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 {
run(cloudRunnerStepState) {
return __awaiter(this, void 0, void 0, function* () {
try {
yield WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString());
}
catch (error) {
throw error;
}
});
}
static runJob(baseImage) {
return __awaiter(this, void 0, void 0, function* () {
try {
core.info(`Custom build steps: ${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));
@ -2562,6 +2608,10 @@ class WorkflowCompositionRoot {
else {
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[],
secrets: CloudRunnerSecret[],
) {
try {
CloudRunnerLogger.log('Starting step 3/4 build compression');
// Cleanup
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
@ -53,5 +54,8 @@ export class CompressionStep implements StepInterface {
secrets,
);
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 {
async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await DownloadRepositoryStep.downloadRepositoryStep(
cloudRunnerStepState.image,
cloudRunnerStepState.environment,
cloudRunnerStepState.secrets,
);
} catch (error) {
throw error;
}
}
private static async downloadRepositoryStep(
@ -19,6 +23,7 @@ export class DownloadRepositoryStep implements StepInterface {
environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[],
) {
try {
CloudRunnerLogger.log('Starting step 1/4 clone and restore cache');
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
CloudRunnerState.buildGuid,
@ -45,5 +50,8 @@ export class DownloadRepositoryStep implements StepInterface {
environmentVariables,
secrets,
);
} catch (error) {
throw error;
}
}
}

View File

@ -9,10 +9,15 @@ import { WorkflowInterface } from './workflow-interface';
export class BuildAutomationWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image);
} catch (error) {
throw error;
}
}
private static async standardBuildAutomation(baseImage: any) {
try {
CloudRunnerLogger.log(`Cloud Runner is running standard build automation`);
await new DownloadRepositoryStep().run(
@ -52,5 +57,8 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
CloudRunnerLogger.logWithTime('Post build step(s) time');
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 {
public static async runCustomJob(buildSteps) {
try {
CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`);
buildSteps = YAML.parse(buildSteps);
for (const step of buildSteps) {
@ -26,5 +27,8 @@ export class CustomWorkflow {
[...CloudRunnerState.defaultSecrets, ...stepSecrets],
);
}
} catch (error) {
throw error;
}
}
}

View File

@ -7,11 +7,15 @@ import { WorkflowInterface } from './workflow-interface';
export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) {
try {
await EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(
cloudRunnerStepState.image,
cloudRunnerStepState.environment,
cloudRunnerStepState.secrets,
);
} catch (error) {
throw error;
}
}
private static async runJobAsEphemeralGitHubRunner(
@ -19,6 +23,7 @@ export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[],
) {
try {
CloudRunnerLogger.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';
@ -31,5 +36,8 @@ export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
environmentVariables,
secrets,
);
} catch (error) {
throw error;
}
}
}

View File

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