2022-02-01 02:31:20 +00:00
|
|
|
import { customAlphabet } from 'nanoid';
|
2022-01-25 21:18:15 +00:00
|
|
|
import * as core from '@actions/core';
|
2020-06-24 22:02:05 +00:00
|
|
|
import AndroidVersioning from './android-versioning';
|
2022-02-01 02:31:20 +00:00
|
|
|
import CloudRunnerConstants from './cloud-runner/services/cloud-runner-constants';
|
|
|
|
import CloudRunnerNamespace from './cloud-runner/services/cloud-runner-namespace';
|
2020-05-21 15:44:56 +00:00
|
|
|
import Input from './input';
|
2020-01-20 23:06:14 +00:00
|
|
|
import Platform from './platform';
|
2020-12-29 05:36:31 +00:00
|
|
|
import UnityVersioning from './unity-versioning';
|
2020-05-21 15:44:56 +00:00
|
|
|
import Versioning from './versioning';
|
2020-01-20 23:06:14 +00:00
|
|
|
|
|
|
|
class BuildParameters {
|
2021-05-23 04:08:40 +00:00
|
|
|
public version!: string;
|
|
|
|
public customImage!: string;
|
2022-01-25 21:18:15 +00:00
|
|
|
public unitySerial!: string;
|
2021-05-23 04:08:40 +00:00
|
|
|
public runnerTempPath: string | undefined;
|
|
|
|
public platform!: string;
|
|
|
|
public projectPath!: string;
|
|
|
|
public buildName!: string;
|
|
|
|
public buildPath!: string;
|
|
|
|
public buildFile!: string;
|
|
|
|
public buildMethod!: string;
|
|
|
|
public buildVersion!: string;
|
|
|
|
public androidVersionCode!: string;
|
|
|
|
public androidKeystoreName!: string;
|
|
|
|
public androidKeystoreBase64!: string;
|
|
|
|
public androidKeystorePass!: string;
|
|
|
|
public androidKeyaliasName!: string;
|
|
|
|
public androidKeyaliasPass!: string;
|
2021-11-24 12:51:52 +00:00
|
|
|
public androidTargetSdkVersion!: string;
|
|
|
|
public androidSdkManagerParameters!: string;
|
2021-05-23 04:08:40 +00:00
|
|
|
public customParameters!: string;
|
2021-05-28 21:51:10 +00:00
|
|
|
public sshAgent!: string;
|
2022-02-01 02:31:20 +00:00
|
|
|
public cloudRunnerCluster!: string;
|
|
|
|
public awsBaseStackName!: string;
|
2021-11-14 22:52:35 +00:00
|
|
|
public gitPrivateToken!: string;
|
2021-05-23 04:08:40 +00:00
|
|
|
public remoteBuildCluster!: string;
|
|
|
|
public awsStackName!: string;
|
|
|
|
public kubeConfig!: string;
|
|
|
|
public githubToken!: string;
|
2022-02-01 02:31:20 +00:00
|
|
|
public cloudRunnerMemory!: string;
|
|
|
|
public cloudRunnerCpu!: string;
|
2021-05-23 04:08:40 +00:00
|
|
|
public kubeVolumeSize!: string;
|
|
|
|
public kubeVolume!: string;
|
|
|
|
public chownFilesTo!: string;
|
|
|
|
|
2022-02-01 02:31:20 +00:00
|
|
|
public postBuildSteps!: string;
|
|
|
|
public preBuildSteps!: string;
|
|
|
|
public customJob!: string;
|
|
|
|
public runNumber!: string;
|
|
|
|
public branch!: string;
|
|
|
|
public githubRepo!: string;
|
|
|
|
public gitSha!: string;
|
|
|
|
public logId!: string;
|
|
|
|
public buildGuid!: string;
|
|
|
|
|
2021-05-23 04:08:40 +00:00
|
|
|
static async create(): Promise<BuildParameters> {
|
2021-03-13 23:44:01 +00:00
|
|
|
const buildFile = this.parseBuildFile(Input.buildName, Input.targetPlatform, Input.androidAppBundle);
|
|
|
|
const unityVersion = UnityVersioning.determineUnityVersion(Input.projectPath, Input.unityVersion);
|
|
|
|
const buildVersion = await Versioning.determineVersion(Input.versioningStrategy, Input.specifiedVersion);
|
|
|
|
const androidVersionCode = AndroidVersioning.determineVersionCode(buildVersion, Input.androidVersionCode);
|
2021-11-24 12:51:52 +00:00
|
|
|
const androidSdkManagerParameters = AndroidVersioning.determineSdkManagerParameters(Input.androidTargetSdkVersion);
|
|
|
|
|
2022-03-27 23:23:32 +00:00
|
|
|
// Todo - Don't use process.env directly, that's what the input model class is for.
|
|
|
|
// ---
|
2022-01-25 21:18:15 +00:00
|
|
|
let unitySerial = '';
|
|
|
|
if (!process.env.UNITY_SERIAL) {
|
|
|
|
//No serial was present so it is a personal license that we need to convert
|
|
|
|
if (!process.env.UNITY_LICENSE) {
|
|
|
|
throw new Error(`Missing Unity License File and no Serial was found. If this
|
|
|
|
is a personal license, make sure to follow the activation
|
|
|
|
steps and set the UNITY_LICENSE GitHub secret or enter a Unity
|
|
|
|
serial number inside the UNITY_SERIAL GitHub secret.`);
|
|
|
|
}
|
|
|
|
unitySerial = this.getSerialFromLicenseFile(process.env.UNITY_LICENSE);
|
|
|
|
} else {
|
|
|
|
unitySerial = process.env.UNITY_SERIAL!;
|
|
|
|
}
|
|
|
|
core.setSecret(unitySerial);
|
2022-03-27 23:23:32 +00:00
|
|
|
// ---
|
2022-01-25 21:18:15 +00:00
|
|
|
|
2020-01-20 23:06:14 +00:00
|
|
|
return {
|
2020-12-29 05:36:31 +00:00
|
|
|
version: unityVersion,
|
2020-09-18 16:41:31 +00:00
|
|
|
customImage: Input.customImage,
|
2022-01-25 21:18:15 +00:00
|
|
|
unitySerial,
|
2020-10-22 08:20:12 +00:00
|
|
|
|
2020-08-22 15:59:08 +00:00
|
|
|
runnerTempPath: process.env.RUNNER_TEMP,
|
2020-05-21 15:44:56 +00:00
|
|
|
platform: Input.targetPlatform,
|
|
|
|
projectPath: Input.projectPath,
|
|
|
|
buildName: Input.buildName,
|
|
|
|
buildPath: `${Input.buildsPath}/${Input.targetPlatform}`,
|
|
|
|
buildFile,
|
|
|
|
buildMethod: Input.buildMethod,
|
2020-04-26 18:22:09 +00:00
|
|
|
buildVersion,
|
2020-06-24 22:02:05 +00:00
|
|
|
androidVersionCode,
|
2020-07-06 01:41:21 +00:00
|
|
|
androidKeystoreName: Input.androidKeystoreName,
|
|
|
|
androidKeystoreBase64: Input.androidKeystoreBase64,
|
|
|
|
androidKeystorePass: Input.androidKeystorePass,
|
|
|
|
androidKeyaliasName: Input.androidKeyaliasName,
|
|
|
|
androidKeyaliasPass: Input.androidKeyaliasPass,
|
2021-11-24 12:51:52 +00:00
|
|
|
androidTargetSdkVersion: Input.androidTargetSdkVersion,
|
|
|
|
androidSdkManagerParameters,
|
2020-05-21 15:44:56 +00:00
|
|
|
customParameters: Input.customParameters,
|
2021-05-28 21:51:10 +00:00
|
|
|
sshAgent: Input.sshAgent,
|
2022-02-01 02:31:20 +00:00
|
|
|
gitPrivateToken: await Input.gitPrivateToken(),
|
2021-05-01 23:23:15 +00:00
|
|
|
chownFilesTo: Input.chownFilesTo,
|
2022-02-01 02:31:20 +00:00
|
|
|
cloudRunnerCluster: Input.cloudRunnerCluster,
|
|
|
|
awsBaseStackName: Input.awsBaseStackName,
|
2020-08-09 19:27:47 +00:00
|
|
|
kubeConfig: Input.kubeConfig,
|
2022-02-01 02:31:20 +00:00
|
|
|
githubToken: await Input.githubToken(),
|
|
|
|
cloudRunnerMemory: Input.cloudRunnerMemory,
|
|
|
|
cloudRunnerCpu: Input.cloudRunnerCpu,
|
2020-08-09 19:27:47 +00:00
|
|
|
kubeVolumeSize: Input.kubeVolumeSize,
|
|
|
|
kubeVolume: Input.kubeVolume,
|
2022-02-01 02:31:20 +00:00
|
|
|
postBuildSteps: Input.postBuildSteps,
|
|
|
|
preBuildSteps: Input.preBuildSteps,
|
|
|
|
customJob: Input.customJob,
|
|
|
|
runNumber: Input.runNumber,
|
|
|
|
branch: await Input.branch(),
|
|
|
|
githubRepo: await Input.githubRepo(),
|
|
|
|
remoteBuildCluster: Input.cloudRunnerCluster,
|
|
|
|
awsStackName: Input.awsBaseStackName,
|
|
|
|
gitSha: Input.gitSha,
|
|
|
|
logId: customAlphabet(CloudRunnerConstants.alphabet, 9)(),
|
|
|
|
buildGuid: CloudRunnerNamespace.generateBuildName(Input.runNumber, Input.targetPlatform),
|
2020-01-20 23:06:14 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-07-06 01:41:21 +00:00
|
|
|
static parseBuildFile(filename, platform, androidAppBundle) {
|
2020-01-20 23:06:14 +00:00
|
|
|
if (Platform.isWindows(platform)) {
|
|
|
|
return `${filename}.exe`;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Platform.isAndroid(platform)) {
|
2020-07-06 01:41:21 +00:00
|
|
|
return androidAppBundle ? `${filename}.aab` : `${filename}.apk`;
|
2020-01-20 23:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|
2022-01-25 21:18:15 +00:00
|
|
|
|
|
|
|
static getSerialFromLicenseFile(license) {
|
|
|
|
const startKey = `<DeveloperData Value="`;
|
|
|
|
const endKey = `"/>`;
|
|
|
|
const startIndex = license.indexOf(startKey) + startKey.length;
|
|
|
|
if (startIndex < 0) {
|
|
|
|
throw new Error(`License File was corrupted, unable to locate serial`);
|
|
|
|
}
|
|
|
|
const endIndex = license.indexOf(endKey, startIndex);
|
|
|
|
// Slice off the first 4 characters as they are garbage values
|
|
|
|
return Buffer.from(license.slice(startIndex, endIndex), 'base64').toString('binary').slice(4);
|
|
|
|
}
|
2020-01-20 23:06:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default BuildParameters;
|