pull/310/head
Frostebite 2021-12-31 20:12:47 +00:00
parent eca0bd0778
commit 9193b8fd15
8 changed files with 104 additions and 76 deletions

95
dist/index.js vendored
View File

@ -465,9 +465,9 @@ const console_1 = __webpack_require__(57082);
const fs_1 = __importDefault(__webpack_require__(35747));
const path_1 = __importDefault(__webpack_require__(85622));
const __1 = __webpack_require__(41359);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const remote_client_logger_1 = __webpack_require__(68972);
class Caching {
static PushToCache(cacheFolder, destinationFolder, artifactName) {
return __awaiter(this, void 0, void 0, function* () {
@ -476,7 +476,7 @@ class Caching {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`zip -r "${artifactName}.zip" "${path_1.default.dirname(destinationFolder)}"`);
console_1.assert(fs_1.default.existsSync(`${artifactName}.zip`));
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`cp "${artifactName}.zip" "${path_1.default.join(cacheFolder, `${artifactName}.zip`)}"`);
cloud_runner_logger_1.default.logCli(`copied ${artifactName} to ${cacheFolder}`);
remote_client_logger_1.RemoteClientLogger.log(`copied ${artifactName} to ${cacheFolder}`);
}
catch (error) {
throw error;
@ -505,12 +505,12 @@ class Caching {
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
}
cloud_runner_logger_1.default.logCli(`cache item exists`);
remote_client_logger_1.RemoteClientLogger.log(`cache item exists`);
console_1.assert(fs_1.default.existsSync(destinationFolder));
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`unzip "${cacheSelection}" -d "${destinationFolder}/.."`);
}
else {
cloud_runner_logger_1.default.logCli(`cache item doesn't exist`);
remote_client_logger_1.RemoteClientLogger.logWarning(`cache item ${specificHashMatch} doesn't exist ${destinationFolder}`);
if (cacheSelection !== ``) {
throw new Error(`Failed to get cache item, but cache hit was found: ${cacheSelection}`);
}
@ -523,7 +523,7 @@ class Caching {
}
static handleCachePurging() {
if (process.env.purgeRemoteCaching !== undefined) {
cloud_runner_logger_1.default.logCli(`purging ${cloud_runner_state_1.CloudRunnerState.purgeRemoteCaching}`);
remote_client_logger_1.RemoteClientLogger.log(`purging ${cloud_runner_state_1.CloudRunnerState.purgeRemoteCaching}`);
fs_1.default.rmdirSync(cloud_runner_state_1.CloudRunnerState.cacheFolder, { recursive: true });
}
}
@ -564,39 +564,36 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerAgentSystem = void 0;
const child_process_1 = __webpack_require__(63129);
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const remote_client_logger_1 = __webpack_require__(68972);
class CloudRunnerAgentSystem {
static Run(command) {
return __awaiter(this, void 0, void 0, function* () {
cloud_runner_logger_1.default.logCli(`${command}`);
remote_client_logger_1.RemoteClientLogger.log(`${command}`);
return yield new Promise((promise) => {
let output = '';
const child = child_process_1.exec(command, (error, stdout, stderr) => {
if (error) {
cloud_runner_logger_1.default.logCliError(`${error.message}`);
remote_client_logger_1.RemoteClientLogger.logCliError(`${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
cloud_runner_logger_1.default.logCliDiagnostic(`${stderr.toString()}`);
remote_client_logger_1.RemoteClientLogger.logCliDiagnostic(`${stderr.toString()}`);
return;
}
const outputChunk = `${stdout}`;
output += outputChunk;
});
child.on('close', function (code) {
cloud_runner_logger_1.default.logCli(`[Exit code ${code}]`);
remote_client_logger_1.RemoteClientLogger.log(`[Exit code ${code}]`);
if (code !== 0) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
for (const element of outputLines) {
cloud_runner_logger_1.default.logCli(element);
remote_client_logger_1.RemoteClientLogger.log(element);
}
promise(output);
});
@ -623,19 +620,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClient = void 0;
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const remote_client_logger_1 = __webpack_require__(68972);
const setup_cloud_runner_repository_1 = __webpack_require__(39656);
class RemoteClient {
static Run() {
return __awaiter(this, void 0, void 0, function* () {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
cloud_runner_logger_1.default.log(`Build Params:
remote_client_logger_1.RemoteClientLogger.log(`Build Params:
${JSON.stringify(buildParameter, undefined, 4)}
`);
cloud_runner_state_1.CloudRunnerState.setup(buildParameter);
@ -702,6 +696,36 @@ class LFSHashing {
exports.LFSHashing = LFSHashing;
/***/ }),
/***/ 68972:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.RemoteClientLogger = void 0;
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
class RemoteClientLogger {
static log(message) {
cloud_runner_logger_1.default.log(`[Client] ${message}`);
}
static logCliError(message) {
cloud_runner_logger_1.default.log(`[Client][Error] ${message}`);
}
static logCliDiagnostic(message) {
cloud_runner_logger_1.default.log(`[Client][Diagnostic] ${message}`);
}
static logWarning(message) {
cloud_runner_logger_1.default.logWarning(message);
}
}
exports.RemoteClientLogger = RemoteClientLogger;
/***/ }),
/***/ 39656:
@ -723,15 +747,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.SetupCloudRunnerRepository = void 0;
const console_1 = __webpack_require__(57082);
const fs_1 = __importDefault(__webpack_require__(35747));
const cloud_runner_logger_1 = __importDefault(__webpack_require__(22855));
const cloud_runner_state_1 = __webpack_require__(70912);
const caching_1 = __webpack_require__(35010);
const lfs_hashing_1 = __webpack_require__(47011);
const cloud_runner_agent_system_1 = __webpack_require__(87685);
const path_1 = __importDefault(__webpack_require__(85622));
const __1 = __webpack_require__(41359);
const remote_client_logger_1 = __webpack_require__(68972);
class SetupCloudRunnerRepository {
static run() {
return __awaiter(this, void 0, void 0, function* () {
@ -741,12 +764,14 @@ class SetupCloudRunnerRepository {
yield SetupCloudRunnerRepository.cloneRepoWithoutLFSFiles();
SetupCloudRunnerRepository.LFS_ASSETS_HASH = yield lfs_hashing_1.LFSHashing.createLFSHashFiles();
if (__1.Input.cloudRunnerTests) {
cloud_runner_logger_1.default.logCli(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
remote_client_logger_1.RemoteClientLogger.log(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
}
yield lfs_hashing_1.LFSHashing.printLFSHashState();
cloud_runner_logger_1.default.logCli(`Library Caching`);
console_1.assert(!fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull), `!Warning!: The Unity library was included in the git repository`);
cloud_runner_logger_1.default.logCli(`LFS Caching`);
remote_client_logger_1.RemoteClientLogger.log(`Library Caching`);
if (!fs_1.default.existsSync(cloud_runner_state_1.CloudRunnerState.libraryFolderFull)) {
remote_client_logger_1.RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
}
remote_client_logger_1.RemoteClientLogger.log(`LFS Caching`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree ${path_1.default.join(cloud_runner_state_1.CloudRunnerState.lfsDirectory, '..')}`);
}
@ -774,19 +799,19 @@ class SetupCloudRunnerRepository {
static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () {
try {
cloud_runner_logger_1.default.logCli(`Initializing source repository for cloning with caching of LFS files`);
remote_client_logger_1.RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
cloud_runner_logger_1.default.logCli(`Cloning the repository being built:`);
remote_client_logger_1.RemoteClientLogger.log(`Cloning the repository being built:`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git clone ${cloud_runner_state_1.CloudRunnerState.targetBuildRepoUrl} ${cloud_runner_state_1.CloudRunnerState.repoPathFull}`);
if (__1.Input.cloudRunnerTests) {
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`ls -lh`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`tree`);
}
cloud_runner_logger_1.default.logCli(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
remote_client_logger_1.RemoteClientLogger.log(`${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git checkout ${cloud_runner_state_1.CloudRunnerState.buildParams.branch}`);
cloud_runner_logger_1.default.logCli(`Checked out ${process.env.GITHUB_SHA}`);
remote_client_logger_1.RemoteClientLogger.log(`Checked out ${process.env.GITHUB_SHA}`);
}
catch (error) {
throw error;
@ -797,7 +822,7 @@ class SetupCloudRunnerRepository {
return __awaiter(this, void 0, void 0, function* () {
process.chdir(cloud_runner_state_1.CloudRunnerState.repoPathFull);
yield cloud_runner_agent_system_1.CloudRunnerAgentSystem.Run(`git lfs pull`);
cloud_runner_logger_1.default.logCli(`pulled latest LFS files`);
remote_client_logger_1.RemoteClientLogger.log(`pulled latest LFS files`);
});
}
}
@ -2502,14 +2527,8 @@ class CloudRunnerLogger {
static log(message) {
core.info(message);
}
static logCli(message) {
CloudRunnerLogger.log(`[Client] ${message}`);
}
static logCliError(message) {
CloudRunnerLogger.log(`[Client][Error] ${message}`);
}
static logCliDiagnostic(message) {
CloudRunnerLogger.log(`[Client][Diagnostic] ${message}`);
static logWarning(message) {
core.warning(message);
}
static logLine(message) {
core.info(`${message}\n`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -2,9 +2,9 @@ import { assert } from 'console';
import fs from 'fs';
import path from 'path';
import { Input } from '../..';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
import { RemoteClientLogger } from './remote-client-logger';
export class Caching {
public static async PushToCache(cacheFolder: string, destinationFolder: string, artifactName: string) {
@ -13,7 +13,7 @@ export class Caching {
await CloudRunnerAgentSystem.Run(`zip -r "${artifactName}.zip" "${path.dirname(destinationFolder)}"`);
assert(fs.existsSync(`${artifactName}.zip`));
await CloudRunnerAgentSystem.Run(`cp "${artifactName}.zip" "${path.join(cacheFolder, `${artifactName}.zip`)}"`);
CloudRunnerLogger.logCli(`copied ${artifactName} to ${cacheFolder}`);
RemoteClientLogger.log(`copied ${artifactName} to ${cacheFolder}`);
} catch (error) {
throw error;
}
@ -45,11 +45,11 @@ export class Caching {
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${destinationFolder}`);
}
CloudRunnerLogger.logCli(`cache item exists`);
RemoteClientLogger.log(`cache item exists`);
assert(fs.existsSync(destinationFolder));
await CloudRunnerAgentSystem.Run(`unzip "${cacheSelection}" -d "${destinationFolder}/.."`);
} else {
CloudRunnerLogger.logCli(`cache item doesn't exist`);
RemoteClientLogger.logWarning(`cache item ${specificHashMatch} doesn't exist ${destinationFolder}`);
if (cacheSelection !== ``) {
throw new Error(`Failed to get cache item, but cache hit was found: ${cacheSelection}`);
}
@ -61,7 +61,7 @@ export class Caching {
public static handleCachePurging() {
if (process.env.purgeRemoteCaching !== undefined) {
CloudRunnerLogger.logCli(`purging ${CloudRunnerState.purgeRemoteCaching}`);
RemoteClientLogger.log(`purging ${CloudRunnerState.purgeRemoteCaching}`);
fs.rmdirSync(CloudRunnerState.cacheFolder, { recursive: true });
}
}

View File

@ -1,31 +1,31 @@
import { exec } from 'child_process';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { RemoteClientLogger } from './remote-client-logger';
export class CloudRunnerAgentSystem {
public static async Run(command: string) {
CloudRunnerLogger.logCli(`${command}`);
RemoteClientLogger.log(`${command}`);
return await new Promise<string>((promise) => {
let output = '';
const child = exec(command, (error, stdout, stderr) => {
if (error) {
CloudRunnerLogger.logCliError(`${error.message}`);
RemoteClientLogger.logCliError(`${error.message}`);
throw new Error(error.toString());
}
if (stderr) {
CloudRunnerLogger.logCliDiagnostic(`${stderr.toString()}`);
RemoteClientLogger.logCliDiagnostic(`${stderr.toString()}`);
return;
}
const outputChunk = `${stdout}`;
output += outputChunk;
});
child.on('close', function (code) {
CloudRunnerLogger.logCli(`[Exit code ${code}]`);
RemoteClientLogger.log(`[Exit code ${code}]`);
if (code !== 0) {
throw new Error(output);
}
const outputLines = output.split(`\n`);
for (const element of outputLines) {
CloudRunnerLogger.logCli(element);
RemoteClientLogger.log(element);
}
promise(output);
});

View File

@ -1,11 +1,11 @@
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { RemoteClientLogger } from './remote-client-logger';
import { SetupCloudRunnerRepository } from './setup-cloud-runner-repository';
export class RemoteClient {
static async Run() {
const buildParameter = JSON.parse(process.env.BUILD_PARAMETERS || '{}');
CloudRunnerLogger.log(`Build Params:
RemoteClientLogger.log(`Build Params:
${JSON.stringify(buildParameter, undefined, 4)}
`);
CloudRunnerState.setup(buildParameter);

View File

@ -0,0 +1,19 @@
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
export class RemoteClientLogger {
public static log(message: string) {
CloudRunnerLogger.log(`[Client] ${message}`);
}
public static logCliError(message: string) {
CloudRunnerLogger.log(`[Client][Error] ${message}`);
}
public static logCliDiagnostic(message: string) {
CloudRunnerLogger.log(`[Client][Diagnostic] ${message}`);
}
public static logWarning(message) {
CloudRunnerLogger.logWarning(message);
}
}

View File

@ -1,12 +1,11 @@
import { assert } from 'console';
import fs from 'fs';
import CloudRunnerLogger from '../../cloud-runner/services/cloud-runner-logger';
import { CloudRunnerState } from '../../cloud-runner/state/cloud-runner-state';
import { Caching } from './caching';
import { LFSHashing } from './lfs-hashing';
import { CloudRunnerAgentSystem } from './cloud-runner-agent-system';
import path from 'path';
import { Input } from '../..';
import { RemoteClientLogger } from './remote-client-logger';
export class SetupCloudRunnerRepository {
static LFS_ASSETS_HASH;
@ -19,15 +18,14 @@ export class SetupCloudRunnerRepository {
SetupCloudRunnerRepository.LFS_ASSETS_HASH = await LFSHashing.createLFSHashFiles();
if (Input.cloudRunnerTests) {
CloudRunnerLogger.logCli(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
RemoteClientLogger.log(SetupCloudRunnerRepository.LFS_ASSETS_HASH);
}
await LFSHashing.printLFSHashState();
CloudRunnerLogger.logCli(`Library Caching`);
assert(
!fs.existsSync(CloudRunnerState.libraryFolderFull),
`!Warning!: The Unity library was included in the git repository`,
);
CloudRunnerLogger.logCli(`LFS Caching`);
RemoteClientLogger.log(`Library Caching`);
if (!fs.existsSync(CloudRunnerState.libraryFolderFull)) {
RemoteClientLogger.logWarning(`!Warning!: The Unity library was included in the git repository`);
}
RemoteClientLogger.log(`LFS Caching`);
if (Input.cloudRunnerTests) {
await CloudRunnerAgentSystem.Run(`tree ${path.join(CloudRunnerState.lfsDirectory, '..')}`);
@ -65,10 +63,10 @@ export class SetupCloudRunnerRepository {
private static async cloneRepoWithoutLFSFiles() {
try {
CloudRunnerLogger.logCli(`Initializing source repository for cloning with caching of LFS files`);
RemoteClientLogger.log(`Initializing source repository for cloning with caching of LFS files`);
process.chdir(CloudRunnerState.repoPathFull);
await CloudRunnerAgentSystem.Run(`git config --global advice.detachedHead false`);
CloudRunnerLogger.logCli(`Cloning the repository being built:`);
RemoteClientLogger.log(`Cloning the repository being built:`);
await CloudRunnerAgentSystem.Run(`git lfs install --skip-smudge`);
await CloudRunnerAgentSystem.Run(
`git clone ${CloudRunnerState.targetBuildRepoUrl} ${CloudRunnerState.repoPathFull}`,
@ -77,9 +75,9 @@ export class SetupCloudRunnerRepository {
await CloudRunnerAgentSystem.Run(`ls -lh`);
await CloudRunnerAgentSystem.Run(`tree`);
}
CloudRunnerLogger.logCli(`${CloudRunnerState.buildParams.branch}`);
RemoteClientLogger.log(`${CloudRunnerState.buildParams.branch}`);
await CloudRunnerAgentSystem.Run(`git checkout ${CloudRunnerState.buildParams.branch}`);
CloudRunnerLogger.logCli(`Checked out ${process.env.GITHUB_SHA}`);
RemoteClientLogger.log(`Checked out ${process.env.GITHUB_SHA}`);
} catch (error) {
throw error;
}
@ -88,6 +86,6 @@ export class SetupCloudRunnerRepository {
private static async pullLatestLFS() {
process.chdir(CloudRunnerState.repoPathFull);
await CloudRunnerAgentSystem.Run(`git lfs pull`);
CloudRunnerLogger.logCli(`pulled latest LFS files`);
RemoteClientLogger.log(`pulled latest LFS files`);
}
}

View File

@ -13,16 +13,8 @@ class CloudRunnerLogger {
core.info(message);
}
public static logCli(message: string) {
CloudRunnerLogger.log(`[Client] ${message}`);
}
public static logCliError(message: string) {
CloudRunnerLogger.log(`[Client][Error] ${message}`);
}
public static logCliDiagnostic(message: string) {
CloudRunnerLogger.log(`[Client][Diagnostic] ${message}`);
public static logWarning(message: string) {
core.warning(message);
}
public static logLine(message: string) {