Cleanup and custom steps

pull/289/head
mdugdale 2021-08-22 00:26:03 +01:00
parent 582bf2a14f
commit 7034f51d93
8 changed files with 455 additions and 292 deletions

351
dist/index.js vendored
View File

@ -50,7 +50,7 @@ function run() {
switch (buildParameters.cloudRunnerCluster) {
case 'aws':
case 'k8s':
yield model_1.CloudRunner.build(buildParameters, baseImage);
yield model_1.CloudRunner.run(buildParameters, baseImage);
break;
// default and local case
default:
@ -238,6 +238,8 @@ class BuildParameters {
kubeVolumeSize: input_1.default.kubeVolumeSize,
kubeVolume: input_1.default.kubeVolume,
postBuildSteps: input_1.default.postBuildSteps,
preBuildSteps: input_1.default.preBuildSteps,
customBuildSteps: input_1.default.customBuildSteps,
};
});
}
@ -862,6 +864,54 @@ class CloudRunnerNamespace {
exports.default = CloudRunnerNamespace;
/***/ }),
/***/ 1669:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__webpack_require__(42186));
class CloudRunnerTimerLogger {
static setup() {
this.timestamp = this.createTimestamp();
this.globalTimestamp = this.timestamp;
}
static logWithTime(message) {
const newTimestamp = this.createTimestamp();
core.info(`${message} (Since previous: ${this.calculateTimeDiff(newTimestamp, this.timestamp)}, Total time: ${this.calculateTimeDiff(newTimestamp, this.globalTimestamp)})`);
this.timestamp = newTimestamp;
}
static calculateTimeDiff(x, y) {
return Math.floor((x - y) / 1000);
}
static createTimestamp() {
return Date.now();
}
}
exports.default = CloudRunnerTimerLogger;
/***/ }),
/***/ 79144:
@ -907,54 +957,19 @@ const cloud_runner_namespace_1 = __importDefault(__webpack_require__(93487));
const kubernetes_build_platform_1 = __importDefault(__webpack_require__(75944));
const image_environment_factory_1 = __importDefault(__webpack_require__(25145));
const yaml_1 = __importDefault(__webpack_require__(13552));
const cloud_runner_timer_logger_1 = __importDefault(__webpack_require__(1669));
const repositoryFolder = 'repo';
const buildVolumeFolder = 'data';
const cacheFolder = 'cache';
class CloudRunner {
static build(buildParameters, baseImage) {
return __awaiter(this, void 0, void 0, function* () {
const t = Date.now();
CloudRunner.buildGuid = cloud_runner_namespace_1.default.generateBuildName(CloudRunner.readRunNumber(), buildParameters.platform);
CloudRunner.buildParams = buildParameters;
CloudRunner.setupBranchName();
CloudRunner.setupFolderVariables();
CloudRunner.setupDefaultSecrets();
try {
CloudRunner.setupBuildPlatform();
yield this.CloudRunnerProviderPlatform.setupSharedBuildResources(this.buildGuid, this.buildParams, this.branchName, this.defaultSecrets);
yield CloudRunner.SetupStep();
const t2 = Date.now();
core.info(`Setup time: ${Math.floor((t2 - t) / 1000)}s`);
yield CloudRunner.BuildStep(baseImage);
const t3 = Date.now();
core.info(`Build time: ${Math.floor((t3 - t2) / 1000)}s`);
yield CloudRunner.CompressionStep();
core.info(`Post build steps ${this.buildParams.postBuildSteps}`);
this.buildParams.postBuildSteps = yaml_1.default.parse(this.buildParams.postBuildSteps);
core.info(`Post build steps ${JSON.stringify(this.buildParams.postBuildSteps, undefined, 4)}`);
for (const step of this.buildParams.postBuildSteps) {
const stepSecrets = step.secrets.map((x) => {
const secret = {
ParameterKey: x.name,
EnvironmentVariable: x.name,
ParameterValue: x.value,
};
return secret;
});
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, step['image'], step['commands'], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
], [...this.defaultSecrets, ...stepSecrets]);
}
yield this.CloudRunnerProviderPlatform.cleanupSharedBuildResources(this.buildGuid, this.buildParams, this.branchName, this.defaultSecrets);
}
catch (error) {
yield CloudRunner.handleException(error);
throw error;
}
});
static setup(buildParameters) {
cloud_runner_timer_logger_1.default.setup();
CloudRunner.buildGuid = cloud_runner_namespace_1.default.generateBuildName(CloudRunner.readRunNumber(), buildParameters.platform);
CloudRunner.buildParams = buildParameters;
CloudRunner.setupBranchName();
CloudRunner.setupFolderVariables();
CloudRunner.setupDefaultSecrets();
CloudRunner.setupBuildPlatform();
}
static setupFolderVariables() {
this.buildPathFull = `/${buildVolumeFolder}/${this.buildGuid}`;
@ -979,93 +994,24 @@ class CloudRunner {
static getCloneBuilder() {
return `git clone -q ${this.CloudRunnerBranch} ${this.unityBuilderRepoUrl} ${this.builderPathFull}`;
}
static SetupStep() {
static run(buildParameters, baseImage) {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 1/4 clone and restore cache)');
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, 'alpine/git', [
` printenv
apk update -q
apk add unzip zip git-lfs jq tree -q
mkdir -p ${this.buildPathFull}
mkdir -p ${this.builderPathFull}
mkdir -p ${this.repoPathFull}
${this.getCloneBuilder()}
echo ' '
echo 'Initializing source repository for cloning with caching of LFS files'
${this.getCloneNoLFSCommand()}
echo 'Source repository initialized'
echo ' '
${process.env.DEBUG ? '' : '#'}echo $LFS_ASSETS_HASH
${process.env.DEBUG ? '' : '#'}echo 'Large File before LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
echo 'Starting checks of cache for the Unity project Library and git LFS files'
${this.getHandleCachingCommand()}
${process.env.DEBUG ? '' : '#'}echo 'Caching complete'
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}echo 'Large File after LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
${process.env.DEBUG ? '' : '#'}echo ' '
`,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, CloudRunner.defaultGitShaEnvironmentVariable, this.defaultSecrets);
CloudRunner.setup(buildParameters);
try {
yield CloudRunner.setupSharedBuildResources();
yield CloudRunner.setupStep();
yield CloudRunner.runMainJob(baseImage);
yield CloudRunner.cleanupSharedBuildResources();
}
catch (error) {
yield CloudRunner.handleException(error);
throw error;
}
});
}
static BuildStep(baseImage) {
static setupSharedBuildResources() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting part 2/4 (build unity project)');
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, baseImage.toString(), [
`
printenv
export GITHUB_WORKSPACE="${this.repoPathFull}"
cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
cp -r "${this.builderPathFull}/dist/steps/" "/steps"
chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps"
/entrypoint.sh
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
`,
], `/${buildVolumeFolder}`, `/${this.projectPathFull}`, CloudRunner.readBuildEnvironmentVariables(), this.defaultSecrets);
});
}
static CompressionStep() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 3/4 build compression');
// Cleanup
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, 'alpine', [
`
printenv
apk update -q
apk add zip tree -q
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
cd "$libraryFolderFull/.."
zip -r "lib-$BUILDID.zip" "./Library"
mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib"
cd "$repoPathFull"
ls -lh "$repoPathFull"
zip -r "build-$BUILDID.zip" "./${CloudRunner.buildParams.buildPath}"
mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull/.."
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'cacheFolderFull',
value: this.cacheFolderFull,
},
], this.defaultSecrets);
core.info('compression step complete');
yield this.CloudRunnerProviderPlatform.setupSharedBuildResources(this.buildGuid, this.buildParams, this.branchName, this.defaultSecrets);
});
}
static setupBuildPlatform() {
@ -1216,6 +1162,146 @@ class CloudRunner {
},
];
}
static runMainJob(baseImage) {
return __awaiter(this, void 0, void 0, function* () {
if (!this.buildParams.customBuildSteps) {
core.info(`Cloud Runner is running in standard build automation mode`);
yield CloudRunner.standardBuildAutomation(baseImage);
}
else {
core.info(`Cloud Runner is running in custom job mode`);
yield CloudRunner.runCustomJob(this.buildParams.customBuildSteps);
}
});
}
static standardBuildAutomation(baseImage) {
return __awaiter(this, void 0, void 0, function* () {
cloud_runner_timer_logger_1.default.logWithTime('Pre build steps time');
yield this.runCustomJob(this.buildParams.preBuildSteps);
cloud_runner_timer_logger_1.default.logWithTime('Setup time');
yield CloudRunner.BuildStep(baseImage);
cloud_runner_timer_logger_1.default.logWithTime('Build time');
yield CloudRunner.CompressionStep();
cloud_runner_timer_logger_1.default.logWithTime('Compression time');
yield this.runCustomJob(this.buildParams.postBuildSteps);
cloud_runner_timer_logger_1.default.logWithTime('Post build steps time');
});
}
static runCustomJob(buildSteps) {
return __awaiter(this, void 0, void 0, function* () {
buildSteps = yaml_1.default.parse(buildSteps);
for (const step of buildSteps) {
const stepSecrets = step.secrets.map((x) => {
const secret = {
ParameterKey: x.name,
EnvironmentVariable: x.name,
ParameterValue: x.value,
};
return secret;
});
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, step['image'], step['commands'], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
], [...this.defaultSecrets, ...stepSecrets]);
}
});
}
static setupStep() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 1/4 clone and restore cache)');
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, 'alpine/git', [
` printenv
apk update -q
apk add unzip zip git-lfs jq tree -q
mkdir -p ${this.buildPathFull}
mkdir -p ${this.builderPathFull}
mkdir -p ${this.repoPathFull}
${this.getCloneBuilder()}
echo ' '
echo 'Initializing source repository for cloning with caching of LFS files'
${this.getCloneNoLFSCommand()}
echo 'Source repository initialized'
echo ' '
${process.env.DEBUG ? '' : '#'}echo $LFS_ASSETS_HASH
${process.env.DEBUG ? '' : '#'}echo 'Large File before LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
echo 'Starting checks of cache for the Unity project Library and git LFS files'
${this.getHandleCachingCommand()}
${process.env.DEBUG ? '' : '#'}echo 'Caching complete'
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}echo 'Large File after LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
${process.env.DEBUG ? '' : '#'}echo ' '
`,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, CloudRunner.defaultGitShaEnvironmentVariable, this.defaultSecrets);
});
}
static BuildStep(baseImage) {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting part 2/4 (build unity project)');
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, baseImage.toString(), [
`
printenv
export GITHUB_WORKSPACE="${this.repoPathFull}"
cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
cp -r "${this.builderPathFull}/dist/steps/" "/steps"
chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps"
/entrypoint.sh
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
`,
], `/${buildVolumeFolder}`, `/${this.projectPathFull}`, CloudRunner.readBuildEnvironmentVariables(), this.defaultSecrets);
});
}
static CompressionStep() {
return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 3/4 build compression');
// Cleanup
yield this.CloudRunnerProviderPlatform.runBuildTask(this.buildGuid, 'alpine', [
`
printenv
apk update -q
apk add zip tree -q
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
cd "$libraryFolderFull/.."
zip -r "lib-$BUILDID.zip" "./Library"
mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib"
cd "$repoPathFull"
ls -lh "$repoPathFull"
zip -r "build-$BUILDID.zip" "./${CloudRunner.buildParams.buildPath}"
mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull/.."
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'cacheFolderFull',
value: this.cacheFolderFull,
},
], this.defaultSecrets);
core.info('compression step complete');
});
}
static cleanupSharedBuildResources() {
return __awaiter(this, void 0, void 0, function* () {
yield this.CloudRunnerProviderPlatform.cleanupSharedBuildResources(this.buildGuid, this.buildParams, this.branchName, this.defaultSecrets);
});
}
static handleException(error) {
return __awaiter(this, void 0, void 0, function* () {
core.error(JSON.stringify(error, undefined, 4));
@ -1224,7 +1310,6 @@ class CloudRunner {
});
}
}
CloudRunner.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
CloudRunner.defaultGitShaEnvironmentVariable = [
{
name: 'GITHUB_SHA',
@ -1934,7 +2019,7 @@ class KubernetesStorage {
};
pvc.spec = {
accessModes: ['ReadWriteMany'],
storageClassName: 'fileserver',
storageClassName: process.env.K8s_STORAGE_CLASS || 'fileserver',
resources: {
requests: {
storage: buildParameters.kubeVolumeSize,
@ -2492,6 +2577,12 @@ class Input {
static get postBuildSteps() {
return core.getInput('postBuildSteps');
}
static get preBuildSteps() {
return core.getInput('postBuildSteps');
}
static get customBuildSteps() {
return core.getInput('postBuildSteps');
}
static get cloudRunnerCluster() {
return core.getInput('cloudRunnerCluster') || '';
}

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -15,7 +15,7 @@ async function run() {
switch (buildParameters.cloudRunnerCluster) {
case 'aws':
case 'k8s':
await CloudRunner.build(buildParameters, baseImage);
await CloudRunner.run(buildParameters, baseImage);
break;
// default and local case

View File

@ -34,6 +34,8 @@ class BuildParameters {
public chownFilesTo!: string;
public postBuildSteps;
public preBuildSteps;
public customBuildSteps;
static async create(): Promise<BuildParameters> {
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidAppBundle);
@ -47,7 +49,6 @@ class BuildParameters {
return {
version: unityVersion,
customImage: Input.customImage,
runnerTempPath: process.env.RUNNER_TEMP,
platform: Input.targetPlatform,
projectPath: Input.projectPath,
@ -74,6 +75,8 @@ class BuildParameters {
kubeVolumeSize: Input.kubeVolumeSize,
kubeVolume: Input.kubeVolume,
postBuildSteps: Input.postBuildSteps,
preBuildSteps: Input.preBuildSteps,
customBuildSteps: Input.customBuildSteps,
};
}

View File

@ -0,0 +1,31 @@
import * as core from '@actions/core';
class CloudRunnerTimerLogger {
private static timestamp: number;
private static globalTimestamp: number;
public static setup() {
this.timestamp = this.createTimestamp();
this.globalTimestamp = this.timestamp;
}
public static logWithTime(message: string) {
const newTimestamp = this.createTimestamp();
core.info(
`${message} (Since previous: ${this.calculateTimeDiff(
newTimestamp,
this.timestamp,
)}, Total time: ${this.calculateTimeDiff(newTimestamp, this.globalTimestamp)})`,
);
this.timestamp = newTimestamp;
}
private static calculateTimeDiff(x: number, y: number) {
return Math.floor((x - y) / 1000);
}
private static createTimestamp() {
return Date.now();
}
}
export default CloudRunnerTimerLogger;

View File

@ -8,6 +8,7 @@ import Kubernetes from './kubernetes-build-platform';
import CloudRunnerEnvironmentVariable from './cloud-runner-environment-variable';
import ImageEnvironmentFactory from '../image-environment-factory';
import YAML from 'yaml';
import CloudRunnerTimerLogger from './cloud-runner-timer-logger';
const repositoryFolder = 'repo';
const buildVolumeFolder = 'data';
const cacheFolder = 'cache';
@ -30,7 +31,6 @@ class CloudRunner {
private static CloudRunnerBranch: string;
private static unityBuilderRepoUrl: string;
private static targetBuildRepoUrl: string;
private static SteamDeploy: boolean = process.env.STEAM_DEPLOY !== undefined || false;
private static readonly defaultGitShaEnvironmentVariable = [
{
name: 'GITHUB_SHA',
@ -38,8 +38,8 @@ class CloudRunner {
},
];
static async build(buildParameters: BuildParameters, baseImage) {
const t = Date.now();
private static setup(buildParameters: BuildParameters) {
CloudRunnerTimerLogger.setup();
CloudRunner.buildGuid = CloudRunnerNamespace.generateBuildName(
CloudRunner.readRunNumber(),
buildParameters.platform,
@ -48,58 +48,7 @@ class CloudRunner {
CloudRunner.setupBranchName();
CloudRunner.setupFolderVariables();
CloudRunner.setupDefaultSecrets();
try {
CloudRunner.setupBuildPlatform();
await this.CloudRunnerProviderPlatform.setupSharedBuildResources(
this.buildGuid,
this.buildParams,
this.branchName,
this.defaultSecrets,
);
await CloudRunner.SetupStep();
const t2 = Date.now();
core.info(`Setup time: ${Math.floor((t2 - t) / 1000)}s`);
await CloudRunner.BuildStep(baseImage);
const t3 = Date.now();
core.info(`Build time: ${Math.floor((t3 - t2) / 1000)}s`);
await CloudRunner.CompressionStep();
core.info(`Post build steps ${this.buildParams.postBuildSteps}`);
this.buildParams.postBuildSteps = YAML.parse(this.buildParams.postBuildSteps);
core.info(`Post build steps ${JSON.stringify(this.buildParams.postBuildSteps, undefined, 4)}`);
for (const step of this.buildParams.postBuildSteps) {
const stepSecrets: CloudRunnerSecret[] = step.secrets.map((x) => {
const secret: CloudRunnerSecret = {
ParameterKey: x.name,
EnvironmentVariable: x.name,
ParameterValue: x.value,
};
return secret;
});
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
step['image'],
step['commands'],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}`,
[
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
],
[...this.defaultSecrets, ...stepSecrets],
);
}
await this.CloudRunnerProviderPlatform.cleanupSharedBuildResources(
this.buildGuid,
this.buildParams,
this.branchName,
this.defaultSecrets,
);
} catch (error) {
await CloudRunner.handleException(error);
throw error;
}
CloudRunner.setupBuildPlatform();
}
private static setupFolderVariables() {
@ -129,116 +78,28 @@ class CloudRunner {
return `git clone -q ${this.CloudRunnerBranch} ${this.unityBuilderRepoUrl} ${this.builderPathFull}`;
}
private static async SetupStep() {
core.info('Starting step 1/4 clone and restore cache)');
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
'alpine/git',
[
` printenv
apk update -q
apk add unzip zip git-lfs jq tree -q
mkdir -p ${this.buildPathFull}
mkdir -p ${this.builderPathFull}
mkdir -p ${this.repoPathFull}
${this.getCloneBuilder()}
echo ' '
echo 'Initializing source repository for cloning with caching of LFS files'
${this.getCloneNoLFSCommand()}
echo 'Source repository initialized'
echo ' '
${process.env.DEBUG ? '' : '#'}echo $LFS_ASSETS_HASH
${process.env.DEBUG ? '' : '#'}echo 'Large File before LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
echo 'Starting checks of cache for the Unity project Library and git LFS files'
${this.getHandleCachingCommand()}
${process.env.DEBUG ? '' : '#'}echo 'Caching complete'
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}echo 'Large File after LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
${process.env.DEBUG ? '' : '#'}echo ' '
`,
],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}/`,
CloudRunner.defaultGitShaEnvironmentVariable,
this.defaultSecrets,
);
static async run(buildParameters: BuildParameters, baseImage) {
CloudRunner.setup(buildParameters);
try {
await CloudRunner.setupSharedBuildResources();
await CloudRunner.setupStep();
await CloudRunner.runMainJob(baseImage);
await CloudRunner.cleanupSharedBuildResources();
} catch (error) {
await CloudRunner.handleException(error);
throw error;
}
}
private static async BuildStep(baseImage: any) {
core.info('Starting part 2/4 (build unity project)');
await this.CloudRunnerProviderPlatform.runBuildTask(
private static async setupSharedBuildResources() {
await this.CloudRunnerProviderPlatform.setupSharedBuildResources(
this.buildGuid,
baseImage.toString(),
[
`
printenv
export GITHUB_WORKSPACE="${this.repoPathFull}"
cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
cp -r "${this.builderPathFull}/dist/steps/" "/steps"
chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps"
/entrypoint.sh
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
`,
],
`/${buildVolumeFolder}`,
`/${this.projectPathFull}`,
CloudRunner.readBuildEnvironmentVariables(),
this.buildParams,
this.branchName,
this.defaultSecrets,
);
}
private static async CompressionStep() {
core.info('Starting step 3/4 build compression');
// Cleanup
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
'alpine',
[
`
printenv
apk update -q
apk add zip tree -q
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
cd "$libraryFolderFull/.."
zip -r "lib-$BUILDID.zip" "./Library"
mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib"
cd "$repoPathFull"
ls -lh "$repoPathFull"
zip -r "build-$BUILDID.zip" "./${CloudRunner.buildParams.buildPath}"
mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull/.."
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`,
],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}`,
[
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'cacheFolderFull',
value: this.cacheFolderFull,
},
],
this.defaultSecrets,
);
core.info('compression step complete');
}
private static setupBuildPlatform() {
switch (this.buildParams.cloudRunnerCluster) {
case 'aws':
@ -397,6 +258,175 @@ class CloudRunner {
];
}
private static async runMainJob(baseImage: any) {
if (!this.buildParams.customBuildSteps) {
core.info(`Cloud Runner is running in standard build automation mode`);
await CloudRunner.standardBuildAutomation(baseImage);
} else {
core.info(`Cloud Runner is running in custom job mode`);
await CloudRunner.runCustomJob(this.buildParams.customBuildSteps);
}
}
private static async standardBuildAutomation(baseImage: any) {
CloudRunnerTimerLogger.logWithTime('Pre build steps time');
await this.runCustomJob(this.buildParams.preBuildSteps);
CloudRunnerTimerLogger.logWithTime('Setup time');
await CloudRunner.BuildStep(baseImage);
CloudRunnerTimerLogger.logWithTime('Build time');
await CloudRunner.CompressionStep();
CloudRunnerTimerLogger.logWithTime('Compression time');
await this.runCustomJob(this.buildParams.postBuildSteps);
CloudRunnerTimerLogger.logWithTime('Post build steps time');
}
private static async runCustomJob(buildSteps) {
buildSteps = YAML.parse(buildSteps);
for (const step of buildSteps) {
const stepSecrets: CloudRunnerSecret[] = step.secrets.map((x) => {
const secret: CloudRunnerSecret = {
ParameterKey: x.name,
EnvironmentVariable: x.name,
ParameterValue: x.value,
};
return secret;
});
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
step['image'],
step['commands'],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}`,
[
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
],
[...this.defaultSecrets, ...stepSecrets],
);
}
}
private static async setupStep() {
core.info('Starting step 1/4 clone and restore cache)');
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
'alpine/git',
[
` printenv
apk update -q
apk add unzip zip git-lfs jq tree -q
mkdir -p ${this.buildPathFull}
mkdir -p ${this.builderPathFull}
mkdir -p ${this.repoPathFull}
${this.getCloneBuilder()}
echo ' '
echo 'Initializing source repository for cloning with caching of LFS files'
${this.getCloneNoLFSCommand()}
echo 'Source repository initialized'
echo ' '
${process.env.DEBUG ? '' : '#'}echo $LFS_ASSETS_HASH
${process.env.DEBUG ? '' : '#'}echo 'Large File before LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
echo 'Starting checks of cache for the Unity project Library and git LFS files'
${this.getHandleCachingCommand()}
${process.env.DEBUG ? '' : '#'}echo 'Caching complete'
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}echo 'Large File after LFS caching and pull'
${process.env.DEBUG ? '' : '#'}ls -alh "${this.lfsDirectory}"
${process.env.DEBUG ? '' : '#'}echo ' '
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
${process.env.DEBUG ? '' : '#'}echo ' '
`,
],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}/`,
CloudRunner.defaultGitShaEnvironmentVariable,
this.defaultSecrets,
);
}
private static async BuildStep(baseImage: any) {
core.info('Starting part 2/4 (build unity project)');
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
baseImage.toString(),
[
`
printenv
export GITHUB_WORKSPACE="${this.repoPathFull}"
cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
cp -r "${this.builderPathFull}/dist/steps/" "/steps"
chmod -R +x "/entrypoint.sh"
chmod -R +x "/steps"
/entrypoint.sh
${process.env.DEBUG ? '' : '#'}tree -L 4 "${this.buildPathFull}"
${process.env.DEBUG ? '' : '#'}ls -lh "/${buildVolumeFolder}"
`,
],
`/${buildVolumeFolder}`,
`/${this.projectPathFull}`,
CloudRunner.readBuildEnvironmentVariables(),
this.defaultSecrets,
);
}
private static async CompressionStep() {
core.info('Starting step 3/4 build compression');
// Cleanup
await this.CloudRunnerProviderPlatform.runBuildTask(
this.buildGuid,
'alpine',
[
`
printenv
apk update -q
apk add zip tree -q
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
cd "$libraryFolderFull/.."
zip -r "lib-$BUILDID.zip" "./Library"
mv "lib-$BUILDID.zip" "/$cacheFolderFull/lib"
cd "$repoPathFull"
ls -lh "$repoPathFull"
zip -r "build-$BUILDID.zip" "./${CloudRunner.buildParams.buildPath}"
mv "build-$BUILDID.zip" "/$cacheFolderFull/build-$BUILDID.zip"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull"
${process.env.DEBUG ? '' : '#'}tree -L 4 "/$cacheFolderFull/.."
${process.env.DEBUG ? '' : '#'}tree -L 4 "$repoPathFull"
${process.env.DEBUG ? '' : '#'}ls -lh "$repoPathFull"
`,
],
`/${buildVolumeFolder}`,
`/${buildVolumeFolder}`,
[
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'cacheFolderFull',
value: this.cacheFolderFull,
},
],
this.defaultSecrets,
);
core.info('compression step complete');
}
private static async cleanupSharedBuildResources() {
await this.CloudRunnerProviderPlatform.cleanupSharedBuildResources(
this.buildGuid,
this.buildParams,
this.branchName,
this.defaultSecrets,
);
}
private static async handleException(error: unknown) {
core.error(JSON.stringify(error, undefined, 4));
core.setFailed('Remote Builder failed');

View File

@ -57,7 +57,7 @@ class KubernetesStorage {
};
pvc.spec = {
accessModes: ['ReadWriteMany'],
storageClassName: 'fileserver',
storageClassName: process.env.K8s_STORAGE_CLASS || 'fileserver',
resources: {
requests: {
storage: buildParameters.kubeVolumeSize,

View File

@ -97,6 +97,14 @@ class Input {
return core.getInput('postBuildSteps');
}
static get preBuildSteps() {
return core.getInput('postBuildSteps');
}
static get customBuildSteps() {
return core.getInput('postBuildSteps');
}
static get cloudRunnerCluster() {
return core.getInput('cloudRunnerCluster') || '';
}