2021-12-27 21:12:46 +00:00
|
|
|
import path from 'path';
|
2021-12-23 18:10:05 +00:00
|
|
|
import { BuildParameters } from '../..';
|
2021-10-04 23:23:49 +00:00
|
|
|
import CloudRunnerEnvironmentVariable from '../services/cloud-runner-environment-variable';
|
2021-12-19 01:45:55 +00:00
|
|
|
import CloudRunnerNamespace from '../services/cloud-runner-namespace';
|
2021-10-04 23:23:49 +00:00
|
|
|
import { CloudRunnerProviderInterface } from '../services/cloud-runner-provider-interface';
|
|
|
|
|
import CloudRunnerSecret from '../services/cloud-runner-secret';
|
2021-12-23 18:10:05 +00:00
|
|
|
import { TaskParameterSerializer } from './task-parameter-serializer';
|
2021-10-04 22:13:26 +00:00
|
|
|
|
|
|
|
|
export class CloudRunnerState {
|
2021-12-19 01:45:55 +00:00
|
|
|
static setup(buildParameters: BuildParameters) {
|
|
|
|
|
CloudRunnerState.buildParams = buildParameters;
|
2021-12-19 21:38:59 +00:00
|
|
|
if (CloudRunnerState.buildGuid === undefined) {
|
|
|
|
|
CloudRunnerState.buildGuid = CloudRunnerNamespace.generateBuildName(
|
2021-12-19 21:41:49 +00:00
|
|
|
CloudRunnerState.runNumber,
|
2021-12-19 21:38:59 +00:00
|
|
|
buildParameters.platform,
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-12-23 18:10:05 +00:00
|
|
|
TaskParameterSerializer.setupDefaultSecrets();
|
2021-12-19 01:45:55 +00:00
|
|
|
}
|
2021-10-04 22:13:26 +00:00
|
|
|
public static CloudRunnerProviderPlatform: CloudRunnerProviderInterface;
|
|
|
|
|
public static buildParams: BuildParameters;
|
|
|
|
|
public static defaultSecrets: CloudRunnerSecret[];
|
|
|
|
|
public static buildGuid: string;
|
2021-12-19 21:38:59 +00:00
|
|
|
public static get branchName(): string {
|
|
|
|
|
return CloudRunnerState.buildParams.branch;
|
|
|
|
|
}
|
|
|
|
|
public static get buildPathFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(`/`, CloudRunnerState.buildVolumeFolder, CloudRunnerState.buildGuid);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get builderPathFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.buildPathFull, `builder`);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get steamPathFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.buildPathFull, `steam`);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get repoPathFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.buildPathFull, CloudRunnerState.repositoryFolder);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get projectPathFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.repoPathFull, CloudRunnerState.buildParams.projectPath);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get libraryFolderFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.projectPathFull, `Library`);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get cacheFolderFull(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.buildVolumeFolder, CloudRunnerState.cacheFolder, CloudRunnerState.branchName);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get lfsDirectory(): string {
|
2021-12-27 21:12:46 +00:00
|
|
|
return path.join(CloudRunnerState.repoPathFull, `.git`, `lfs`);
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
|
|
|
|
public static get purgeRemoteCaching(): boolean {
|
|
|
|
|
return process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
|
|
|
|
|
}
|
|
|
|
|
public static get unityBuilderRepoUrl(): string {
|
|
|
|
|
return `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
|
|
|
|
|
}
|
|
|
|
|
public static get targetBuildRepoUrl(): string {
|
2021-12-19 22:28:07 +00:00
|
|
|
return `https://${CloudRunnerState.buildParams.githubToken}@github.com/${CloudRunnerState.githubRepo}.git`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static get githubRepo(): string {
|
|
|
|
|
return `${CloudRunnerState.buildParams.githubRepo}`;
|
2021-12-19 21:38:59 +00:00
|
|
|
}
|
2021-10-04 22:13:26 +00:00
|
|
|
public static readonly defaultGitShaEnvironmentVariable = [
|
|
|
|
|
{
|
|
|
|
|
name: 'GITHUB_SHA',
|
|
|
|
|
value: process.env.GITHUB_SHA || '',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
public static readonly repositoryFolder = 'repo';
|
|
|
|
|
public static readonly buildVolumeFolder = 'data';
|
|
|
|
|
public static readonly cacheFolder = 'cache';
|
2021-12-19 01:45:55 +00:00
|
|
|
public static cloudRunnerBranch: string;
|
2021-10-04 22:13:26 +00:00
|
|
|
|
|
|
|
|
public static readBuildEnvironmentVariables(): CloudRunnerEnvironmentVariable[] {
|
2021-12-23 18:10:05 +00:00
|
|
|
return TaskParameterSerializer.readBuildEnvironmentVariables();
|
2021-12-20 20:21:31 +00:00
|
|
|
}
|
2021-10-04 22:13:26 +00:00
|
|
|
|
2021-12-19 21:41:49 +00:00
|
|
|
public static get runNumber() {
|
2021-12-06 20:56:40 +00:00
|
|
|
const runNumber = CloudRunnerState.buildParams.runNumber;
|
2021-10-04 22:13:26 +00:00
|
|
|
if (!runNumber || runNumber === '') {
|
|
|
|
|
throw new Error('no run number found, exiting');
|
|
|
|
|
}
|
|
|
|
|
return runNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|