Further improvement of remote-cli, serialize all build params and setup on remote cli

pull/310/head
Frostebite 2021-12-19 21:38:59 +00:00
parent 08810c4d51
commit b10ad0165c
6 changed files with 155 additions and 117 deletions

174
dist/index.js vendored
View File

@ -95,16 +95,16 @@ const options = program.opts();
process.env.AWS_REGION = options.region;
// eslint-disable-next-line no-console
console.log(`Entrypoint: ${options.mode}`);
model_1.Input.githubEnabled = false;
switch (options.mode) {
case 'cli':
model_1.Input.githubEnabled = false;
runCli();
break;
case 'remote-cli':
model_1.Input.githubEnabled = false;
runRemoteCli(options);
break;
default:
model_1.Input.githubEnabled = true;
runMain();
break;
}
@ -1955,10 +1955,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClientCli = void 0;
const download_repository_1 = __webpack_require__(42996);
const cloud_runner_state_1 = __webpack_require__(70912);
const download_repository_1 = __webpack_require__(20477);
class RemoteClientCli {
static RunRemoteClient(options) {
return __awaiter(this, void 0, void 0, function* () {
const buff = Buffer.from(process.env.SERIALIZED_BUILD_PARAMS || '', 'base64');
const text = buff.toString('ascii');
// eslint-disable-next-line no-console
console.log(text);
cloud_runner_state_1.CloudRunnerState.setup(JSON.parse(text));
switch (options.remoteClientState) {
default:
yield download_repository_1.DownloadRepository.run();
@ -1970,6 +1976,57 @@ class RemoteClientCli {
exports.RemoteClientCli = RemoteClientCli;
/***/ }),
/***/ 20477:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DownloadRepository = void 0;
const { exec } = __webpack_require__(63129);
class DownloadRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
yield new Promise((promise) => {
exec(`
echo "test"
apk update -q
apk add unzip zip git-lfs jq tree -q
`, (error, stdout, stderr) => {
if (error) {
// eslint-disable-next-line no-console
console.log(`error: ${error.message}`);
promise();
return;
}
if (stderr) {
// eslint-disable-next-line no-console
console.log(`stderr: ${stderr}`);
promise();
return;
}
// eslint-disable-next-line no-console
console.log(`stdout: ${stdout}`);
promise();
});
});
});
}
}
exports.DownloadRepository = DownloadRepository;
/***/ }),
/***/ 91311:
@ -2081,11 +2138,47 @@ const cloud_runner_namespace_1 = __importDefault(__webpack_require__(63287));
class CloudRunnerState {
static setup(buildParameters) {
CloudRunnerState.buildParams = buildParameters;
if (CloudRunnerState.buildGuid === undefined) {
CloudRunnerState.buildGuid = cloud_runner_namespace_1.default.generateBuildName(CloudRunnerState.readRunNumber(), buildParameters.platform);
CloudRunnerState.setupBranchName();
CloudRunnerState.setupFolderVariables();
}
CloudRunnerState.setupDefaultSecrets();
}
static get branchName() {
return CloudRunnerState.buildParams.branch;
}
static get buildPathFull() {
return `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.buildGuid}`;
}
static get builderPathFull() {
return `${CloudRunnerState.buildPathFull}/builder`;
}
static get steamPathFull() {
return `${CloudRunnerState.buildPathFull}/steam`;
}
static get repoPathFull() {
return `${CloudRunnerState.buildPathFull}/${CloudRunnerState.repositoryFolder}`;
}
static get projectPathFull() {
return `${CloudRunnerState.repoPathFull}/${CloudRunnerState.buildParams.projectPath}`;
}
static get libraryFolderFull() {
return `${CloudRunnerState.projectPathFull}/Library`;
}
static get cacheFolderFull() {
return `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.cacheFolder}/${CloudRunnerState.branchName}`;
}
static get lfsDirectory() {
return `${CloudRunnerState.repoPathFull}/.git/lfs`;
}
static get purgeRemoteCaching() {
return process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
}
static get unityBuilderRepoUrl() {
return `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
}
static get targetBuildRepoUrl() {
return `https://${CloudRunnerState.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
}
static readBuildEnvironmentVariables() {
return [
{
@ -2141,8 +2234,8 @@ class CloudRunnerState {
value: CloudRunnerState.buildParams.androidKeyaliasName,
},
{
name: 'SERIALIZED_STATE',
value: JSON.stringify(CloudRunnerState),
name: 'SERIALIZED_BUILD_PARAMS',
value: Buffer.from(JSON.stringify(CloudRunnerState.buildParams)).toString('base64'),
},
];
}
@ -2164,22 +2257,6 @@ class CloudRunnerState {
}
return runNumber;
}
static setupFolderVariables() {
CloudRunnerState.buildPathFull = `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.buildGuid}`;
CloudRunnerState.builderPathFull = `${CloudRunnerState.buildPathFull}/builder`;
CloudRunnerState.steamPathFull = `${CloudRunnerState.buildPathFull}/steam`;
CloudRunnerState.repoPathFull = `${CloudRunnerState.buildPathFull}/${CloudRunnerState.repositoryFolder}`;
CloudRunnerState.projectPathFull = `${CloudRunnerState.repoPathFull}/${CloudRunnerState.buildParams.projectPath}`;
CloudRunnerState.libraryFolderFull = `${CloudRunnerState.projectPathFull}/Library`;
CloudRunnerState.cacheFolderFull = `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.cacheFolder}/${CloudRunnerState.branchName}`;
CloudRunnerState.lfsDirectory = `${CloudRunnerState.repoPathFull}/.git/lfs`;
CloudRunnerState.purgeRemoteCaching = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
CloudRunnerState.unityBuilderRepoUrl = `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
CloudRunnerState.targetBuildRepoUrl = `https://${CloudRunnerState.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
}
static setupBranchName() {
CloudRunnerState.branchName = CloudRunnerState.buildParams.branch;
}
static setupDefaultSecrets() {
CloudRunnerState.defaultSecrets = [
{
@ -2460,57 +2537,6 @@ class DownloadRepositoryStep {
exports.DownloadRepositoryStep = DownloadRepositoryStep;
/***/ }),
/***/ 42996:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DownloadRepository = void 0;
const { exec } = __webpack_require__(63129);
class DownloadRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
yield new Promise((promise) => {
exec(`
echo "test"
apk update -q
apk add unzip zip git-lfs jq tree -q
`, (error, stdout, stderr) => {
if (error) {
// eslint-disable-next-line no-console
console.log(`error: ${error.message}`);
promise();
return;
}
if (stderr) {
// eslint-disable-next-line no-console
console.log(`stderr: ${stderr}`);
promise();
return;
}
// eslint-disable-next-line no-console
console.log(`stdout: ${stdout}`);
promise();
});
});
});
}
}
exports.DownloadRepository = DownloadRepository;
/***/ }),
/***/ 94655:

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -59,17 +59,17 @@ process.env.AWS_REGION = options.region;
// eslint-disable-next-line no-console
console.log(`Entrypoint: ${options.mode}`);
Input.githubEnabled = false;
switch (options.mode) {
case 'cli':
Input.githubEnabled = false;
runCli();
break;
case 'remote-cli':
Input.githubEnabled = false;
runRemoteCli(options);
break;
default:
Input.githubEnabled = true;
runMain();
break;
}

