unity-builder/src/model/input.ts

220 lines
5.5 KiB
TypeScript
Raw Normal View History

2021-12-29 15:15:39 +00:00
import { GitRepoReader } from './input-readers/git-repo';
import { GithubCliReader } from './input-readers/github-cli';
import Platform from './platform';
2019-12-22 14:05:15 +00:00
const core = require('@actions/core');
/**
* Input variables specified in workflows using "with" prop.
*
* Note that input is always passed as a string, even booleans.
*/
class Input {
2021-12-06 20:56:40 +00:00
public static githubEnabled = true;
public static cliOptions;
2021-12-25 20:05:17 +00:00
static get cloudRunnerTests(): boolean {
return Input.getInput(`CloudRunnerTests`) || false;
2021-12-20 19:15:27 +00:00
}
2021-12-06 20:56:40 +00:00
private static getInput(query) {
return Input.githubEnabled
? core.getInput(query)
: Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined
2021-12-06 20:56:40 +00:00
? Input.cliOptions[query]
: process.env[query] !== undefined
? process.env[query]
: process.env[
query
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
2021-12-29 16:51:04 +00:00
.replace(/ /g, '_')
] !== undefined
? process.env[
query
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
2021-12-29 16:51:04 +00:00
.replace(/ /g, '_')
]
2021-12-06 20:56:40 +00:00
: false;
}
2021-12-19 22:28:07 +00:00
static get region(): string {
2021-12-19 22:35:28 +00:00
return Input.getInput('region') || 'eu-west-2';
2021-12-19 22:28:07 +00:00
}
static get githubRepo(): string {
2021-12-29 15:15:39 +00:00
return Input.getInput('GITHUB_REPOSITORY') || GitRepoReader.GetRemote() || 'game-ci/unity-builder';
2021-12-19 22:28:07 +00:00
}
2021-12-29 18:15:23 +00:00
static async branch() {
if (Input.getInput(`REMOTE_BUILDER_CACHE`)) {
return Input.getInput(`REMOTE_BUILDER_CACHE`);
} else if (Input.getInput(`GITHUB_REF`)) {
return Input.getInput(`GITHUB_REF`)
.split('/')
2021-12-29 14:30:26 +00:00
.map((x) => {
x = x[0].toUpperCase() + x.slice(1);
return x;
})
.join('');
} else if (Input.getInput('branch')) {
return Input.getInput('branch');
2021-12-29 18:15:23 +00:00
} else if (await GitRepoReader.GetBranch()) {
return await GitRepoReader.GetBranch();
} else {
2021-12-19 22:35:28 +00:00
return 'remote-builder/unified-providers';
}
2021-12-29 15:15:39 +00:00
//
}
2021-12-25 19:17:05 +00:00
static get gitSha() {
if (Input.getInput(`GITHUB_SHA`)) {
return Input.getInput(`GITHUB_SHA`);
2021-12-29 15:15:39 +00:00
} else if (Input.getInput(`GitSHA`)) {
2021-12-25 19:17:05 +00:00
return Input.getInput(`GitSHA`);
2021-12-29 15:15:39 +00:00
} else if (GitRepoReader.GetSha()) {
return GitRepoReader.GetSha();
2021-12-25 19:17:05 +00:00
}
}
2021-12-06 20:56:40 +00:00
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
}
static get unityVersion() {
2021-12-06 20:56:40 +00:00
return Input.getInput('unityVersion') || 'auto';
}
static get customImage() {
2021-12-06 20:56:40 +00:00
return Input.getInput('customImage');
}
static get targetPlatform() {
2021-12-06 20:56:40 +00:00
return Input.getInput('targetPlatform') || Platform.default;
}
static get projectPath() {
2021-12-06 20:56:40 +00:00
const rawProjectPath = Input.getInput('projectPath') || '.';
return rawProjectPath.replace(/\/$/, '');
}
static get buildName() {
2021-12-06 20:56:40 +00:00
return Input.getInput('buildName') || this.targetPlatform;
}
static get buildsPath() {
2021-12-06 20:56:40 +00:00
return Input.getInput('buildsPath') || 'build';
}
static get buildMethod() {
return Input.getInput('buildMethod') || ''; // processed in docker file
}
static get versioningStrategy() {
2021-12-06 20:56:40 +00:00
return Input.getInput('versioning') || 'Semantic';
}
static get specifiedVersion() {
2021-12-06 20:56:40 +00:00
return Input.getInput('version') || '';
}
static get androidVersionCode() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidVersionCode');
}
2020-07-06 01:41:21 +00:00
static get androidAppBundle() {
2021-12-06 20:56:40 +00:00
const input = Input.getInput('androidAppBundle') || false;
2020-07-06 01:41:21 +00:00
2020-08-10 14:30:06 +00:00
return input === 'true';
2020-07-06 01:41:21 +00:00
}
static get androidKeystoreName() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidKeystoreName') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeystoreBase64() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidKeystoreBase64') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeystorePass() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidKeystorePass') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeyaliasName() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidKeyaliasName') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeyaliasPass() {
2021-12-06 20:56:40 +00:00
return Input.getInput('androidKeyaliasPass') || '';
2020-07-06 01:41:21 +00:00
}
static get androidTargetSdkVersion() {
return core.getInput('androidTargetSdkVersion') || '';
}
static get allowDirtyBuild() {
2021-12-06 20:56:40 +00:00
const input = Input.getInput('allowDirtyBuild') || false;
2020-08-10 14:30:06 +00:00
return input === 'true';
}
static get customParameters() {
2021-12-06 20:56:40 +00:00
return Input.getInput('customParameters') || '';
2019-12-22 14:05:15 +00:00
}
static get sshAgent() {
2021-12-06 20:56:40 +00:00
return Input.getInput('sshAgent') || '';
}
2021-12-29 18:15:23 +00:00
static async githubToken() {
return Input.getInput('githubToken') || (await GithubCliReader.GetGitHubAuthToken()) || '';
}
static async gitPrivateToken() {
return core.getInput('gitPrivateToken') || (await GithubCliReader.GetGitHubAuthToken()) || '';
}
static get chownFilesTo() {
2021-12-06 20:56:40 +00:00
return Input.getInput('chownFilesTo') || '';
}
2021-08-15 20:45:22 +00:00
static get postBuildSteps() {
2021-12-13 22:21:26 +00:00
return Input.getInput('postBuildSteps') || '';
2021-08-15 20:45:22 +00:00
}
2021-08-21 23:26:03 +00:00
static get preBuildSteps() {
2021-12-13 22:21:26 +00:00
return Input.getInput('preBuildSteps') || '';
2021-08-21 23:26:03 +00:00
}
static get customJob() {
return Input.getInput('customJobs') || '';
2021-08-21 23:26:03 +00:00
}
2021-08-17 22:13:46 +00:00
static get cloudRunnerCluster() {
2021-12-06 20:56:40 +00:00
return Input.getInput('cloudRunnerCluster') || '';
}
2021-08-13 19:59:01 +00:00
static get awsBaseStackName() {
2021-12-19 22:35:28 +00:00
return Input.getInput('awsBaseStackName') || 'game-ci-3-test';
}
static get kubeConfig() {
2021-12-06 20:56:40 +00:00
return Input.getInput('kubeConfig') || '';
}
2021-08-17 22:13:46 +00:00
static get cloudRunnerMemory() {
2021-12-06 20:56:40 +00:00
return Input.getInput('cloudRunnerMemory') || '750M';
}
2021-08-17 22:13:46 +00:00
static get cloudRunnerCpu() {
2021-12-06 20:56:40 +00:00
return Input.getInput('cloudRunnerCpu') || '1.0';
}
static get kubeVolumeSize() {
2021-12-06 20:56:40 +00:00
return Input.getInput('kubeVolumeSize') || '5Gi';
}
static get kubeVolume() {
2021-12-06 20:56:40 +00:00
return Input.getInput('kubeVolume') || '';
}
2019-12-22 14:05:15 +00:00
}
export default Input;