2021-12-31 17:52:01 +00:00
|
|
|
import { BuildParameters, Input } from '../..';
|
2022-01-01 17:44:41 +00:00
|
|
|
import YAML from 'yaml';
|
|
|
|
|
import CloudRunnerSecret from './cloud-runner-secret';
|
|
|
|
|
import CloudRunnerLogger from './cloud-runner-logger';
|
2021-12-29 19:08:41 +00:00
|
|
|
|
2021-12-29 16:28:42 +00:00
|
|
|
export class CloudRunnerBuildCommandProcessor {
|
2021-12-29 19:08:41 +00:00
|
|
|
public static ProcessCommands(commands: string, buildParameters: BuildParameters): string {
|
2022-01-01 18:20:36 +00:00
|
|
|
const hooks = CloudRunnerBuildCommandProcessor.getHooks().filter((x) => x.step.includes(`all`));
|
2022-01-01 17:44:41 +00:00
|
|
|
|
2021-12-29 17:04:06 +00:00
|
|
|
return `echo "---"
|
2021-12-31 19:01:35 +00:00
|
|
|
echo "start cloud runner init"
|
2021-12-31 17:52:01 +00:00
|
|
|
${Input.cloudRunnerTests ? '' : '#'} printenv
|
2021-12-31 19:01:35 +00:00
|
|
|
echo "start cloud runner job"
|
2022-01-01 18:20:36 +00:00
|
|
|
${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
|
2021-12-29 17:04:06 +00:00
|
|
|
${commands}
|
2022-01-01 18:20:36 +00:00
|
|
|
${hooks.filter((x) => x.hook.includes(`after`)).map((x) => x.commands) || ' '}
|
2021-12-31 19:01:35 +00:00
|
|
|
echo "end of cloud runner job
|
|
|
|
|
---${buildParameters.logId}"
|
2021-12-29 17:04:06 +00:00
|
|
|
`;
|
2021-12-29 16:28:42 +00:00
|
|
|
}
|
2022-01-01 17:44:41 +00:00
|
|
|
|
|
|
|
|
public static getHooks(): Hook[] {
|
|
|
|
|
const experimentHooks = process.env.EXPERIMENTAL_HOOKS;
|
2022-01-01 17:52:19 +00:00
|
|
|
let output = new Array<Hook>();
|
2022-01-01 17:44:41 +00:00
|
|
|
if (experimentHooks && experimentHooks !== '') {
|
|
|
|
|
try {
|
|
|
|
|
output = YAML.parse(experimentHooks);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-01-01 18:20:36 +00:00
|
|
|
if (Input.cloudRunnerTests) {
|
|
|
|
|
CloudRunnerLogger.log(`Getting hooks: ${JSON.stringify(output, undefined, 4)}`);
|
|
|
|
|
}
|
|
|
|
|
return output.filter((x) => x.step !== undefined && x.hook !== undefined && x.hook.length > 0);
|
2022-01-01 17:44:41 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export class Hook {
|
|
|
|
|
public commands;
|
2022-01-01 22:00:35 +00:00
|
|
|
public secrets: CloudRunnerSecret[] = new Array<CloudRunnerSecret>();
|
2022-01-01 17:44:41 +00:00
|
|
|
public name;
|
2022-01-01 18:20:36 +00:00
|
|
|
public hook!: string[];
|
|
|
|
|
public step!: string[];
|
2021-12-29 16:28:42 +00:00
|
|
|
}
|