unity-builder/src/model/input.ts

225 lines
5.7 KiB
TypeScript
Raw Normal View History

2022-02-01 02:31:20 +00:00
import fs from 'fs';
import path from 'path';
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 {
2022-02-01 02:31:20 +00:00
public static cliOptions;
public static githubInputEnabled: boolean = true;
// also enabled debug logging for cloud runner
static get cloudRunnerTests(): boolean {
return Input.getInput(`cloudRunnerTests`) || Input.getInput(`CloudRunnerTests`) || false;
}
private static getInput(query) {
const coreInput = core.getInput(query);
if (Input.githubInputEnabled && coreInput && coreInput !== '') {
return coreInput;
}
return Input.cliOptions !== undefined && Input.cliOptions[query] !== undefined
? Input.cliOptions[query]
: process.env[query] !== undefined
? process.env[query]
: process.env[Input.ToEnvVarFormat(query)]
? process.env[Input.ToEnvVarFormat(query)]
: '';
}
static get region(): string {
return Input.getInput('region') || 'eu-west-2';
}
static async githubRepo() {
return (
Input.getInput('GITHUB_REPOSITORY') ||
Input.getInput('GITHUB_REPO') ||
(await GitRepoReader.GetRemote()) ||
'game-ci/unity-builder'
);
}
static async branch() {
if (await GitRepoReader.GetBranch()) {
return await GitRepoReader.GetBranch();
} else if (Input.getInput(`GITHUB_REF`)) {
return Input.getInput(`GITHUB_REF`).replace('refs/', '').replace(`head/`, '');
} else if (Input.getInput('branch')) {
return Input.getInput('branch');
} else {
return 'main';
}
}
static get gitSha() {
if (Input.getInput(`GITHUB_SHA`)) {
return Input.getInput(`GITHUB_SHA`);
} else if (Input.getInput(`GitSHA`)) {
return Input.getInput(`GitSHA`);
} else if (GitRepoReader.GetSha()) {
return GitRepoReader.GetSha();
}
}
static get runNumber() {
return Input.getInput('GITHUB_RUN_NUMBER') || '0';
}
static get unityVersion() {
2022-02-01 02:31:20 +00:00
return Input.getInput('unityVersion') || 'auto';
}
static get customImage() {
2022-02-01 02:31:20 +00:00
return Input.getInput('customImage');
}
static get targetPlatform() {
2022-02-01 02:31:20 +00:00
return Input.getInput('targetPlatform') || Platform.default;
}
static get projectPath() {
2022-02-01 02:31:20 +00:00
const input = Input.getInput('projectPath');
const rawProjectPath = input
? input
: fs.existsSync(path.join('test-project', 'ProjectSettings', 'ProjectVersion.txt')) &&
!fs.existsSync(path.join('ProjectSettings', 'ProjectVersion.txt'))
? 'test-project'
: '.';
return rawProjectPath.replace(/\/$/, '');
}
static get buildName() {
2022-02-01 02:31:20 +00:00
return Input.getInput('buildName') || this.targetPlatform;
}
static get buildsPath() {
2022-02-01 02:31:20 +00:00
return Input.getInput('buildsPath') || 'build';
}
static get buildMethod() {
2022-02-01 02:31:20 +00:00
return Input.getInput('buildMethod') || ''; // processed in docker file
}
static get versioningStrategy() {
2022-02-01 02:31:20 +00:00
return Input.getInput('versioning') || 'Semantic';
}
static get specifiedVersion() {
2022-02-01 02:31:20 +00:00
return Input.getInput('version') || '';
}
static get androidVersionCode() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidVersionCode');
}
2020-07-06 01:41:21 +00:00
static get androidAppBundle() {
2022-02-01 02:31:20 +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() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidKeystoreName') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeystoreBase64() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidKeystoreBase64') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeystorePass() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidKeystorePass') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeyaliasName() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidKeyaliasName') || '';
2020-07-06 01:41:21 +00:00
}
static get androidKeyaliasPass() {
2022-02-01 02:31:20 +00:00
return Input.getInput('androidKeyaliasPass') || '';
2020-07-06 01:41:21 +00:00
}
static get androidTargetSdkVersion() {
return core.getInput('androidTargetSdkVersion') || '';
}
static get allowDirtyBuild() {
2022-02-01 02:31:20 +00:00
const input = Input.getInput('allowDirtyBuild') || false;
2020-08-10 14:30:06 +00:00
return input === 'true';
}
static get customParameters() {
2022-02-01 02:31:20 +00:00
return Input.getInput('customParameters') || '';
2019-12-22 14:05:15 +00:00
}
static get sshAgent() {
2022-02-01 02:31:20 +00:00
return Input.getInput('sshAgent') || '';
}
static async githubToken() {
return Input.getInput('githubToken') || (await GithubCliReader.GetGitHubAuthToken()) || '';
}
2022-02-01 02:31:20 +00:00
static async gitPrivateToken() {
return core.getInput('gitPrivateToken') || (await Input.githubToken());
}
static get chownFilesTo() {
2022-02-01 02:31:20 +00:00
return Input.getInput('chownFilesTo') || '';
}
2022-02-01 02:31:20 +00:00
static get postBuildSteps() {
return Input.getInput('postBuildSteps') || '';
}
2022-02-01 02:31:20 +00:00
static get preBuildSteps() {
return Input.getInput('preBuildSteps') || '';
}
2022-02-01 02:31:20 +00:00
static get customJob() {
return Input.getInput('customJob') || '';
}
static get cloudRunnerCluster() {
return Input.getInput('cloudRunnerCluster') || '';
}
static get awsBaseStackName() {
return Input.getInput('awsBaseStackName') || 'game-ci';
}
2022-02-01 02:31:20 +00:00
static get kubeConfig() {
return Input.getInput('kubeConfig') || '';
}
2022-02-01 02:31:20 +00:00
static get cloudRunnerMemory() {
return Input.getInput('cloudRunnerMemory') || '750M';
}
2022-02-01 02:31:20 +00:00
static get cloudRunnerCpu() {
return Input.getInput('cloudRunnerCpu') || '1.0';
}
static get kubeVolumeSize() {
2022-02-01 02:31:20 +00:00
return Input.getInput('kubeVolumeSize') || '5Gi';
}
static get kubeVolume() {
2022-02-01 02:31:20 +00:00
return Input.getInput('kubeVolume') || '';
}
public static ToEnvVarFormat(input: string) {
return input
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
.replace(/ /g, '_');
}
2019-12-22 14:05:15 +00:00
}
export default Input;