2022-02-01 02:31:20 +00:00
|
|
|
import CloudRunnerLogger from '../services/cloud-runner-logger';
|
2022-04-03 00:31:08 +00:00
|
|
|
import { CloudRunnerFolders } from '../services/cloud-runner-folders';
|
|
|
|
|
import { CloudRunnerStepState } from '../cloud-runner-step-state';
|
2022-02-01 02:31:20 +00:00
|
|
|
import { CustomWorkflow } from './custom-workflow';
|
|
|
|
|
import { WorkflowInterface } from './workflow-interface';
|
|
|
|
|
import * as core from '@actions/core';
|
2022-04-03 00:31:08 +00:00
|
|
|
import { CloudRunnerBuildCommandProcessor } from '../services/cloud-runner-build-command-process';
|
|
|
|
|
import path from 'path';
|
|
|
|
|
import CloudRunner from '../cloud-runner';
|
2022-02-01 02:31:20 +00:00
|
|
|
|
|
|
|
|
export class BuildAutomationWorkflow implements WorkflowInterface {
|
|
|
|
|
async run(cloudRunnerStepState: CloudRunnerStepState) {
|
|
|
|
|
try {
|
|
|
|
|
return 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`);
|
|
|
|
|
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.startGroup('pre build steps');
|
2022-02-01 02:31:20 +00:00
|
|
|
let output = '';
|
2022-04-03 00:31:08 +00:00
|
|
|
if (CloudRunner.buildParameters.preBuildSteps !== '') {
|
|
|
|
|
output += await CustomWorkflow.runCustomJob(CloudRunner.buildParameters.preBuildSteps);
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.endGroup();
|
2022-02-01 02:31:20 +00:00
|
|
|
CloudRunnerLogger.logWithTime('Configurable pre build step(s) time');
|
|
|
|
|
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.startGroup('build');
|
2022-04-02 23:12:35 +00:00
|
|
|
CloudRunnerLogger.log(baseImage.toString());
|
2022-04-03 00:31:08 +00:00
|
|
|
CloudRunnerLogger.logLine(` `);
|
|
|
|
|
CloudRunnerLogger.logLine('Starting build automation job');
|
|
|
|
|
|
|
|
|
|
output += await CloudRunner.CloudRunnerProviderPlatform.runTask(
|
|
|
|
|
CloudRunner.buildParameters.buildGuid,
|
|
|
|
|
baseImage.toString(),
|
|
|
|
|
BuildAutomationWorkflow.FullWorkflow,
|
|
|
|
|
`/${CloudRunnerFolders.buildVolumeFolder}`,
|
2022-04-03 19:32:04 +00:00
|
|
|
`/${CloudRunnerFolders.buildVolumeFolder}/`,
|
2022-04-04 19:21:37 +00:00
|
|
|
CloudRunner.cloudRunnerEnvironmentVariables,
|
2022-04-03 00:31:08 +00:00
|
|
|
CloudRunner.defaultSecrets,
|
2022-02-01 02:31:20 +00:00
|
|
|
);
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.endGroup();
|
2022-02-01 02:31:20 +00:00
|
|
|
CloudRunnerLogger.logWithTime('Build time');
|
|
|
|
|
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.startGroup('post build steps');
|
|
|
|
|
if (CloudRunner.buildParameters.postBuildSteps !== '') {
|
|
|
|
|
output += await CustomWorkflow.runCustomJob(CloudRunner.buildParameters.postBuildSteps);
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|
2022-04-03 00:31:08 +00:00
|
|
|
if (!CloudRunner.buildParameters.cliMode) core.endGroup();
|
2022-02-01 02:31:20 +00:00
|
|
|
CloudRunnerLogger.logWithTime('Configurable post build step(s) time');
|
|
|
|
|
|
|
|
|
|
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-03 00:31:08 +00:00
|
|
|
|
|
|
|
|
private static get FullWorkflow() {
|
2022-04-03 19:32:04 +00:00
|
|
|
const setupHooks = CloudRunnerBuildCommandProcessor.getHooks(CloudRunner.buildParameters.customJobHooks).filter(
|
|
|
|
|
(x) => x.step.includes(`setup`),
|
|
|
|
|
);
|
|
|
|
|
const buildHooks = CloudRunnerBuildCommandProcessor.getHooks(CloudRunner.buildParameters.customJobHooks).filter(
|
|
|
|
|
(x) => x.step.includes(`build`),
|
2022-04-03 00:31:08 +00:00
|
|
|
);
|
2022-04-04 22:27:19 +00:00
|
|
|
const builderPath = path.join(CloudRunnerFolders.builderPathFull, 'dist', `index.js`).replace(/\\/g, `/`);
|
2022-04-04 19:54:48 +00:00
|
|
|
return `apt-get update > /dev/null
|
|
|
|
|
apt-get install -y zip tree npm git-lfs jq unzip git > /dev/null
|
2022-04-04 19:59:13 +00:00
|
|
|
npm install -g n > /dev/null
|
|
|
|
|
n stable > /dev/null
|
2022-04-03 19:32:04 +00:00
|
|
|
${setupHooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
|
2022-04-03 20:39:20 +00:00
|
|
|
export GITHUB_WORKSPACE="${CloudRunnerFolders.repoPathFull.replace(/\\/g, `/`)}"
|
2022-04-04 22:27:19 +00:00
|
|
|
${BuildAutomationWorkflow.SetupCommands(builderPath)}
|
2022-04-03 19:32:04 +00:00
|
|
|
${setupHooks.filter((x) => x.hook.includes(`after`)).map((x) => x.commands) || ' '}
|
|
|
|
|
${buildHooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
|
2022-04-04 22:27:19 +00:00
|
|
|
${BuildAutomationWorkflow.BuildCommands(builderPath)}
|
2022-04-04 19:59:13 +00:00
|
|
|
${buildHooks.filter((x) => x.hook.includes(`after`)).map((x) => x.commands) || ' '}`;
|
2022-04-03 00:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-04 22:27:19 +00:00
|
|
|
private static SetupCommands(builderPath) {
|
2022-04-03 00:31:08 +00:00
|
|
|
return `export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
|
2022-04-04 23:24:37 +00:00
|
|
|
echo "game ci cloud runner clone"
|
2022-04-03 00:31:08 +00:00
|
|
|
mkdir -p ${CloudRunnerFolders.builderPathFull.replace(/\\/g, `/`)}
|
|
|
|
|
git clone -q -b ${CloudRunner.buildParameters.cloudRunnerBranch} ${
|
|
|
|
|
CloudRunnerFolders.unityBuilderRepoUrl
|
|
|
|
|
} "${CloudRunnerFolders.builderPathFull.replace(/\\/g, `/`)}"
|
2022-04-04 22:27:19 +00:00
|
|
|
chmod +x ${builderPath}
|
2022-04-04 23:24:37 +00:00
|
|
|
echo "game ci cloud runner bootstrap"
|
2022-04-04 22:27:19 +00:00
|
|
|
node ${builderPath} -m remote-cli`;
|
2022-04-03 00:31:08 +00:00
|
|
|
}
|
|
|
|
|
|
2022-04-04 22:27:19 +00:00
|
|
|
private static BuildCommands(builderPath) {
|
2022-04-04 23:24:37 +00:00
|
|
|
const linuxCacheFolder = CloudRunnerFolders.cacheFolderFull.replace(/\\/g, `/`);
|
|
|
|
|
const distFolder = path.join(CloudRunnerFolders.builderPathFull, 'dist');
|
|
|
|
|
const ubuntuPlatformsFolder = path.join(CloudRunnerFolders.builderPathFull, 'dist', 'platforms', 'ubuntu');
|
|
|
|
|
return `echo "game ci cloud runner init"
|
|
|
|
|
cp -r "${path.join(distFolder, 'default-build-script').replace(/\\/g, `/`)}" "/UnityBuilderAction"
|
|
|
|
|
cp -r "${path.join(ubuntuPlatformsFolder, 'entrypoint.sh').replace(/\\/g, `/`)}" "/entrypoint.sh"
|
|
|
|
|
cp -r "${path.join(ubuntuPlatformsFolder, 'steps').replace(/\\/g, `/`)}" "/steps"
|
2022-04-03 19:20:06 +00:00
|
|
|
chmod -R +x "/entrypoint.sh"
|
|
|
|
|
chmod -R +x "/steps"
|
2022-04-04 23:24:37 +00:00
|
|
|
echo "game ci cloud runner start"
|
2022-04-03 19:20:06 +00:00
|
|
|
/entrypoint.sh
|
2022-04-04 23:24:37 +00:00
|
|
|
echo "game ci cloud runner push library to cache"
|
2022-04-04 22:27:19 +00:00
|
|
|
chmod +x ${builderPath}
|
2022-04-06 23:33:26 +00:00
|
|
|
node ${builderPath} -m cache-push --cachePushFrom Library --cachePushTo ${linuxCacheFolder}/Library
|
2022-04-04 23:24:37 +00:00
|
|
|
echo "game ci cloud runner push build to cache"
|
2022-04-06 23:33:26 +00:00
|
|
|
node ${builderPath} -m cache-push --cachePushFrom build --cachePushTo ${linuxCacheFolder}/build`;
|
2022-04-03 00:31:08 +00:00
|
|
|
}
|
2022-02-01 02:31:20 +00:00
|
|
|
}
|