pull/289/head
Frostebite 2021-08-02 00:38:30 +01:00
parent fd8599c0ac
commit 2a1d36b928
3 changed files with 492 additions and 423 deletions

429
dist/index.js vendored
View File

@ -2093,67 +2093,35 @@ const cacheFolder = 'cache';
const cacheFolderFull = `/${buildVolumeFolder}/${cacheFolder}`; const cacheFolderFull = `/${buildVolumeFolder}/${cacheFolder}`;
class RemoteBuilder { class RemoteBuilder {
static build(buildParameters, baseImage) { static build(buildParameters, baseImage) {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const runNumber = process.env.GITHUB_RUN_NUMBER; RemoteBuilder.buildId = remote_builder_namespace_1.default.generateBuildName(RemoteBuilder.readRunNumber(), buildParameters.platform);
if (!runNumber || runNumber === '') {
throw new Error('no run number found, exiting');
}
RemoteBuilder.buildParams = buildParameters; RemoteBuilder.buildParams = buildParameters;
RemoteBuilder.buildId = remote_builder_namespace_1.default.generateBuildName(runNumber, buildParameters.platform); RemoteBuilder.readBranchNameSetting();
const defaultBranchName = ((_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').filter((x) => { RemoteBuilder.setupDefaultSecrets();
x = x[0].toUpperCase() + x.slice(1);
return x;
}).join('')) || '';
const branchName = process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
const token = this.buildParams.githubToken;
RemoteBuilder.newMethod(token);
try { try {
switch (this.buildParams.remoteBuildCluster) { RemoteBuilder.setupBuildPlatform();
case 'aws': yield this.RemoteBuilderProviderPlatform.setupSharedBuildResources(this.buildId, this.buildParams, this.branchName, this.defaultSecrets);
core.info('Building with AWS');
this.RemoteBuilderProviderPlatform = new aws_build_platform_1.default(this.buildParams);
break;
default:
case 'k8s':
core.info('Building with Kubernetes');
this.RemoteBuilderProviderPlatform = new kubernetes_build_platform_1.default(this.buildParams);
break;
}
yield this.RemoteBuilderProviderPlatform.setupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets);
this.buildPathFull = `/${buildVolumeFolder}/${this.buildId}`; 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}/${this.buildParams.projectPath}`; this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`;
this.libraryFolderFull = `${this.projectPathFull}/Library`; this.libraryFolderFull = `${this.projectPathFull}/Library`;
yield RemoteBuilder.SetupStep(branchName); yield RemoteBuilder.SetupStep(this.branchName);
yield RemoteBuilder.BuildStep(baseImage); yield RemoteBuilder.BuildStep(baseImage);
yield RemoteBuilder.CompressionStep(); yield RemoteBuilder.CompressionStep();
yield RemoteBuilder.UploadArtifacts(branchName); yield RemoteBuilder.UploadArtifacts(this.branchName);
if (this.SteamDeploy) { if (this.SteamDeploy) {
yield RemoteBuilder.DeployToSteam(); yield RemoteBuilder.DeployToSteam();
} }
yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets); yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, this.branchName, this.defaultSecrets);
} }
catch (error) { catch (error) {
core.error(JSON.stringify(error, undefined, 4)); yield RemoteBuilder.handleException(error);
core.setFailed('Remote Builder failed');
yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, branchName, this.defaultSecrets);
throw error; throw error;
} }
}); });
} }
static newMethod(token) {
this.defaultSecrets = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: token,
},
];
}
static SetupStep(branchName) { 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)');
@ -2206,60 +2174,13 @@ class RemoteBuilder {
echo ' ' echo ' '
# #
`, `,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, [ ], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, RemoteBuilder.defaultGitShaEnvironmentVariable, this.defaultSecrets);
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
], this.defaultSecrets);
}); });
} }
static BuildStep(baseImage) { 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(...this.defaultSecrets); RemoteBuilder.setupBuildSecrets(buildSecrets);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParams.androidKeystoreBase64,
});
if (this.buildParams.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParams.androidKeystorePass,
});
if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
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(this.buildId, baseImage.toString(), [ yield this.RemoteBuilderProviderPlatform.runBuildTask(this.buildId, baseImage.toString(), [
` `
@ -2270,60 +2191,7 @@ class RemoteBuilder {
chmod -R +x "/steps" chmod -R +x "/steps"
/entrypoint.sh /entrypoint.sh
`, `,
], `/${buildVolumeFolder}`, `/${this.repoPathFull}`, [ ], `/${buildVolumeFolder}`, `/${this.repoPathFull}`, RemoteBuilder.readBuildEnvironmentVariables(), buildSecrets);
{
name: 'ContainerMemory',
value: this.buildParams.remoteBuildMemory,
},
{
name: 'ContainerCpu',
value: this.buildParams.remoteBuildCpu,
},
{
name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
},
{
name: 'PROJECT_PATH',
value: this.buildParams.projectPath,
},
{
name: 'BUILD_PATH',
value: this.buildParams.buildPath,
},
{
name: 'BUILD_FILE',
value: this.buildParams.buildFile,
},
{
name: 'BUILD_NAME',
value: this.buildParams.buildName,
},
{
name: 'BUILD_METHOD',
value: this.buildParams.buildMethod,
},
{
name: 'CUSTOM_PARAMETERS',
value: this.buildParams.customParameters,
},
{
name: 'BUILD_TARGET',
value: this.buildParams.platform,
},
{
name: 'ANDROID_VERSION_CODE',
value: this.buildParams.androidVersionCode.toString(),
},
{
name: 'ANDROID_KEYSTORE_NAME',
value: this.buildParams.androidKeystoreName,
},
{
name: 'ANDROID_KEYALIAS_NAME',
value: this.buildParams.androidKeyaliasName,
},
], buildSecrets);
}); });
} }
static CompressionStep() { static CompressionStep() {
@ -2361,28 +2229,7 @@ class RemoteBuilder {
# aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${this.buildId}.zip s3://game-ci-storage/ # aws s3 cp /${buildVolumeFolder}/${cacheFolder}/${branchName}/lib-${this.buildId}.zip s3://game-ci-storage/
${this.SteamDeploy ? '#' : ''} rm -r ${this.buildId} ${this.SteamDeploy ? '#' : ''} rm -r ${this.buildId}
`, `,
], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, [ ], `/${buildVolumeFolder}`, `/${buildVolumeFolder}/`, RemoteBuilder.readUploadArtifactEnvironmentVariables(), RemoteBuilder.readUploadArtifactsSecrets());
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'AWS_DEFAULT_REGION',
value: process.env.AWS_DEFAULT_REGION || '',
},
], [
{
ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID || '',
},
{
ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
},
...this.defaultSecrets,
]);
}); });
} }
static DeployToSteam() { static DeployToSteam() {
@ -2404,43 +2251,225 @@ class RemoteBuilder {
name: 'GITHUB_SHA', name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], [ ], RemoteBuilder.readDeployToSteamSecrets());
{ });
EnvironmentVariable: 'INPUT_APPID', }
ParameterKey: 'appId', static setupBuildPlatform() {
ParameterValue: process.env.APP_ID || '', switch (this.buildParams.remoteBuildCluster) {
}, case 'aws':
{ core.info('Building with AWS');
EnvironmentVariable: 'INPUT_BUILDDESCRIPTION', this.RemoteBuilderProviderPlatform = new aws_build_platform_1.default(this.buildParams);
ParameterKey: 'buildDescription', break;
ParameterValue: process.env.BUILD_DESCRIPTION || '', default:
}, case 'k8s':
{ core.info('Building with Kubernetes');
EnvironmentVariable: 'INPUT_ROOTPATH', this.RemoteBuilderProviderPlatform = new kubernetes_build_platform_1.default(this.buildParams);
ParameterKey: 'rootPath', break;
ParameterValue: RemoteBuilder.buildParams.buildPath, }
}, }
{ static readRunNumber() {
EnvironmentVariable: 'INPUT_RELEASEBRANCH', const runNumber = process.env.GITHUB_RUN_NUMBER;
ParameterKey: 'releaseBranch', if (!runNumber || runNumber === '') {
ParameterValue: process.env.RELEASE_BRANCH || '', throw new Error('no run number found, exiting');
}, }
{ return runNumber;
EnvironmentVariable: 'INPUT_LOCALCONTENTSERVER', }
ParameterKey: 'localContentServer', static readBranchNameSetting() {
ParameterValue: process.env.LOCAL_CONTENT_SERVER || '', var _a;
}, const defaultBranchName = ((_a = process.env.GITHUB_REF) === null || _a === void 0 ? void 0 : _a.split('/').filter((x) => {
{ x = x[0].toUpperCase() + x.slice(1);
EnvironmentVariable: 'INPUT_PREVIEWENABLED', return x;
ParameterKey: 'previewEnabled', }).join('')) || '';
ParameterValue: process.env.PREVIEW_ENABLED || '', this.branchName =
}, process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
...this.defaultSecrets, }
]); static setupDefaultSecrets() {
this.defaultSecrets = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParams.githubToken,
},
];
}
static setupBuildSecrets(buildSecrets) {
buildSecrets.push(...this.defaultSecrets);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParams.androidKeystoreBase64,
});
if (this.buildParams.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParams.androidKeystorePass,
});
if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: this.buildParams.androidKeyaliasPass,
});
}
static readUploadArtifactsSecrets() {
return [
{
ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID || '',
},
{
ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
},
...this.defaultSecrets,
];
}
static readDeployToSteamSecrets() {
return [
{
EnvironmentVariable: 'INPUT_APPID',
ParameterKey: 'appId',
ParameterValue: process.env.APP_ID || '',
},
{
EnvironmentVariable: 'INPUT_BUILDDESCRIPTION',
ParameterKey: 'buildDescription',
ParameterValue: process.env.BUILD_DESCRIPTION || '',
},
{
EnvironmentVariable: 'INPUT_ROOTPATH',
ParameterKey: 'rootPath',
ParameterValue: RemoteBuilder.buildParams.buildPath,
},
{
EnvironmentVariable: 'INPUT_RELEASEBRANCH',
ParameterKey: 'releaseBranch',
ParameterValue: process.env.RELEASE_BRANCH || '',
},
{
EnvironmentVariable: 'INPUT_LOCALCONTENTSERVER',
ParameterKey: 'localContentServer',
ParameterValue: process.env.LOCAL_CONTENT_SERVER || '',
},
{
EnvironmentVariable: 'INPUT_PREVIEWENABLED',
ParameterKey: 'previewEnabled',
ParameterValue: process.env.PREVIEW_ENABLED || '',
},
...this.defaultSecrets,
];
}
static readUploadArtifactEnvironmentVariables() {
return [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'AWS_DEFAULT_REGION',
value: process.env.AWS_DEFAULT_REGION || '',
},
];
}
static readBuildEnvironmentVariables() {
return [
{
name: 'ContainerMemory',
value: this.buildParams.remoteBuildMemory,
},
{
name: 'ContainerCpu',
value: this.buildParams.remoteBuildCpu,
},
{
name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
},
{
name: 'PROJECT_PATH',
value: this.buildParams.projectPath,
},
{
name: 'BUILD_PATH',
value: this.buildParams.buildPath,
},
{
name: 'BUILD_FILE',
value: this.buildParams.buildFile,
},
{
name: 'BUILD_NAME',
value: this.buildParams.buildName,
},
{
name: 'BUILD_METHOD',
value: this.buildParams.buildMethod,
},
{
name: 'CUSTOM_PARAMETERS',
value: this.buildParams.customParameters,
},
{
name: 'BUILD_TARGET',
value: this.buildParams.platform,
},
{
name: 'ANDROID_VERSION_CODE',
value: this.buildParams.androidVersionCode.toString(),
},
{
name: 'ANDROID_KEYSTORE_NAME',
value: this.buildParams.androidKeystoreName,
},
{
name: 'ANDROID_KEYALIAS_NAME',
value: this.buildParams.androidKeyaliasName,
},
];
}
static handleException(error) {
return __awaiter(this, void 0, void 0, function* () {
core.error(JSON.stringify(error, undefined, 4));
core.setFailed('Remote Builder failed');
yield this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(this.buildId, this.buildParams, this.branchName, this.defaultSecrets);
}); });
} }
} }
RemoteBuilder.SteamDeploy = false; RemoteBuilder.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
RemoteBuilder.defaultGitShaEnvironmentVariable = [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
];
exports.default = RemoteBuilder; exports.default = RemoteBuilder;

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -5,59 +5,47 @@ import RemoteBuilderNamespace from './remote-builder-namespace';
import RemoteBuilderSecret from './remote-builder-secret'; 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';
import RemoteBuilderEnvironmentVariable from './remote-builder-environment-variable';
const repositoryFolder = 'repo'; const repositoryFolder = 'repo';
const buildVolumeFolder = 'data'; const buildVolumeFolder = 'data';
const cacheFolder = 'cache'; const cacheFolder = 'cache';
const cacheFolderFull = `/${buildVolumeFolder}/${cacheFolder}`; const cacheFolderFull = `/${buildVolumeFolder}/${cacheFolder}`;
class RemoteBuilder { class RemoteBuilder {
static SteamDeploy: boolean = false; private static buildId: string;
private static branchName: string;
private static buildParams: BuildParameters;
static RemoteBuilderProviderPlatform: RemoteBuilderProviderInterface;
private static defaultSecrets: RemoteBuilderSecret[];
static SteamDeploy: boolean = process.env.STEAM_DEPLOY !== undefined || false;
private static buildPathFull: string; private static buildPathFull: string;
private static builderPathFull: string; private static builderPathFull: string;
private static steamPathFull: string; private static steamPathFull: string;
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 readonly defaultGitShaEnvironmentVariable = [
private static buildParams: BuildParameters; {
private static defaultSecrets: RemoteBuilderSecret[]; name: 'GITHUB_SHA',
static RemoteBuilderProviderPlatform: RemoteBuilderProviderInterface; value: process.env.GITHUB_SHA || '',
},
];
static async build(buildParameters: BuildParameters, baseImage) { static async build(buildParameters: BuildParameters, baseImage) {
const runNumber = process.env.GITHUB_RUN_NUMBER; RemoteBuilder.buildId = RemoteBuilderNamespace.generateBuildName(
if (!runNumber || runNumber === '') { RemoteBuilder.readRunNumber(),
throw new Error('no run number found, exiting'); buildParameters.platform,
} );
RemoteBuilder.buildParams = buildParameters; RemoteBuilder.buildParams = buildParameters;
RemoteBuilder.buildId = RemoteBuilderNamespace.generateBuildName(runNumber, buildParameters.platform); RemoteBuilder.readBranchNameSetting();
const defaultBranchName = RemoteBuilder.setupDefaultSecrets();
process.env.GITHUB_REF?.split('/')
.filter((x) => {
x = x[0].toUpperCase() + x.slice(1);
return x;
})
.join('') || '';
const branchName =
process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
this.SteamDeploy = process.env.STEAM_DEPLOY !== undefined || false;
const token: string = this.buildParams.githubToken;
RemoteBuilder.newMethod(token);
try { try {
switch (this.buildParams.remoteBuildCluster) { RemoteBuilder.setupBuildPlatform();
case 'aws':
core.info('Building with AWS');
this.RemoteBuilderProviderPlatform = new AWSBuildPlatform(this.buildParams);
break;
default:
case 'k8s':
core.info('Building with Kubernetes');
this.RemoteBuilderProviderPlatform = new Kubernetes(this.buildParams);
break;
}
await this.RemoteBuilderProviderPlatform.setupSharedBuildResources( await this.RemoteBuilderProviderPlatform.setupSharedBuildResources(
this.buildId, this.buildId,
this.buildParams, this.buildParams,
branchName, this.branchName,
this.defaultSecrets, this.defaultSecrets,
); );
@ -68,42 +56,25 @@ class RemoteBuilder {
this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`; this.projectPathFull = `${this.repoPathFull}/${this.buildParams.projectPath}`;
this.libraryFolderFull = `${this.projectPathFull}/Library`; this.libraryFolderFull = `${this.projectPathFull}/Library`;
await RemoteBuilder.SetupStep(branchName); await RemoteBuilder.SetupStep(this.branchName);
await RemoteBuilder.BuildStep(baseImage); await RemoteBuilder.BuildStep(baseImage);
await RemoteBuilder.CompressionStep(); await RemoteBuilder.CompressionStep();
await RemoteBuilder.UploadArtifacts(branchName); await RemoteBuilder.UploadArtifacts(this.branchName);
if (this.SteamDeploy) { if (this.SteamDeploy) {
await RemoteBuilder.DeployToSteam(); await RemoteBuilder.DeployToSteam();
} }
await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources( await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(
this.buildId, this.buildId,
this.buildParams, this.buildParams,
branchName, this.branchName,
this.defaultSecrets, this.defaultSecrets,
); );
} catch (error) { } catch (error) {
core.error(JSON.stringify(error, undefined, 4)); await RemoteBuilder.handleException(error);
core.setFailed('Remote Builder failed');
await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(
this.buildId,
this.buildParams,
branchName,
this.defaultSecrets,
);
throw error; throw error;
} }
} }
private static newMethod(token: string) {
this.defaultSecrets = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: token,
},
];
}
private static async SetupStep(branchName: string | undefined) { private static async SetupStep(branchName: string | undefined) {
core.info('Starting step 1/4 clone and restore cache)'); core.info('Starting step 1/4 clone and restore cache)');
@ -164,69 +135,14 @@ class RemoteBuilder {
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
`/${buildVolumeFolder}/`, `/${buildVolumeFolder}/`,
[ RemoteBuilder.defaultGitShaEnvironmentVariable,
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
],
this.defaultSecrets, this.defaultSecrets,
); );
} }
private static async BuildStep(baseImage: any) { private static async BuildStep(baseImage: any) {
const buildSecrets = new Array(); const buildSecrets = new Array();
RemoteBuilder.setupBuildSecrets(buildSecrets);
buildSecrets.push(...this.defaultSecrets);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParams.androidKeystoreBase64,
});
if (this.buildParams.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParams.androidKeystorePass,
});
if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
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(
this.buildId, this.buildId,
@ -243,60 +159,7 @@ class RemoteBuilder {
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
`/${this.repoPathFull}`, `/${this.repoPathFull}`,
[ RemoteBuilder.readBuildEnvironmentVariables(),
{
name: 'ContainerMemory',
value: this.buildParams.remoteBuildMemory,
},
{
name: 'ContainerCpu',
value: this.buildParams.remoteBuildCpu,
},
{
name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
},
{
name: 'PROJECT_PATH',
value: this.buildParams.projectPath,
},
{
name: 'BUILD_PATH',
value: this.buildParams.buildPath,
},
{
name: 'BUILD_FILE',
value: this.buildParams.buildFile,
},
{
name: 'BUILD_NAME',
value: this.buildParams.buildName,
},
{
name: 'BUILD_METHOD',
value: this.buildParams.buildMethod,
},
{
name: 'CUSTOM_PARAMETERS',
value: this.buildParams.customParameters,
},
{
name: 'BUILD_TARGET',
value: this.buildParams.platform,
},
{
name: 'ANDROID_VERSION_CODE',
value: this.buildParams.androidVersionCode.toString(),
},
{
name: 'ANDROID_KEYSTORE_NAME',
value: this.buildParams.androidKeystoreName,
},
{
name: 'ANDROID_KEYALIAS_NAME',
value: this.buildParams.androidKeyaliasName,
},
],
buildSecrets, buildSecrets,
); );
} }
@ -348,29 +211,8 @@ class RemoteBuilder {
], ],
`/${buildVolumeFolder}`, `/${buildVolumeFolder}`,
`/${buildVolumeFolder}/`, `/${buildVolumeFolder}/`,
[ RemoteBuilder.readUploadArtifactEnvironmentVariables(),
{ RemoteBuilder.readUploadArtifactsSecrets(),
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'AWS_DEFAULT_REGION',
value: process.env.AWS_DEFAULT_REGION || '',
},
],
[
{
ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID || '',
},
{
ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
},
...this.defaultSecrets,
],
); );
} }
@ -399,39 +241,237 @@ class RemoteBuilder {
value: process.env.GITHUB_SHA || '', value: process.env.GITHUB_SHA || '',
}, },
], ],
[ RemoteBuilder.readDeployToSteamSecrets(),
{ );
EnvironmentVariable: 'INPUT_APPID', }
ParameterKey: 'appId',
ParameterValue: process.env.APP_ID || '', private static setupBuildPlatform() {
}, switch (this.buildParams.remoteBuildCluster) {
{ case 'aws':
EnvironmentVariable: 'INPUT_BUILDDESCRIPTION', core.info('Building with AWS');
ParameterKey: 'buildDescription', this.RemoteBuilderProviderPlatform = new AWSBuildPlatform(this.buildParams);
ParameterValue: process.env.BUILD_DESCRIPTION || '', break;
}, default:
{ case 'k8s':
EnvironmentVariable: 'INPUT_ROOTPATH', core.info('Building with Kubernetes');
ParameterKey: 'rootPath', this.RemoteBuilderProviderPlatform = new Kubernetes(this.buildParams);
ParameterValue: RemoteBuilder.buildParams.buildPath, break;
}, }
{ }
EnvironmentVariable: 'INPUT_RELEASEBRANCH',
ParameterKey: 'releaseBranch', private static readRunNumber() {
ParameterValue: process.env.RELEASE_BRANCH || '', const runNumber = process.env.GITHUB_RUN_NUMBER;
}, if (!runNumber || runNumber === '') {
{ throw new Error('no run number found, exiting');
EnvironmentVariable: 'INPUT_LOCALCONTENTSERVER', }
ParameterKey: 'localContentServer', return runNumber;
ParameterValue: process.env.LOCAL_CONTENT_SERVER || '', }
},
{ private static readBranchNameSetting() {
EnvironmentVariable: 'INPUT_PREVIEWENABLED', const defaultBranchName =
ParameterKey: 'previewEnabled', process.env.GITHUB_REF?.split('/')
ParameterValue: process.env.PREVIEW_ENABLED || '', .filter((x) => {
}, x = x[0].toUpperCase() + x.slice(1);
...this.defaultSecrets, return x;
], })
.join('') || '';
this.branchName =
process.env.REMOTE_BUILDER_CACHE !== undefined ? process.env.REMOTE_BUILDER_CACHE : defaultBranchName;
}
private static setupDefaultSecrets() {
this.defaultSecrets = [
{
ParameterKey: 'GithubToken',
EnvironmentVariable: 'GITHUB_TOKEN',
ParameterValue: this.buildParams.githubToken,
},
];
}
private static setupBuildSecrets(buildSecrets: any[]) {
buildSecrets.push(...this.defaultSecrets);
if (process.env.UNITY_LICENSE)
buildSecrets.push({
ParameterKey: 'UnityLicense',
EnvironmentVariable: 'UNITY_LICENSE',
ParameterValue: process.env.UNITY_LICENSE,
});
if (process.env.UNITY_EMAIL)
buildSecrets.push({
ParameterKey: 'UnityEmail',
EnvironmentVariable: 'UNITY_EMAIL',
ParameterValue: process.env.UNITY_EMAIL,
});
if (process.env.UNITY_PASSWORD)
buildSecrets.push({
ParameterKey: 'UnityPassword',
EnvironmentVariable: 'UNITY_PASSWORD',
ParameterValue: process.env.UNITY_PASSWORD,
});
if (process.env.UNITY_SERIAL)
buildSecrets.push({
ParameterKey: 'UnitySerial',
EnvironmentVariable: 'UNITY_SERIAL',
ParameterValue: process.env.UNITY_SERIAL,
});
if (this.buildParams.androidKeystoreBase64)
buildSecrets.push({
ParameterKey: 'AndroidKeystoreBase64',
EnvironmentVariable: 'ANDROID_KEYSTORE_BASE64',
ParameterValue: this.buildParams.androidKeystoreBase64,
});
if (this.buildParams.androidKeystorePass)
buildSecrets.push({
ParameterKey: 'AndroidKeystorePass',
EnvironmentVariable: 'ANDROID_KEYSTORE_PASS',
ParameterValue: this.buildParams.androidKeystorePass,
});
if (this.buildParams.androidKeyaliasPass)
buildSecrets.push({
ParameterKey: 'AndroidKeyAliasPass',
EnvironmentVariable: 'AWS_ACCESS_KEY_ALIAS_PASS',
ParameterValue: this.buildParams.androidKeyaliasPass,
});
}
private static readUploadArtifactsSecrets() {
return [
{
ParameterKey: 'AWSAccessKeyID',
EnvironmentVariable: 'AWS_ACCESS_KEY_ID',
ParameterValue: process.env.AWS_ACCESS_KEY_ID || '',
},
{
ParameterKey: 'AWSSecretAccessKey',
EnvironmentVariable: 'AWS_SECRET_ACCESS_KEY',
ParameterValue: process.env.AWS_SECRET_ACCESS_KEY || '',
},
...this.defaultSecrets,
];
}
private static readDeployToSteamSecrets(): RemoteBuilderSecret[] {
return [
{
EnvironmentVariable: 'INPUT_APPID',
ParameterKey: 'appId',
ParameterValue: process.env.APP_ID || '',
},
{
EnvironmentVariable: 'INPUT_BUILDDESCRIPTION',
ParameterKey: 'buildDescription',
ParameterValue: process.env.BUILD_DESCRIPTION || '',
},
{
EnvironmentVariable: 'INPUT_ROOTPATH',
ParameterKey: 'rootPath',
ParameterValue: RemoteBuilder.buildParams.buildPath,
},
{
EnvironmentVariable: 'INPUT_RELEASEBRANCH',
ParameterKey: 'releaseBranch',
ParameterValue: process.env.RELEASE_BRANCH || '',
},
{
EnvironmentVariable: 'INPUT_LOCALCONTENTSERVER',
ParameterKey: 'localContentServer',
ParameterValue: process.env.LOCAL_CONTENT_SERVER || '',
},
{
EnvironmentVariable: 'INPUT_PREVIEWENABLED',
ParameterKey: 'previewEnabled',
ParameterValue: process.env.PREVIEW_ENABLED || '',
},
...this.defaultSecrets,
];
}
private static readUploadArtifactEnvironmentVariables() {
return [
{
name: 'GITHUB_SHA',
value: process.env.GITHUB_SHA || '',
},
{
name: 'AWS_DEFAULT_REGION',
value: process.env.AWS_DEFAULT_REGION || '',
},
];
}
private static readBuildEnvironmentVariables(): RemoteBuilderEnvironmentVariable[] {
return [
{
name: 'ContainerMemory',
value: this.buildParams.remoteBuildMemory,
},
{
name: 'ContainerCpu',
value: this.buildParams.remoteBuildCpu,
},
{
name: 'GITHUB_WORKSPACE',
value: `/${buildVolumeFolder}/${this.buildId}/${repositoryFolder}/`,
},
{
name: 'PROJECT_PATH',
value: this.buildParams.projectPath,
},
{
name: 'BUILD_PATH',
value: this.buildParams.buildPath,
},
{
name: 'BUILD_FILE',
value: this.buildParams.buildFile,
},
{
name: 'BUILD_NAME',
value: this.buildParams.buildName,
},
{
name: 'BUILD_METHOD',
value: this.buildParams.buildMethod,
},
{
name: 'CUSTOM_PARAMETERS',
value: this.buildParams.customParameters,
},
{
name: 'BUILD_TARGET',
value: this.buildParams.platform,
},
{
name: 'ANDROID_VERSION_CODE',
value: this.buildParams.androidVersionCode.toString(),
},
{
name: 'ANDROID_KEYSTORE_NAME',
value: this.buildParams.androidKeystoreName,
},
{
name: 'ANDROID_KEYALIAS_NAME',
value: this.buildParams.androidKeyaliasName,
},
];
}
private static async handleException(error: unknown) {
core.error(JSON.stringify(error, undefined, 4));
core.setFailed('Remote Builder failed');
await this.RemoteBuilderProviderPlatform.cleanupSharedBuildResources(
this.buildId,
this.buildParams,
this.branchName,
this.defaultSecrets,
); );
} }
} }