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

174
dist/index.js vendored
View File

@ -2261,10 +2261,11 @@ 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* () {
cloud_runner_logger_1.default.log('Starting step 3/4 build compression'); try {
// Cleanup cloud_runner_logger_1.default.log('Starting step 3/4 build compression');
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, 'alpine', [ // Cleanup
` yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, 'alpine', [
`
printenv printenv
apk update -q apk update -q
apk add zip tree -q apk add zip tree -q
@ -2282,16 +2283,20 @@ class CompressionStep {
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull" ${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull" ${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`, `,
], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, [ ], `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, `/${cloud_runner_state_1.CloudRunnerState.buildVolumeFolder}`, [
...environmentVariables, ...environmentVariables,
...[ ...[
{ {
name: 'cacheFolderFull', name: 'cacheFolderFull',
value: cloud_runner_state_1.CloudRunnerState.cacheFolderFull, value: cloud_runner_state_1.CloudRunnerState.cacheFolderFull,
}, },
], ],
], 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,14 +2329,20 @@ 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* () {
yield DownloadRepositoryStep.downloadRepositoryStep(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets); try {
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* () {
cloud_runner_logger_1.default.log('Starting step 1/4 clone and restore cache'); try {
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [ cloud_runner_logger_1.default.log('Starting step 1/4 clone and restore cache');
` printenv yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [
` printenv
apk update -q apk update -q
apk add unzip zip git-lfs jq tree -q apk add unzip zip git-lfs jq tree -q
mkdir -p ${cloud_runner_state_1.CloudRunnerState.buildPathFull} mkdir -p ${cloud_runner_state_1.CloudRunnerState.buildPathFull}
@ -2346,7 +2357,11 @@ class DownloadRepositoryStep {
echo 'Starting checks of cache for the Unity project Library and git LFS files' echo 'Starting checks of cache for the Unity project Library and git LFS files'
${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,27 +2399,37 @@ 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* () {
yield BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image); try {
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* () {
cloud_runner_logger_1.default.log(`Cloud Runner is running standard build automation`); try {
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.log(`Cloud Runner is running standard build automation`);
cloud_runner_logger_1.default.logWithTime('Download repository step time'); 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));
if (cloud_runner_state_1.CloudRunnerState.buildParams.preBuildSteps !== '') { cloud_runner_logger_1.default.logWithTime('Download repository step time');
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.preBuildSteps); if (cloud_runner_state_1.CloudRunnerState.buildParams.preBuildSteps !== '') {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.preBuildSteps);
}
cloud_runner_logger_1.default.logWithTime('Pre build step(s) time');
new build_step_1.BuildStep().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
cloud_runner_logger_1.default.logWithTime('Build time');
yield new compression_step_1.CompressionStep().run(new cloud_runner_step_state_1.CloudRunnerStepState('alpine', cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
cloud_runner_logger_1.default.logWithTime('Compression time');
if (cloud_runner_state_1.CloudRunnerState.buildParams.postBuildSteps !== '') {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.postBuildSteps);
}
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.logWithTime('Pre build step(s) time'); catch (error) {
new build_step_1.BuildStep().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets)); throw error;
cloud_runner_logger_1.default.logWithTime('Build time');
yield new compression_step_1.CompressionStep().run(new cloud_runner_step_state_1.CloudRunnerStepState('alpine', cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
cloud_runner_logger_1.default.logWithTime('Compression time');
if (cloud_runner_state_1.CloudRunnerState.buildParams.postBuildSteps !== '') {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.postBuildSteps);
} }
cloud_runner_logger_1.default.logWithTime('Post build step(s) time');
cloud_runner_logger_1.default.log(`Cloud Runner finished running standard build automation`);
}); });
} }
} }
@ -2438,18 +2463,23 @@ 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* () {
cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`); try {
buildSteps = yaml_1.default.parse(buildSteps); cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`);
for (const step of buildSteps) { buildSteps = yaml_1.default.parse(buildSteps);
const stepSecrets = step.secrets.map((x) => { for (const step of buildSteps) {
const secret = { const stepSecrets = step.secrets.map((x) => {
ParameterKey: x.name, const secret = {
EnvironmentVariable: x.name, ParameterKey: x.name,
ParameterValue: x.value, EnvironmentVariable: x.name,
}; ParameterValue: x.value,
return secret; };
}); return secret;
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* () {
yield EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(cloudRunnerStepState.image, cloudRunnerStepState.environment, cloudRunnerStepState.secrets); try {
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* () {
cloud_runner_logger_1.default.log(`Cloud Runner is running in ephemeral GitHub runner mode`); try {
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'; cloud_runner_logger_1.default.log(`Cloud Runner is running in ephemeral GitHub runner mode`);
yield cloud_runner_state_1.CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(cloud_runner_state_1.CloudRunnerState.buildGuid, image, [installAndStartRunner], `/runner`, `/runner`, environmentVariables, secrets); 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,23 +2584,33 @@ 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* () {
yield WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString()); try {
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* () {
core.info(`Custom build steps: ${cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps}`); try {
if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === '') { core.info(`Custom build steps: ${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)); 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));
}
else if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === 'ephemeral') {
yield new ephemeral_github_runner_workflow_1.EphemeralGitHubRunnerWorkflow().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets));
}
else if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === 'download') {
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));
}
else {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps);
}
} }
else if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === 'ephemeral') { catch (error) {
yield new ephemeral_github_runner_workflow_1.EphemeralGitHubRunnerWorkflow().run(new cloud_runner_step_state_1.CloudRunnerStepState(baseImage, cloud_runner_state_1.CloudRunnerState.readBuildEnvironmentVariables(), cloud_runner_state_1.CloudRunnerState.defaultSecrets)); throw error;
}
else if (cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps === 'download') {
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));
}
else {
yield custom_workflow_1.CustomWorkflow.runCustomJob(cloud_runner_state_1.CloudRunnerState.buildParams.customBuildSteps);
} }
}); });
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -14,13 +14,14 @@ export class CompressionStep implements StepInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
CloudRunnerLogger.log('Starting step 3/4 build compression'); try {
// Cleanup CloudRunnerLogger.log('Starting step 3/4 build compression');
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( // Cleanup
CloudRunnerState.buildGuid, await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
'alpine', CloudRunnerState.buildGuid,
[ 'alpine',
` [
`
printenv printenv
apk update -q apk update -q
apk add zip tree -q apk add zip tree -q
@ -38,20 +39,23 @@ export class CompressionStep implements StepInterface {
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull" ${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull" ${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`, `,
],
`/${CloudRunnerState.buildVolumeFolder}`,
`/${CloudRunnerState.buildVolumeFolder}`,
[
...environmentVariables,
...[
{
name: 'cacheFolderFull',
value: CloudRunnerState.cacheFolderFull,
},
], ],
], `/${CloudRunnerState.buildVolumeFolder}`,
secrets, `/${CloudRunnerState.buildVolumeFolder}`,
); [
CloudRunnerLogger.log('compression step complete'); ...environmentVariables,
...[
{
name: 'cacheFolderFull',
value: CloudRunnerState.cacheFolderFull,
},
],
],
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 { export class DownloadRepositoryStep implements StepInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
await DownloadRepositoryStep.downloadRepositoryStep( try {
cloudRunnerStepState.image, await DownloadRepositoryStep.downloadRepositoryStep(
cloudRunnerStepState.environment, cloudRunnerStepState.image,
cloudRunnerStepState.secrets, cloudRunnerStepState.environment,
); cloudRunnerStepState.secrets,
);
} catch (error) {
throw error;
}
} }
private static async downloadRepositoryStep( private static async downloadRepositoryStep(
@ -19,12 +23,13 @@ export class DownloadRepositoryStep implements StepInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
CloudRunnerLogger.log('Starting step 1/4 clone and restore cache'); try {
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( CloudRunnerLogger.log('Starting step 1/4 clone and restore cache');
CloudRunnerState.buildGuid, await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
image, CloudRunnerState.buildGuid,
[ image,
` printenv [
` printenv
apk update -q apk update -q
apk add unzip zip git-lfs jq tree -q apk add unzip zip git-lfs jq tree -q
mkdir -p ${CloudRunnerState.buildPathFull} mkdir -p ${CloudRunnerState.buildPathFull}
@ -39,11 +44,14 @@ export class DownloadRepositoryStep implements StepInterface {
echo 'Starting checks of cache for the Unity project Library and git LFS files' echo 'Starting checks of cache for the Unity project Library and git LFS files'
${CloudRunnerState.getHandleCachingCommand()} ${CloudRunnerState.getHandleCachingCommand()}
`, `,
], ],
`/${CloudRunnerState.buildVolumeFolder}`, `/${CloudRunnerState.buildVolumeFolder}`,
`/${CloudRunnerState.buildVolumeFolder}/`, `/${CloudRunnerState.buildVolumeFolder}/`,
environmentVariables, environmentVariables,
secrets, secrets,
); );
} catch (error) {
throw error;
}
} }
} }