View File

@ -1,7 +1,13 @@
import { DownloadRepository } from '../steps/remote-steps/download-repository';
import { CloudRunnerState } from '../state/cloud-runner-state';
import { DownloadRepository } from './remote-steps/download-repository';
export class RemoteClientCli {
static async RunRemoteClient(options) {
const buff = Buffer.from(process.env.SERIALIZED_BUILD_PARAMS || '', 'base64');
const text = buff.toString('ascii');
// eslint-disable-next-line no-console
console.log(text);
CloudRunnerState.setup(JSON.parse(text));
switch (options.remoteClientState) {
default:
await DownloadRepository.run();

View File

@ -9,30 +9,54 @@ import CloudRunnerSecret from '../services/cloud-runner-secret';
export class CloudRunnerState {
static setup(buildParameters: BuildParameters) {
CloudRunnerState.buildParams = buildParameters;
if (CloudRunnerState.buildGuid === undefined) {
CloudRunnerState.buildGuid = CloudRunnerNamespace.generateBuildName(
CloudRunnerState.readRunNumber(),
buildParameters.platform,
);
CloudRunnerState.setupBranchName();
CloudRunnerState.setupFolderVariables();
}
CloudRunnerState.setupDefaultSecrets();
}
public static CloudRunnerProviderPlatform: CloudRunnerProviderInterface;
public static buildParams: BuildParameters;
public static defaultSecrets: CloudRunnerSecret[];
public static buildGuid: string;
public static branchName: string;
public static buildPathFull: string;
public static builderPathFull: string;
public static steamPathFull: string;
public static repoPathFull: string;
public static projectPathFull: string;
public static libraryFolderFull: string;
public static cacheFolderFull: string;
public static lfsDirectory: string;
public static purgeRemoteCaching: boolean;
public static unityBuilderRepoUrl: string;
public static targetBuildRepoUrl: string;
public static get branchName(): string {
return CloudRunnerState.buildParams.branch;
}
public static get buildPathFull(): string {
return `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.buildGuid}`;
}
public static get builderPathFull(): string {
return `${CloudRunnerState.buildPathFull}/builder`;
}
public static get steamPathFull(): string {
return `${CloudRunnerState.buildPathFull}/steam`;
}
public static get repoPathFull(): string {
return `${CloudRunnerState.buildPathFull}/${CloudRunnerState.repositoryFolder}`;
}
public static get projectPathFull(): string {
return `${CloudRunnerState.repoPathFull}/${CloudRunnerState.buildParams.projectPath}`;
}
public static get libraryFolderFull(): string {
return `${CloudRunnerState.projectPathFull}/Library`;
}
public static get cacheFolderFull(): string {
return `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.cacheFolder}/${CloudRunnerState.branchName}`;
}
public static get lfsDirectory(): string {
return `${CloudRunnerState.repoPathFull}/.git/lfs`;
}
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 {
return `https://${CloudRunnerState.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
}
public static readonly defaultGitShaEnvironmentVariable = [
{
name: 'GITHUB_SHA',
@ -99,8 +123,8 @@ export class CloudRunnerState {
value: CloudRunnerState.buildParams.androidKeyaliasName,
},
{
name: 'SERIALIZED_STATE',
value: JSON.stringify(CloudRunnerState),
name: 'SERIALIZED_BUILD_PARAMS',
value: Buffer.from(JSON.stringify(CloudRunnerState.buildParams)).toString('base64'),
},
];
}
@ -127,24 +151,6 @@ export class CloudRunnerState {
return runNumber;
}
public static setupFolderVariables() {
CloudRunnerState.buildPathFull = `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.buildGuid}`;
CloudRunnerState.builderPathFull = `${CloudRunnerState.buildPathFull}/builder`;
CloudRunnerState.steamPathFull = `${CloudRunnerState.buildPathFull}/steam`;
CloudRunnerState.repoPathFull = `${CloudRunnerState.buildPathFull}/${CloudRunnerState.repositoryFolder}`;
CloudRunnerState.projectPathFull = `${CloudRunnerState.repoPathFull}/${CloudRunnerState.buildParams.projectPath}`;
CloudRunnerState.libraryFolderFull = `${CloudRunnerState.projectPathFull}/Library`;
CloudRunnerState.cacheFolderFull = `/${CloudRunnerState.buildVolumeFolder}/${CloudRunnerState.cacheFolder}/${CloudRunnerState.branchName}`;
CloudRunnerState.lfsDirectory = `${CloudRunnerState.repoPathFull}/.git/lfs`;
CloudRunnerState.purgeRemoteCaching = process.env.PURGE_REMOTE_BUILDER_CACHE !== undefined;
CloudRunnerState.unityBuilderRepoUrl = `https://${CloudRunnerState.buildParams.githubToken}@github.com/game-ci/unity-builder.git`;
CloudRunnerState.targetBuildRepoUrl = `https://${CloudRunnerState.buildParams.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git`;
}
public static setupBranchName() {
CloudRunnerState.branchName = CloudRunnerState.buildParams.branch;
}
public static setupDefaultSecrets() {
CloudRunnerState.defaultSecrets = [
{