unity-builder/src/model/cloud-runner/cloud-runner-options.ts

266 lines
6.8 KiB
TypeScript
Raw Normal View History

2022-09-16 18:48:40 +00:00
import { Cli } from '../cli/cli';
import CloudRunnerQueryOverride from './services/cloud-runner-query-override';
import GitHub from '../github';
const core = require('@actions/core');
class CloudRunnerOptions {
2022-10-13 17:54:25 +00:00
// ### ### ###
// Input Handling
// ### ### ###
2022-09-16 18:48:40 +00:00
public static getInput(query) {
if (GitHub.githubInputEnabled) {
const coreInput = core.getInput(query);
if (coreInput && coreInput !== '') {
return coreInput;
}
}
const alternativeQuery = CloudRunnerOptions.ToEnvVarFormat(query);
// Query input sources
if (Cli.query(query, alternativeQuery)) {
return Cli.query(query, alternativeQuery);
}
if (CloudRunnerQueryOverride.query(query, alternativeQuery)) {
return CloudRunnerQueryOverride.query(query, alternativeQuery);
}
if (process.env[query] !== undefined) {
return process.env[query];
}
if (alternativeQuery !== query && process.env[alternativeQuery] !== undefined) {
return process.env[alternativeQuery];
}
return;
}
2022-10-13 17:54:25 +00:00
public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) {
return input;
}
return input
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
.replace(/ /g, '_');
}
// ### ### ###
// Provider parameters
// ### ### ###
2022-09-16 18:48:40 +00:00
static get region(): string {
return CloudRunnerOptions.getInput('region') || 'eu-west-2';
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Git syncronization parameters
// ### ### ###
2022-09-16 18:48:40 +00:00
static get githubRepo() {
return CloudRunnerOptions.getInput('GITHUB_REPOSITORY') || CloudRunnerOptions.getInput('GITHUB_REPO') || undefined;
}
static get branch() {
if (CloudRunnerOptions.getInput(`GITHUB_REF`)) {
return CloudRunnerOptions.getInput(`GITHUB_REF`).replace('refs/', '').replace(`head/`, '').replace(`heads/`, '');
} else if (CloudRunnerOptions.getInput('branch')) {
return CloudRunnerOptions.getInput('branch');
} else {
return '';
}
}
2022-10-13 17:54:25 +00:00
static get gitSha() {
if (CloudRunnerOptions.getInput(`GITHUB_SHA`)) {
return CloudRunnerOptions.getInput(`GITHUB_SHA`);
} else if (CloudRunnerOptions.getInput(`GitSHA`)) {
return CloudRunnerOptions.getInput(`GitSHA`);
}
}
// ### ### ###
// Cloud Runner parameters
// ### ### ###
2022-09-16 18:48:40 +00:00
static get cloudRunnerBuilderPlatform() {
const input = CloudRunnerOptions.getInput('cloudRunnerBuilderPlatform');
if (input) {
return input;
}
if (CloudRunnerOptions.cloudRunnerCluster !== 'local') {
return 'linux';
}
return;
}
2022-10-13 17:54:25 +00:00
static get cloudRunnerBranch() {
return CloudRunnerOptions.getInput('cloudRunnerBranch') || 'cloud-runner-develop';
}
static get cloudRunnerCluster() {
if (Cli.isCliMode) {
return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'aws';
2022-09-16 18:48:40 +00:00
}
2022-10-13 17:54:25 +00:00
return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'local';
2022-09-16 18:48:40 +00:00
}
2022-10-13 17:54:25 +00:00
static get cloudRunnerCpu() {
return CloudRunnerOptions.getInput('cloudRunnerCpu');
}
2022-10-13 17:54:25 +00:00
static get cloudRunnerMemory() {
return CloudRunnerOptions.getInput('cloudRunnerMemory');
}
2022-09-16 18:48:40 +00:00
static get customJob() {
return CloudRunnerOptions.getInput('customJob') || '';
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Custom commands from files parameters
// ### ### ###
static get customStepFiles() {
return CloudRunnerOptions.getInput('customStepFiles')?.split(`,`) || [];
}
static get customHookFiles() {
return CloudRunnerOptions.getInput('customHookFiles')?.split(`,`) || [];
}
// ### ### ###
// Custom commands from yaml parameters
// ### ### ###
2022-09-16 18:48:40 +00:00
static customJobHooks() {
return CloudRunnerOptions.getInput('customJobHooks') || '';
}
2022-10-13 17:54:25 +00:00
static get postBuildSteps() {
return CloudRunnerOptions.getInput('postBuildSteps') || '';
}
static get preBuildSteps() {
return CloudRunnerOptions.getInput('preBuildSteps') || '';
}
// ### ### ###
// Input override handling
// ### ### ###
2022-09-16 18:48:40 +00:00
static readInputFromOverrideList() {
return CloudRunnerOptions.getInput('readInputFromOverrideList') || '';
}
static readInputOverrideCommand() {
const value = CloudRunnerOptions.getInput('readInputOverrideCommand');
if (value === 'gcp-secret-manager') {
return 'gcloud secrets versions access 1 --secret="{0}"';
} else if (value === 'aws-secret-manager') {
return 'aws secretsmanager get-secret-value --secret-id {0}';
}
return value || '';
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Aws
// ### ### ###
2022-09-16 18:48:40 +00:00
static get awsBaseStackName() {
return CloudRunnerOptions.getInput('awsBaseStackName') || 'game-ci';
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// K8s
// ### ### ###
2022-09-16 18:48:40 +00:00
static get kubeConfig() {
return CloudRunnerOptions.getInput('kubeConfig') || '';
}
static get kubeVolume() {
return CloudRunnerOptions.getInput('kubeVolume') || '';
}
static get kubeVolumeSize() {
return CloudRunnerOptions.getInput('kubeVolumeSize') || '5Gi';
}
static get kubeStorageClass(): string {
return CloudRunnerOptions.getInput('kubeStorageClass') || '';
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Caching
// ### ### ###
2022-09-16 18:48:40 +00:00
static get cacheKey(): string {
return CloudRunnerOptions.getInput('cacheKey') || CloudRunnerOptions.branch;
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Utility Parameters
// ### ### ###
static get cloudRunnerDebug(): boolean {
return CloudRunnerOptions.getInput(`cloudRunnerTests`) || CloudRunnerOptions.getInput(`cloudRunnerDebug`) || false;
2022-09-16 18:48:40 +00:00
}
2022-10-14 16:24:47 +00:00
static get cloudRunnerDebugTree(): boolean {
return CloudRunnerOptions.getInput(`cloudRunnerDebugTree`) || false;
}
static get cloudRunnerDebugEnv(): boolean {
return CloudRunnerOptions.getInput(`cloudRunnerDebugEnv`) || false;
}
2022-09-16 18:48:40 +00:00
static get watchCloudRunnerToEnd(): boolean {
const input = CloudRunnerOptions.getInput(`watchToEnd`);
return !input || input === 'true';
}
Cloud Runner 1.0 (#459) * Fix: post build caching, use linux path conversion * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Log if retained workspace option is present for testing * Log if retained workspace option is present for testing * Use retained workspace :O * Use retained workspace :O * Use retained workspace :O * Use retained workspace :O * Ignore garbage creating lock actions in test for now * Lock workspace when using Get or Create Locked Workspace * Lock workspace before creating workspace file to allow for an unblockable creation sequence with guarenteed lock for the original creator * intuitive locking logs from the most important flow * test naming * consider lock folders without workspace file locked * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Skip all locking actions test as we now have two useful test flows * Skip all locking actions test as we now have two useful test flows * Skip all locking actions test as we now have two useful test flows * Copy all of data folder to docker volume to enable local-docker retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Skip main clone if game repo exists * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * transfer locked workspace to static CloudRunner field * transfer locked workspace to static CloudRunner field * transfer locked workspace to static CloudRunner field * custom hook files and test * custom hook files and test * custom hook files and test
2022-10-06 19:42:33 +00:00
public static get useSharedLargePackages(): boolean {
return CloudRunnerOptions.getInput(`useSharedLargePackages`) || false;
}
2022-10-21 17:39:47 +00:00
public static get useSharedBuilder(): boolean {
return CloudRunnerOptions.getInput(`useSharedBuilder`) || true;
}
2022-10-14 16:24:47 +00:00
public static get useLz4Compression(): boolean {
return CloudRunnerOptions.getInput(`useLz4Compression`) || true;
Cloud Runner 1.0 (#459) * Fix: post build caching, use linux path conversion * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Fix: post build caching via CLI * Log if retained workspace option is present for testing * Log if retained workspace option is present for testing * Use retained workspace :O * Use retained workspace :O * Use retained workspace :O * Use retained workspace :O * Ignore garbage creating lock actions in test for now * Lock workspace when using Get or Create Locked Workspace * Lock workspace before creating workspace file to allow for an unblockable creation sequence with guarenteed lock for the original creator * intuitive locking logs from the most important flow * test naming * consider lock folders without workspace file locked * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Use cache key to segment lock folders * Skip all locking actions test as we now have two useful test flows * Skip all locking actions test as we now have two useful test flows * Skip all locking actions test as we now have two useful test flows * Copy all of data folder to docker volume to enable local-docker retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Fix: check for retained workspace * Skip main clone if game repo exists * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * handle cloud runner git sync via sha not only branch * transfer locked workspace to static CloudRunner field * transfer locked workspace to static CloudRunner field * transfer locked workspace to static CloudRunner field * custom hook files and test * custom hook files and test * custom hook files and test
2022-10-06 19:42:33 +00:00
}
2022-10-13 17:54:25 +00:00
// ### ### ###
// Retained Workspace
// ### ### ###
2022-09-16 18:48:40 +00:00
2022-10-13 17:54:25 +00:00
public static get retainWorkspaces(): boolean {
return CloudRunnerOptions.getInput(`retainWorkspaces`) || false;
}
static get maxRetainedWorkspaces(): number {
return Number(CloudRunnerOptions.getInput(`maxRetainedWorkspaces`)) || 3;
2022-09-16 18:48:40 +00:00
}
// ### ### ###
// Garbage Collection
// ### ### ###
static get constantGarbageCollection(): boolean {
return CloudRunnerOptions.getInput(`constantGarbageCollection`) || true;
}
static get garbageCollectionMaxAge(): number {
return Number(CloudRunnerOptions.getInput(`garbageCollectionMaxAge`)) || 24;
}
2022-09-16 18:48:40 +00:00
}
export default CloudRunnerOptions;