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 17:44:41 +00:00
|
|
|
let hooks = CloudRunnerBuildCommandProcessor.getHooks();
|
|
|
|
|
|
|
|
|
|
if (Input.cloudRunnerTests) {
|
|
|
|
|
CloudRunnerLogger.log(JSON.stringify(hooks, undefined, 4));
|
|
|
|
|
} else {
|
|
|
|
|
hooks = [];
|
|
|
|
|
}
|
|
|
|
|
|
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 17:44:41 +00:00
|
|
|
${
|
|
|
|
|
hooks
|
|
|
|
|
.filter((x) => x.hook !== undefined && x.hook.length > 0 && x.hook.includes(`before`))
|
|
|
|
|
.map((x) => x.commands)
|
|
|
|
|
.join(`\n`) || ' '
|
|
|
|
|
}
|
2021-12-29 17:04:06 +00:00
|
|
|
${commands}
|
2022-01-01 17:44:41 +00:00
|
|
|
${
|
|
|
|
|
hooks
|
|
|
|
|
.filter((x) => x.hook !== undefined && x.hook.length > 0 && x.hook.includes(`before`))
|
|
|
|
|
.map((x) => x.commands)
|
|
|
|
|
.join(`\n`) || ' '
|
|
|
|
|
}
|
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;
|
|
|
|
|
let output = new Hook[0]();
|
|
|
|
|
if (experimentHooks && experimentHooks !== '') {
|
|
|
|
|
try {
|
|
|
|
|
output = YAML.parse(experimentHooks);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export class Hook {
|
|
|
|
|
public commands;
|
|
|
|
|
public secrets: CloudRunnerSecret[] = [];
|
|
|
|
|
public name;
|
|
|
|
|
public hook;
|
2021-12-29 16:28:42 +00:00
|
|
|
}
|