View File

@ -9,48 +9,56 @@ import { WorkflowInterface } from './workflow-interface';
export class BuildAutomationWorkflow implements WorkflowInterface { export class BuildAutomationWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image); try {
await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image);
} catch (error) {
throw error;
}
} }
private static async standardBuildAutomation(baseImage: any) { private static async standardBuildAutomation(baseImage: any) {
CloudRunnerLogger.log(`Cloud Runner is running standard build automation`); try {
CloudRunnerLogger.log(`Cloud Runner is running standard build automation`);
await new DownloadRepositoryStep().run( await new DownloadRepositoryStep().run(
new CloudRunnerStepState( new CloudRunnerStepState(
'alpine/git', 'alpine/git',
CloudRunnerState.readBuildEnvironmentVariables(), CloudRunnerState.readBuildEnvironmentVariables(),
CloudRunnerState.defaultSecrets, CloudRunnerState.defaultSecrets,
), ),
); );
CloudRunnerLogger.logWithTime('Download repository step time'); CloudRunnerLogger.logWithTime('Download repository step time');
if (CloudRunnerState.buildParams.preBuildSteps !== '') { if (CloudRunnerState.buildParams.preBuildSteps !== '') {
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.preBuildSteps); await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.preBuildSteps);
}
CloudRunnerLogger.logWithTime('Pre build step(s) time');
new BuildStep().run(
new CloudRunnerStepState(
baseImage,
CloudRunnerState.readBuildEnvironmentVariables(),
CloudRunnerState.defaultSecrets,
),
);
CloudRunnerLogger.logWithTime('Build time');
await new CompressionStep().run(
new CloudRunnerStepState(
'alpine',
CloudRunnerState.readBuildEnvironmentVariables(),
CloudRunnerState.defaultSecrets,
),
);
CloudRunnerLogger.logWithTime('Compression time');
if (CloudRunnerState.buildParams.postBuildSteps !== '') {
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.postBuildSteps);
}
CloudRunnerLogger.logWithTime('Post build step(s) time');
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
} catch (error) {
throw error;
} }
CloudRunnerLogger.logWithTime('Pre build step(s) time');
new BuildStep().run(
new CloudRunnerStepState(
baseImage,
CloudRunnerState.readBuildEnvironmentVariables(),
CloudRunnerState.defaultSecrets,
),
);
CloudRunnerLogger.logWithTime('Build time');
await new CompressionStep().run(
new CloudRunnerStepState(
'alpine',
CloudRunnerState.readBuildEnvironmentVariables(),
CloudRunnerState.defaultSecrets,
),
);
CloudRunnerLogger.logWithTime('Compression time');
if (CloudRunnerState.buildParams.postBuildSteps !== '') {
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.postBuildSteps);
}
CloudRunnerLogger.logWithTime('Post build step(s) time');
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
} }
} }

