pull/289/head
Frostebite 2021-08-02 00:09:57 +01:00
parent 681513aec3
commit 8875b32f01
3 changed files with 145 additions and 164 deletions

133
dist/index.js vendored
View File

@ -2099,15 +2099,16 @@ class RemoteBuilder {
if (!runNumber || runNumber === '') { if (!runNumber || runNumber === '') {
throw new Error('no run number found, exiting'); throw new Error('no run number found, exiting');
} }
const buildUid = remote_builder_namespace_1.default.generateBuildName(runNumber, buildParameters.platform); RemoteBuilder.buildParams = buildParameters;
RemoteBuilder.buildId = remote_builder_namespace_1.default.generateBuildName(runNumber, buildParameters.platform);
const defaultBranchName = ((_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').filter((x) => { const defaultBranchName = ((_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').filter((x) => {
x = x[0].toUpperCase() + x.slice(1); x = x[0].toUpperCase() + x.slice(1);
return x; return x;
}).join('')) || ''; }).join('')) || '';
const branchName = process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName; const branchName = process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false; this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
const token = buildParameters.githubToken; const token = this.buildParams.githubToken;
const defaultSecretsArray = [ this.defaultSecrets = [
{ {
ParameterKey: 'GithubToken', ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN', EnvironmentVariable: 'GITHUB_TOKEN',
@ -2115,53 +2116,53 @@ class RemoteBuilder {
}, },
]; ];
try { try {
switch (buildParameters.remoteBuildCluster) { switch (this.buildParams.remoteBuildCluster) {
case 'aws': case 'aws':
core.info('Building with AWS'); core.info('Building with AWS');
this.RemoteBuilderProviderPlatform = new aws_build_platform_1.default(buildParameters); this.RemoteBuilderProviderPlatform = new aws_build_platform_1.default(this.buildParams);
break; break;
default: default:
case 'k8s': case 'k8s':
core.info('Building with Kubernetes'); core.info('Building with Kubernetes');
this.RemoteBuilderProviderPlatform = new kubernetes_build_platform_1.default(buildParameters); this.RemoteBuilderProviderPlatform = new kubernetes_build_platform_1.default(this.buildParams);
break; break;
} }
yield this.RemoteBuilderProviderPlatform.setupSharedBuildResources(buildUid, buildParameters, branchName, defaultSecretsArray); yield this.RemoteBuilderProviderPlatform.setupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets);
this.buildPathFull = `/${buildVolumeFolder}/${buildUid}`; this.buildPathFull = `/${buildVolumeFolder}/${this.buildId}`;
this.builderPathFull = `${this.buildPathFull}/builder`; this.builderPathFull = `${this.buildPathFull}/builder`;
this.steamPathFull = `${this.buildPathFull}/steam`; this.steamPathFull = `${this.buildPathFull}/steam`;
this.repoPathFull = `${this.buildPathFull}/${repositoryFolder}`; this.repoPathFull = `${this.buildPathFull}/${repositoryFolder}`;
this.projectPathFull = `${this.repoPathFull}/${buildParameters.projectPath}`; this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`;
this.libraryFolderFull = `${this.projectPathFull}/Library`; this.libraryFolderFull = `${this.projectPathFull}/Library`;
yield RemoteBuilder.SetupStep(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); yield RemoteBuilder.SetupStep(branchName);
yield RemoteBuilder.BuildStep(`${buildUid}`, buildParameters, baseImage, defaultSecretsArray); yield RemoteBuilder.BuildStep(baseImage);
yield RemoteBuilder.CompressionStep(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); yield RemoteBuilder.CompressionStep();
yield RemoteBuilder.UploadArtifacts(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); yield RemoteBuilder.UploadArtifacts(branchName);
if (this.SteamDeploy) { if (this.SteamDeploy) {
yield RemoteBuilder.DeployToSteam(buildUid, buildParameters, defaultSecretsArray); yield RemoteBuilder.DeployToSteam();
} }
yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(buildUid, buildParameters, branchName, defaultSecretsArray); yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets);
} }
catch (error) { catch (error) {
core.error(JSON.stringify(error, undefined, 4)); core.error(JSON.stringify(error, undefined, 4));
core.setFailed('Remote Builder failed'); core.setFailed('Remote Builder failed');
yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(buildUid, buildParameters, branchName, defaultSecretsArray); yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets);
throw error; throw error;
} }
}); });
} }
static SetupStep(buildUid, buildParameters, branchName, defaultSecretsArray) { static SetupStep(branchName) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 1/4 clone and restore cache)'); core.info('Starting step 1/4 clone and restore cache)');
const lfsDirectory = `${this.repoPathFull}/.git/lfs`; const lfsDirectory = `${this.repoPathFull}/.git/lfs`;
const testLFSFile = `${this.projectPathFull}/Assets/LFS_Test_File.jpg`; const testLFSFile = `${this.projectPathFull}/Assets/LFS_Test_File.jpg`;
const repo = `https://${buildParameters.githubToken}@github.com/game-ci/unity-builder.git`; const repo = `https://${this.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
const repo2 = `https://${buildParameters.githubToken}@github.com/game-ci/steam-deploy.git`; const repo2 = `https://${this.buildParams.githubToken}@github.com/game-ci/steam-deploy.git`;
const repo3 = `https://${buildParameters.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`; const repo3 = `https://${this.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const purgeRemoteCache = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined; const purgeRemoteCache = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
const initializeSourceRepoForCaching = `${this.builderPathFull}/dist/remote-builder/cloneNoLFS.sh "${this.repoPathFull}" "${repo3}" "$GITHUB_SHA" "${testLFSFile}"`; const initializeSourceRepoForCaching = `${this.builderPathFull}/dist/remote-builder/cloneNoLFS.sh "${this.repoPathFull}" "${repo3}" "$GITHUB_SHA" "${testLFSFile}"`;
const handleCaching = `${this.builderPathFull}/dist/remote-builder/handleCaching.sh "${cacheFolderFull}" "${branchName}" "${this.libraryFolderFull}" "${lfsDirectory}" "${purgeRemoteCache}"`; const handleCaching = `${this.builderPathFull}/dist/remote-builder/handleCaching.sh "${cacheFolderFull}" "${branchName}" "${this.libraryFolderFull}" "${lfsDirectory}" "${purgeRemoteCache}"`;
yield this.RemoteBuilderProviderPlatform.runBuildTask(buildUid, 'alpine/git', [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, 'alpine/git', [
` apk update -q ` apk update -q
apk add unzip zip git-lfs jq tree -q apk add unzip zip git-lfs jq tree -q
# #
@ -2207,13 +2208,13 @@ class RemoteBuilder {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], defaultSecretsArray); ], this.defaultSecrets);
}); });
} }
static BuildStep(buildUid, buildParameters, baseImage, defaultSecretsArray) { static BuildStep(baseImage) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const buildSecrets = new Array(); const buildSecrets = new Array();
buildSecrets.push(...defaultSecretsArray); buildSecrets.push(...this.defaultSecrets);
if (process.env.UNITY_LICENSE) if (process.env.UNITY_LICENSE)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'UnityLicense', ParameterKey: 'UnityLicense',
@ -2238,26 +2239,26 @@ class RemoteBuilder {
EnvironmentVariable: 'UNITY_SERIAL', EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL, ParameterValue: process.env.UNITY_SERIAL,
}); });
if (buildParameters.androidKeystoreBase64) if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64', ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64', EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: buildParameters.androidKeystoreBase64, ParameterValue: this.buildParams.androidKeystoreBase64,
}); });
if (buildParameters.androidKeystorePass) if (this.buildParams.androidKeystorePass)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeystorePass', ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS', EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: buildParameters.androidKeystorePass, ParameterValue: this.buildParams.androidKeystorePass,
}); });
if (buildParameters.androidKeyaliasPass) if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass', ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS', EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: buildParameters.androidKeyaliasPass, ParameterValue: this.buildParams.androidKeyaliasPass,
}); });
core.info('Starting part 2/4 (build unity project)'); core.info('Starting part 2/4 (build unity project)');
yield this.RemoteBuilderProviderPlatform.runBuildTask(buildUid, baseImage.toString(), [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, baseImage.toString(), [
` `
cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction" cp -r "${this.builderPathFull}/dist/default-build-script/" "/UnityBuilderAction"
cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh" cp -r "${this.builderPathFull}/dist/entrypoint.sh" "/entrypoint.sh"
@ -2269,93 +2270,93 @@ class RemoteBuilder {
], `/${buildVolumeFolder}`, `/${this.repoPathFull}`, [ ], `/${buildVolumeFolder}`, `/${this.repoPathFull}`, [
{ {
name: 'ContainerMemory', name: 'ContainerMemory',
value: buildParameters.remoteBuildMemory, value: this.buildParams.remoteBuildMemory,
}, },
{ {
name: 'ContainerCpu', name: 'ContainerCpu',
value: buildParameters.remoteBuildCpu, value: this.buildParams.remoteBuildCpu,
}, },
{ {
name: 'GITHUB_WORKSPACE', name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${buildUid}/${repositoryFolder}/`, value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
}, },
{ {
name: 'PROJECT_PATH', name: 'PROJECT_PATH',
value: buildParameters.projectPath, value: this.buildParams.projectPath,
}, },
{ {
name: 'BUILD_PATH', name: 'BUILD_PATH',
value: buildParameters.buildPath, value: this.buildParams.buildPath,
}, },
{ {
name: 'BUILD_FILE', name: 'BUILD_FILE',
value: buildParameters.buildFile, value: this.buildParams.buildFile,
}, },
{ {
name: 'BUILD_NAME', name: 'BUILD_NAME',
value: buildParameters.buildName, value: this.buildParams.buildName,
}, },
{ {
name: 'BUILD_METHOD', name: 'BUILD_METHOD',
value: buildParameters.buildMethod, value: this.buildParams.buildMethod,
}, },
{ {
name: 'CUSTOM_PARAMETERS', name: 'CUSTOM_PARAMETERS',
value: buildParameters.customParameters, value: this.buildParams.customParameters,
}, },
{ {
name: 'BUILD_TARGET', name: 'BUILD_TARGET',
value: buildParameters.platform, value: this.buildParams.platform,
}, },
{ {
name: 'ANDROID_VERSION_CODE', name: 'ANDROID_VERSION_CODE',
value: buildParameters.androidVersionCode.toString(), value: this.buildParams.androidVersionCode.toString(),
}, },
{ {
name: 'ANDROID_KEYSTORE_NAME', name: 'ANDROID_KEYSTORE_NAME',
value: buildParameters.androidKeystoreName, value: this.buildParams.androidKeystoreName,
}, },
{ {
name: 'ANDROID_KEYALIAS_NAME', name: 'ANDROID_KEYALIAS_NAME',
value: buildParameters.androidKeyaliasName, value: this.buildParams.androidKeyaliasName,
}, },
], buildSecrets); ], buildSecrets);
}); });
} }
static CompressionStep(buildUid, buildParameters, branchName, defaultSecretsArray) { static CompressionStep() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 3/4 build compression'); core.info('Starting step 3/4 build compression');
// Cleanup // Cleanup
yield this.RemoteBuilderProviderPlatform.runBuildTask(buildUid, 'alpine', [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, 'alpine', [
` `
apk update -q apk update -q
apk add zip -q apk add zip -q
cd "${this.libraryFolderFull}" cd "${this.libraryFolderFull}"
zip -r "lib-${buildUid}.zip" "${this.libraryFolderFull}" zip -r "lib-${this.buildId}.zip" "${this.libraryFolderFull}"
mv "lib-${buildUid}.zip" "${cacheFolderFull}/lib/lib-${buildUid}.zip" mv "lib-${this.buildId}.zip" "${cacheFolderFull}/lib/lib-${this.buildId}.zip"
cd "${this.projectPathFull}" cd "${this.projectPathFull}"
ls -lh "${buildParameters.buildPath}" ls -lh "${RemoteBuilder.buildParams.buildPath}"
zip -r "build-${buildUid}.zip" "${buildParameters.buildPath}" zip -r "build-${this.buildId}.zip" "${RemoteBuilder.buildParams.buildPath}"
mv "build-${buildUid}.zip" "/${buildVolumeFolder}/${buildUid}/build-${buildUid}.zip" mv "build-${this.buildId}.zip" "/${buildVolumeFolder}/${this.buildId}/build-${this.buildId}.zip"
`, `,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [ ], `/${buildVolumeFolder}`, `/${buildVolumeFolder}`, [
{ {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], defaultSecretsArray); ], this.defaultSecrets);
core.info('compression step complete'); core.info('compression step complete');
}); });
} }
static UploadArtifacts(buildUid, buildParameters, branchName, defaultSecretsArray) { static UploadArtifacts(branchName) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('Starting step 4/4 upload build to s3'); core.info('Starting step 4/4 upload build to s3');
yield this.RemoteBuilderProviderPlatform.runBuildTask(buildUid, 'amazon/aws-cli', [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, 'amazon/aws-cli', [
` `
aws s3 cp ${buildUid}/build-${buildUid}.zip s3://game-ci-storage/ aws s3 cp ${this.buildId}/build-${this.buildId}.zip s3://game-ci-storage/
# no need to upload Library cache for now # no need to upload Library cache for now
# aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/ # aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${this.buildId}.zip s3://game-ci-storage/
${this.SteamDeploy ? '#' : ''} rm -r ${buildUid} ${this.SteamDeploy ? '#' : ''} rm -r ${this.buildId}
`, `,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, [ ], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, [
{ {
@ -2377,25 +2378,25 @@ class RemoteBuilder {
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY', EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '', ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
}, },
...defaultSecretsArray, ...this.defaultSecrets,
]); ]);
}); });
} }
static DeployToSteam(buildUid, buildParameters, defaultSecretsArray) { static DeployToSteam() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
core.info('Starting steam deployment'); core.info('Starting steam deployment');
yield this.RemoteBuilderProviderPlatform.runBuildTask(buildUid, 'cm2network/steamcmd:root', [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, 'cm2network/steamcmd:root', [
` `
ls ls
ls / ls /
cp -r /${buildVolumeFolder}/${buildUid}/steam/action/entrypoint.sh /entrypoint.sh; cp -r /${buildVolumeFolder}/${this.buildId}/steam/action/entrypoint.sh /entrypoint.sh;
cp -r /${buildVolumeFolder}/${buildUid}/steam/action/steps/ /steps; cp -r /${buildVolumeFolder}/${this.buildId}/steam/action/steps/ /steps;
chmod -R +x /entrypoint.sh; chmod -R +x /entrypoint.sh;
chmod -R +x /steps; chmod -R +x /steps;
/entrypoint.sh; /entrypoint.sh;
rm -r /${buildVolumeFolder}/${buildUid} rm -r /${buildVolumeFolder}/${this.buildId}
`, `,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/${buildUid}/steam/action/`, [ ], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/${this.buildId}/steam/action/`, [
{ {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
@ -2414,7 +2415,7 @@ class RemoteBuilder {
{ {
EnvironmentVariable: 'INPUT_ROOTPATH', EnvironmentVariable: 'INPUT_ROOTPATH',
ParameterKey: 'rootPath', ParameterKey: 'rootPath',
ParameterValue: buildParameters.buildPath, ParameterValue: RemoteBuilder.buildParams.buildPath,
}, },
{ {
EnvironmentVariable: 'INPUT_RELEASEBRANCH', EnvironmentVariable: 'INPUT_RELEASEBRANCH',
@ -2431,7 +2432,7 @@ class RemoteBuilder {
ParameterKey: 'previewEnabled', ParameterKey: 'previewEnabled',
ParameterValue: process.env.PREVIEW_ENABLED || '', ParameterValue: process.env.PREVIEW_ENABLED || '',
}, },
...defaultSecretsArray, ...this.defaultSecrets,
]); ]);
}); });
} }

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,6 @@ import AWSBuildPlatform from './aws-build-platform';
import * as core from '@actions/core'; import * as core from '@actions/core';
import { BuildParameters } from '..'; import { BuildParameters } from '..';
import RemoteBuilderNamespace from './remote-builder-namespace'; import RemoteBuilderNamespace from './remote-builder-namespace';
import RemoteBuilderSecret from './remote-builder-secret';
import { RemoteBuilderProviderInterface } from './remote-builder-provider-interface'; import { RemoteBuilderProviderInterface } from './remote-builder-provider-interface';
import Kubernetes from './kubernetes-build-platform'; import Kubernetes from './kubernetes-build-platform';
const repositoryFolder = 'repo'; const repositoryFolder = 'repo';
@ -18,13 +17,17 @@ class RemoteBuilder {
private static repoPathFull: string; private static repoPathFull: string;
private static projectPathFull: string; private static projectPathFull: string;
private static libraryFolderFull: string; private static libraryFolderFull: string;
private static buildId: string;
private static buildParams: BuildParameters;
private static defaultSecrets;
static RemoteBuilderProviderPlatform: RemoteBuilderProviderInterface; static RemoteBuilderProviderPlatform: RemoteBuilderProviderInterface;
static async build(buildParameters: BuildParameters, baseImage) { static async build(buildParameters: BuildParameters, baseImage) {
const runNumber = process.env.GITHUB_RUN_NUMBER; const runNumber = process.env.GITHUB_RUN_NUMBER;
if (!runNumber || runNumber === '') { if (!runNumber || runNumber === '') {
throw new Error('no run number found, exiting'); throw new Error('no run number found, exiting');
} }
const buildUid = RemoteBuilderNamespace.generateBuildName(runNumber, buildParameters.platform); RemoteBuilder.buildParams = buildParameters;
RemoteBuilder.buildId = RemoteBuilderNamespace.generateBuildName(runNumber, buildParameters.platform);
const defaultBranchName = const defaultBranchName =
process.env.GITHUB_REF?.split('/') process.env.GITHUB_REF?.split('/')
.filter((x) => { .filter((x) => {
@ -35,8 +38,8 @@ class RemoteBuilder {
const branchName = const branchName =
process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName; process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false; this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
const token: string = buildParameters.githubToken; const token: string = this.buildParams.githubToken;
const defaultSecretsArray = [ this.defaultSecrets = [
{ {
ParameterKey: 'GithubToken', ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN', EnvironmentVariable: 'GITHUB_TOKEN',
@ -44,77 +47,73 @@ class RemoteBuilder {
}, },
]; ];
try { try {
switch (buildParameters.remoteBuildCluster) { switch (this.buildParams.remoteBuildCluster) {
case 'aws': case 'aws':
core.info('Building with AWS'); core.info('Building with AWS');
this.RemoteBuilderProviderPlatform = new AWSBuildPlatform(buildParameters); this.RemoteBuilderProviderPlatform = new AWSBuildPlatform(this.buildParams);
break; break;
default: default:
case 'k8s': case 'k8s':
core.info('Building with Kubernetes'); core.info('Building with Kubernetes');
this.RemoteBuilderProviderPlatform = new Kubernetes(buildParameters); this.RemoteBuilderProviderPlatform = new Kubernetes(this.buildParams);
break; break;
} }
await this.RemoteBuilderProviderPlatform.setupSharedBuildResources( await this.RemoteBuilderProviderPlatform.setupSharedBuildResources(
buildUid, this.buildId,
buildParameters, this.buildParams,
branchName, branchName,
defaultSecretsArray, this.defaultSecrets,
); );
this.buildPathFull = `/${buildVolumeFolder}/${buildUid}`; this.buildPathFull = `/${buildVolumeFolder}/${this.buildId}`;
this.builderPathFull = `${this.buildPathFull}/builder`; this.builderPathFull = `${this.buildPathFull}/builder`;
this.steamPathFull = `${this.buildPathFull}/steam`; this.steamPathFull = `${this.buildPathFull}/steam`;
this.repoPathFull = `${this.buildPathFull}/${repositoryFolder}`; this.repoPathFull = `${this.buildPathFull}/${repositoryFolder}`;
this.projectPathFull = `${this.repoPathFull}/${buildParameters.projectPath}`; this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`;
this.libraryFolderFull = `${this.projectPathFull}/Library`; this.libraryFolderFull = `${this.projectPathFull}/Library`;
await RemoteBuilder.SetupStep(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); await RemoteBuilder.SetupStep(branchName);
await RemoteBuilder.BuildStep(`${buildUid}`, buildParameters, baseImage, defaultSecretsArray); await RemoteBuilder.BuildStep(baseImage);
await RemoteBuilder.CompressionStep(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); await RemoteBuilder.CompressionStep();
await RemoteBuilder.UploadArtifacts(`${buildUid}`, buildParameters, branchName, defaultSecretsArray); await RemoteBuilder.UploadArtifacts(branchName);
if (this.SteamDeploy) { if (this.SteamDeploy) {
await RemoteBuilder.DeployToSteam(buildUid, buildParameters, defaultSecretsArray); await RemoteBuilder.DeployToSteam();
} }
await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources( await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(
buildUid, this.buildId,
buildParameters, this.buildParams,
branchName, branchName,
defaultSecretsArray, this.defaultSecrets,
); );
} catch (error) { } catch (error) {
core.error(JSON.stringify(error, undefined, 4)); core.error(JSON.stringify(error, undefined, 4));
core.setFailed('Remote Builder failed'); core.setFailed('Remote Builder failed');
await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources( await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(
buildUid, this.buildId,
buildParameters, this.buildParams,
branchName, branchName,
defaultSecretsArray, this.defaultSecrets,
); );
throw error; throw error;
} }
} }
private static async SetupStep( private static async SetupStep(branchName: string | undefined) {
buildUid: string,
buildParameters: BuildParameters,
branchName: string | undefined,
defaultSecretsArray: RemoteBuilderSecret[],
) {
core.info('Starting step 1/4 clone and restore cache)'); core.info('Starting step 1/4 clone and restore cache)');
const lfsDirectory = `${this.repoPathFull}/.git/lfs`; const lfsDirectory = `${this.repoPathFull}/.git/lfs`;
const testLFSFile = `${this.projectPathFull}/Assets/LFS_Test_File.jpg`; const testLFSFile = `${this.projectPathFull}/Assets/LFS_Test_File.jpg`;
const repo = `https://${buildParameters.githubToken}@github.com/game-ci/unity-builder.git`; const repo = `https://${this.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
const repo2 = `https://${buildParameters.githubToken}@github.com/game-ci/steam-deploy.git`; const repo2 = `https://${this.buildParams.githubToken}@github.com/game-ci/steam-deploy.git`;
const repo3 = `https://${buildParameters.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`; const repo3 = `https://${this.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
const purgeRemoteCache = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined; const purgeRemoteCache = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
const initializeSourceRepoForCaching = `${this.builderPathFull}/dist/remote-builder/cloneNoLFS.sh "${this.repoPathFull}" "${repo3}" "$GITHUB_SHA" "${testLFSFile}"`; const initializeSourceRepoForCaching = `${this.builderPathFull}/dist/remote-builder/cloneNoLFS.sh "${this.repoPathFull}" "${repo3}" "$GITHUB_SHA" "${testLFSFile}"`;
const handleCaching = `${this.builderPathFull}/dist/remote-builder/handleCaching.sh "${cacheFolderFull}" "${branchName}" "${this.libraryFolderFull}" "${lfsDirectory}" "${purgeRemoteCache}"`; const handleCaching = `${this.builderPathFull}/dist/remote-builder/handleCaching.sh "${cacheFolderFull}" "${branchName}" "${this.libraryFolderFull}" "${lfsDirectory}" "${purgeRemoteCache}"`;
await this.RemoteBuilderProviderPlatform.runBuildTask( await this.RemoteBuilderProviderPlatform.runBuildTask(
buildUid, this.buildId,
'alpine/git', 'alpine/git',
[ [
` apk update -q ` apk update -q
@ -166,19 +165,14 @@ class RemoteBuilder {
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], ],
defaultSecretsArray, this.defaultSecrets,
); );
} }
private static async BuildStep( private static async BuildStep(baseImage: any) {
buildUid: string,
buildParameters: BuildParameters,
baseImage: any,
defaultSecretsArray: RemoteBuilderSecret[],
) {
const buildSecrets = new Array(); const buildSecrets = new Array();
buildSecrets.push(...defaultSecretsArray); buildSecrets.push(...this.defaultSecrets);
if (process.env.UNITY_LICENSE) if (process.env.UNITY_LICENSE)
buildSecrets.push({ buildSecrets.push({
@ -208,29 +202,29 @@ class RemoteBuilder {
ParameterValue: process.env.UNITY_SERIAL, ParameterValue: process.env.UNITY_SERIAL,
}); });
if (buildParameters.androidKeystoreBase64) if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64', ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64', EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: buildParameters.androidKeystoreBase64, ParameterValue: this.buildParams.androidKeystoreBase64,
}); });
if (buildParameters.androidKeystorePass) if (this.buildParams.androidKeystorePass)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeystorePass', ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS', EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: buildParameters.androidKeystorePass, ParameterValue: this.buildParams.androidKeystorePass,
}); });
if (buildParameters.androidKeyaliasPass) if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({ buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass', ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS', EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: buildParameters.androidKeyaliasPass, ParameterValue: this.buildParams.androidKeyaliasPass,
}); });
core.info('Starting part 2/4 (build unity project)'); core.info('Starting part 2/4 (build unity project)');
await this.RemoteBuilderProviderPlatform.runBuildTask( await this.RemoteBuilderProviderPlatform.runBuildTask(
buildUid, this.buildId,
baseImage.toString(), baseImage.toString(),
[ [
` `
@ -247,83 +241,78 @@ class RemoteBuilder {
[ [
{ {
name: 'ContainerMemory', name: 'ContainerMemory',
value: buildParameters.remoteBuildMemory, value: this.buildParams.remoteBuildMemory,
}, },
{ {
name: 'ContainerCpu', name: 'ContainerCpu',
value: buildParameters.remoteBuildCpu, value: this.buildParams.remoteBuildCpu,
}, },
{ {
name: 'GITHUB_WORKSPACE', name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${buildUid}/${repositoryFolder}/`, value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
}, },
{ {
name: 'PROJECT_PATH', name: 'PROJECT_PATH',
value: buildParameters.projectPath, value: this.buildParams.projectPath,
}, },
{ {
name: 'BUILD_PATH', name: 'BUILD_PATH',
value: buildParameters.buildPath, value: this.buildParams.buildPath,
}, },
{ {
name: 'BUILD_FILE', name: 'BUILD_FILE',
value: buildParameters.buildFile, value: this.buildParams.buildFile,
}, },
{ {
name: 'BUILD_NAME', name: 'BUILD_NAME',
value: buildParameters.buildName, value: this.buildParams.buildName,
}, },
{ {
name: 'BUILD_METHOD', name: 'BUILD_METHOD',
value: buildParameters.buildMethod, value: this.buildParams.buildMethod,
}, },
{ {
name: 'CUSTOM_PARAMETERS', name: 'CUSTOM_PARAMETERS',
value: buildParameters.customParameters, value: this.buildParams.customParameters,
}, },
{ {
name: 'BUILD_TARGET', name: 'BUILD_TARGET',
value: buildParameters.platform, value: this.buildParams.platform,
}, },
{ {
name: 'ANDROID_VERSION_CODE', name: 'ANDROID_VERSION_CODE',
value: buildParameters.androidVersionCode.toString(), value: this.buildParams.androidVersionCode.toString(),
}, },
{ {
name: 'ANDROID_KEYSTORE_NAME', name: 'ANDROID_KEYSTORE_NAME',
value: buildParameters.androidKeystoreName, value: this.buildParams.androidKeystoreName,
}, },
{ {
name: 'ANDROID_KEYALIAS_NAME', name: 'ANDROID_KEYALIAS_NAME',
value: buildParameters.androidKeyaliasName, value: this.buildParams.androidKeyaliasName,
}, },
], ],
buildSecrets, buildSecrets,
); );
} }
private static async CompressionStep( private static async CompressionStep() {
buildUid: string,
buildParameters: BuildParameters,
branchName: string | undefined,
defaultSecretsArray: RemoteBuilderSecret[],
) {
core.info('Starting step 3/4 build compression'); core.info('Starting step 3/4 build compression');
// Cleanup // Cleanup
await this.RemoteBuilderProviderPlatform.runBuildTask( await this.RemoteBuilderProviderPlatform.runBuildTask(
buildUid, this.buildId,
'alpine', 'alpine',
[ [
` `
apk update -q apk update -q
apk add zip -q apk add zip -q
cd "${this.libraryFolderFull}" cd "${this.libraryFolderFull}"
zip -r "lib-${buildUid}.zip" "${this.libraryFolderFull}" zip -r "lib-${this.buildId}.zip" "${this.libraryFolderFull}"
mv "lib-${buildUid}.zip" "${cacheFolderFull}/lib/lib-${buildUid}.zip" mv "lib-${this.buildId}.zip" "${cacheFolderFull}/lib/lib-${this.buildId}.zip"
cd "${this.projectPathFull}" cd "${this.projectPathFull}"
ls -lh "${buildParameters.buildPath}" ls -lh "${RemoteBuilder.buildParams.buildPath}"
zip -r "build-${buildUid}.zip" "${buildParameters.buildPath}" zip -r "build-${this.buildId}.zip" "${RemoteBuilder.buildParams.buildPath}"
mv "build-${buildUid}.zip" "/${buildVolumeFolder}/${buildUid}/build-${buildUid}.zip" mv "build-${this.buildId}.zip" "/${buildVolumeFolder}/${this.buildId}/build-${this.buildId}.zip"
`, `,
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
@ -334,27 +323,22 @@ class RemoteBuilder {
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], ],
defaultSecretsArray, this.defaultSecrets,
); );
core.info('compression step complete'); core.info('compression step complete');
} }
private static async UploadArtifacts( private static async UploadArtifacts(branchName: string | undefined) {
buildUid: string,
buildParameters: BuildParameters,
branchName: string | undefined,
defaultSecretsArray: RemoteBuilderSecret[],
) {
core.info('Starting step 4/4 upload build to s3'); core.info('Starting step 4/4 upload build to s3');
await this.RemoteBuilderProviderPlatform.runBuildTask( await this.RemoteBuilderProviderPlatform.runBuildTask(
buildUid, this.buildId,
'amazon/aws-cli', 'amazon/aws-cli',
[ [
` `
aws s3 cp ${buildUid}/build-${buildUid}.zip s3://game-ci-storage/ aws s3 cp ${this.buildId}/build-${this.buildId}.zip s3://game-ci-storage/
# no need to upload Library cache for now # no need to upload Library cache for now
# aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/ # aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${this.buildId}.zip s3://game-ci-storage/
${this.SteamDeploy ? '#' : ''} rm -r ${buildUid} ${this.SteamDeploy ? '#' : ''} rm -r ${this.buildId}
`, `,
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
@ -380,34 +364,30 @@ class RemoteBuilder {
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY', EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '', ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
}, },
...defaultSecretsArray, ...this.defaultSecrets,
], ],
); );
} }
private static async DeployToSteam( private static async DeployToSteam() {
buildUid: string,
buildParameters: BuildParameters,
defaultSecretsArray: RemoteBuilderSecret[],
) {
core.info('Starting steam deployment'); core.info('Starting steam deployment');
await this.RemoteBuilderProviderPlatform.runBuildTask( await this.RemoteBuilderProviderPlatform.runBuildTask(
buildUid, this.buildId,
'cm2network/steamcmd:root', 'cm2network/steamcmd:root',
[ [
` `
ls ls
ls / ls /
cp -r /${buildVolumeFolder}/${buildUid}/steam/action/entrypoint.sh /entrypoint.sh; cp -r /${buildVolumeFolder}/${this.buildId}/steam/action/entrypoint.sh /entrypoint.sh;
cp -r /${buildVolumeFolder}/${buildUid}/steam/action/steps/ /steps; cp -r /${buildVolumeFolder}/${this.buildId}/steam/action/steps/ /steps;
chmod -R +x /entrypoint.sh; chmod -R +x /entrypoint.sh;
chmod -R +x /steps; chmod -R +x /steps;
/entrypoint.sh; /entrypoint.sh;
rm -r /${buildVolumeFolder}/${buildUid} rm -r /${buildVolumeFolder}/${this.buildId}
`, `,
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
`/${buildVolumeFolder}/${buildUid}/steam/action/`, `/${buildVolumeFolder}/${this.buildId}/steam/action/`,
[ [
{ {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
@ -428,7 +408,7 @@ class RemoteBuilder {
{ {
EnvironmentVariable: 'INPUT_ROOTPATH', EnvironmentVariable: 'INPUT_ROOTPATH',
ParameterKey: 'rootPath', ParameterKey: 'rootPath',
ParameterValue: buildParameters.buildPath, ParameterValue: RemoteBuilder.buildParams.buildPath,
}, },
{ {
EnvironmentVariable: 'INPUT_RELEASEBRANCH', EnvironmentVariable: 'INPUT_RELEASEBRANCH',
@ -445,7 +425,7 @@ class RemoteBuilder {
ParameterKey: 'previewEnabled', ParameterKey: 'previewEnabled',
ParameterValue: process.env.PREVIEW_ENABLED || '', ParameterValue: process.env.PREVIEW_ENABLED || '',
}, },
...defaultSecretsArray, ...this.defaultSecrets,
], ],
); );
} }