View File

@ -5,26 +5,30 @@ import YAML from 'yaml';
export class CustomWorkflow { export class CustomWorkflow {
public static async runCustomJob(buildSteps) { public static async runCustomJob(buildSteps) {
CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`); try {
buildSteps = YAML.parse(buildSteps); CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`);
for (const step of buildSteps) { buildSteps = YAML.parse(buildSteps);
const stepSecrets: CloudRunnerSecret[] = step.secrets.map((x) => { for (const step of buildSteps) {
const secret: CloudRunnerSecret = { const stepSecrets: CloudRunnerSecret[] = step.secrets.map((x) => {
ParameterKey: x.name, const secret: CloudRunnerSecret = {
EnvironmentVariable: x.name, ParameterKey: x.name,
ParameterValue: x.value, EnvironmentVariable: x.name,
}; ParameterValue: x.value,
return secret; };
}); return secret;
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( });
CloudRunnerState.buildGuid, await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
step['image'], CloudRunnerState.buildGuid,
step['commands'], step['image'],
`/${CloudRunnerState.buildVolumeFolder}`, step['commands'],
`/${CloudRunnerState.buildVolumeFolder}`, `/${CloudRunnerState.buildVolumeFolder}`,
CloudRunnerState.defaultGitShaEnvironmentVariable, `/${CloudRunnerState.buildVolumeFolder}`,
[...CloudRunnerState.defaultSecrets, ...stepSecrets], CloudRunnerState.defaultGitShaEnvironmentVariable,
); [...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) {
await EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner( try {
cloudRunnerStepState.image, await EphemeralGitHubRunnerWorkflow.runJobAsEphemeralGitHubRunner(
cloudRunnerStepState.environment, cloudRunnerStepState.image,
cloudRunnerStepState.secrets, cloudRunnerStepState.environment,
); cloudRunnerStepState.secrets,
);
} catch (error) {
throw error;
}
} }
private static async runJobAsEphemeralGitHubRunner( private static async runJobAsEphemeralGitHubRunner(
@ -19,17 +23,21 @@ export class EphemeralGitHubRunnerWorkflow implements WorkflowInterface {
environmentVariables: CloudRunnerEnvironmentVariable[], environmentVariables: CloudRunnerEnvironmentVariable[],
secrets: CloudRunnerSecret[], secrets: CloudRunnerSecret[],
) { ) {
CloudRunnerLogger.log(`Cloud Runner is running in ephemeral GitHub runner mode`); try {
const installAndStartRunner = CloudRunnerLogger.log(`Cloud Runner is running in ephemeral GitHub runner mode`);
' 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 =
await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask( ' 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';
CloudRunnerState.buildGuid, await CloudRunnerState.CloudRunnerProviderPlatform.runBuildTask(
image, CloudRunnerState.buildGuid,
[installAndStartRunner], image,
`/runner`, [installAndStartRunner],
`/runner`, `/runner`,
environmentVariables, `/runner`,
secrets, environmentVariables,
); secrets,
);
} catch (error) {
throw error;
}
} }
} }

View File

@ -9,37 +9,45 @@ import { BuildAutomationWorkflow } from './build-automation-workflow';
export class WorkflowCompositionRoot implements WorkflowInterface { export class WorkflowCompositionRoot implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepState) { async run(cloudRunnerStepState: CloudRunnerStepState) {
await WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString()); try {
await WorkflowCompositionRoot.runJob(cloudRunnerStepState.image.toString());
} catch (error) {
throw error;
}
} }
private static async runJob(baseImage: any) { private static async runJob(baseImage: any) {
core.info(`Custom build steps: ${CloudRunnerState.buildParams.customBuildSteps}`); try {
if (CloudRunnerState.buildParams.customBuildSteps === '') { core.info(`Custom build steps: ${CloudRunnerState.buildParams.customBuildSteps}`);
await new BuildAutomationWorkflow().run( if (CloudRunnerState.buildParams.customBuildSteps === '') {
new CloudRunnerStepState( await new BuildAutomationWorkflow().run(
baseImage, new CloudRunnerStepState(
CloudRunnerState.readBuildEnvironmentVariables(), baseImage,
CloudRunnerState.defaultSecrets, CloudRunnerState.readBuildEnvironmentVariables(),
), CloudRunnerState.defaultSecrets,
); ),
} else if (CloudRunnerState.buildParams.customBuildSteps === 'ephemeral') { );
await new EphemeralGitHubRunnerWorkflow().run( } else if (CloudRunnerState.buildParams.customBuildSteps === 'ephemeral') {
new CloudRunnerStepState( await new EphemeralGitHubRunnerWorkflow().run(
baseImage, new CloudRunnerStepState(
CloudRunnerState.readBuildEnvironmentVariables(), baseImage,
CloudRunnerState.defaultSecrets, CloudRunnerState.readBuildEnvironmentVariables(),
), CloudRunnerState.defaultSecrets,
); ),
} else if (CloudRunnerState.buildParams.customBuildSteps === 'download') { );
await new DownloadRepositoryStep().run( } else if (CloudRunnerState.buildParams.customBuildSteps === 'download') {
new CloudRunnerStepState( await new DownloadRepositoryStep().run(
'alpine/git', new CloudRunnerStepState(
CloudRunnerState.readBuildEnvironmentVariables(), 'alpine/git',
CloudRunnerState.defaultSecrets, CloudRunnerState.readBuildEnvironmentVariables(),
), CloudRunnerState.defaultSecrets,
); ),
} else { );
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.customBuildSteps); } else {
await CustomWorkflow.runCustomJob(CloudRunnerState.buildParams.customBuildSteps);
}
} catch (error) {
throw error;
} }
} }
} }