Prebuilt steps

pull/437/head
Frostebite 2022-10-13 18:54:25 +01:00
parent 1e2679d2d6
commit 4c4e25f21a
19 changed files with 461 additions and 178 deletions

298
dist/index.js vendored
View File

@ -284,7 +284,7 @@ class BuildParameters {
runNumber: input_1.default.runNumber, runNumber: input_1.default.runNumber,
branch: input_1.default.branch.replace('/head', '') || (yield git_repo_1.GitRepoReader.GetBranch()), branch: input_1.default.branch.replace('/head', '') || (yield git_repo_1.GitRepoReader.GetBranch()),
cloudRunnerBranch: cloud_runner_options_1.default.cloudRunnerBranch.split('/').reverse()[0], cloudRunnerBranch: cloud_runner_options_1.default.cloudRunnerBranch.split('/').reverse()[0],
cloudRunnerIntegrationTests: cloud_runner_options_1.default.cloudRunnerTests, cloudRunnerDebug: cloud_runner_options_1.default.cloudRunnerDebug,
githubRepo: input_1.default.githubRepo || (yield git_repo_1.GitRepoReader.GetRemote()) || 'game-ci/unity-builder', githubRepo: input_1.default.githubRepo || (yield git_repo_1.GitRepoReader.GetRemote()) || 'game-ci/unity-builder',
isCliMode: cli_1.Cli.isCliMode, isCliMode: cli_1.Cli.isCliMode,
awsStackName: cloud_runner_options_1.default.awsBaseStackName, awsStackName: cloud_runner_options_1.default.awsBaseStackName,
@ -794,6 +794,9 @@ const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(31011)
const github_1 = __importDefault(__nccwpck_require__(83654)); const github_1 = __importDefault(__nccwpck_require__(83654));
const core = __nccwpck_require__(42186); const core = __nccwpck_require__(42186);
class CloudRunnerOptions { class CloudRunnerOptions {
// ### ### ###
// Input Handling
// ### ### ###
static getInput(query) { static getInput(query) {
if (github_1.default.githubInputEnabled) { if (github_1.default.githubInputEnabled) {
const coreInput = core.getInput(query); const coreInput = core.getInput(query);
@ -817,9 +820,25 @@ class CloudRunnerOptions {
} }
return; return;
} }
static ToEnvVarFormat(input) {
if (input.toUpperCase() === input) {
return input;
}
return input
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
.replace(/ /g, '_');
}
// ### ### ###
// Provider parameters
// ### ### ###
static get region() { static get region() {
return CloudRunnerOptions.getInput('region') || 'eu-west-2'; return CloudRunnerOptions.getInput('region') || 'eu-west-2';
} }
// ### ### ###
// Git syncronization parameters
// ### ### ###
static get githubRepo() { static get githubRepo() {
return CloudRunnerOptions.getInput('GITHUB_REPOSITORY') || CloudRunnerOptions.getInput('GITHUB_REPO') || undefined; return CloudRunnerOptions.getInput('GITHUB_REPOSITORY') || CloudRunnerOptions.getInput('GITHUB_REPO') || undefined;
} }
@ -834,6 +853,17 @@ class CloudRunnerOptions {
return ''; return '';
} }
} }
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
// ### ### ###
static get cloudRunnerBuilderPlatform() { static get cloudRunnerBuilderPlatform() {
const input = CloudRunnerOptions.getInput('cloudRunnerBuilderPlatform'); const input = CloudRunnerOptions.getInput('cloudRunnerBuilderPlatform');
if (input) { if (input) {
@ -844,51 +874,9 @@ class CloudRunnerOptions {
} }
return; return;
} }
static get gitSha() {
if (CloudRunnerOptions.getInput(`GITHUB_SHA`)) {
return CloudRunnerOptions.getInput(`GITHUB_SHA`);
}
else if (CloudRunnerOptions.getInput(`GitSHA`)) {
return CloudRunnerOptions.getInput(`GitSHA`);
}
}
static get customStepFiles() {
return CloudRunnerOptions.getInput('customStepFiles') || '';
}
static get customHookFiles() {
return CloudRunnerOptions.getInput('customHookFiles') || '';
}
static get customJob() {
return CloudRunnerOptions.getInput('customJob') || '';
}
static customJobHooks() {
return CloudRunnerOptions.getInput('customJobHooks') || '';
}
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 || '';
}
static get cloudRunnerBranch() { static get cloudRunnerBranch() {
return CloudRunnerOptions.getInput('cloudRunnerBranch') || 'cloud-runner-develop'; return CloudRunnerOptions.getInput('cloudRunnerBranch') || 'cloud-runner-develop';
} }
static get postBuildSteps() {
return CloudRunnerOptions.getInput('postBuildSteps') || '';
}
static get preBuildSteps() {
return CloudRunnerOptions.getInput('preBuildSteps') || '';
}
static get awsBaseStackName() {
return CloudRunnerOptions.getInput('awsBaseStackName') || 'game-ci';
}
static get cloudRunnerCluster() { static get cloudRunnerCluster() {
if (cli_1.Cli.isCliMode) { if (cli_1.Cli.isCliMode) {
return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'aws'; return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'aws';
@ -901,6 +889,57 @@ class CloudRunnerOptions {
static get cloudRunnerMemory() { static get cloudRunnerMemory() {
return CloudRunnerOptions.getInput('cloudRunnerMemory'); return CloudRunnerOptions.getInput('cloudRunnerMemory');
} }
static get customJob() {
return CloudRunnerOptions.getInput('customJob') || '';
}
// ### ### ###
// Custom commands from files parameters
// ### ### ###
static get customStepFiles() {
var _a;
return ((_a = CloudRunnerOptions.getInput('customStepFiles')) === null || _a === void 0 ? void 0 : _a.split(`,`)) || [];
}
static get customHookFiles() {
var _a;
return ((_a = CloudRunnerOptions.getInput('customHookFiles')) === null || _a === void 0 ? void 0 : _a.split(`,`)) || [];
}
// ### ### ###
// Custom commands from yaml parameters
// ### ### ###
static customJobHooks() {
return CloudRunnerOptions.getInput('customJobHooks') || '';
}
static get postBuildSteps() {
return CloudRunnerOptions.getInput('postBuildSteps') || '';
}
static get preBuildSteps() {
return CloudRunnerOptions.getInput('preBuildSteps') || '';
}
// ### ### ###
// Input override handling
// ### ### ###
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 || '';
}
// ### ### ###
// Aws
// ### ### ###
static get awsBaseStackName() {
return CloudRunnerOptions.getInput('awsBaseStackName') || 'game-ci';
}
// ### ### ###
// K8s
// ### ### ###
static get kubeConfig() { static get kubeConfig() {
return CloudRunnerOptions.getInput('kubeConfig') || ''; return CloudRunnerOptions.getInput('kubeConfig') || '';
} }
@ -913,37 +952,36 @@ class CloudRunnerOptions {
static get kubeStorageClass() { static get kubeStorageClass() {
return CloudRunnerOptions.getInput('kubeStorageClass') || ''; return CloudRunnerOptions.getInput('kubeStorageClass') || '';
} }
// ### ### ###
// Caching
// ### ### ###
static get cacheKey() { static get cacheKey() {
return CloudRunnerOptions.getInput('cacheKey') || CloudRunnerOptions.branch; return CloudRunnerOptions.getInput('cacheKey') || CloudRunnerOptions.branch;
} }
static get cloudRunnerTests() { // ### ### ###
return CloudRunnerOptions.getInput(`cloudRunnerTests`) || false; // Utility Parameters
// ### ### ###
static get cloudRunnerDebug() {
return CloudRunnerOptions.getInput(`cloudRunnerTests`) || CloudRunnerOptions.getInput(`cloudRunnerDebug`) || false;
} }
static get watchCloudRunnerToEnd() { static get watchCloudRunnerToEnd() {
const input = CloudRunnerOptions.getInput(`watchToEnd`); const input = CloudRunnerOptions.getInput(`watchToEnd`);
return !input || input === 'true'; return !input || input === 'true';
} }
static get retainWorkspaces() {
return CloudRunnerOptions.getInput(`retainWorkspaces`) || false;
}
static get retainWorkspacesMax() {
return Number(CloudRunnerOptions.getInput(`retainWorkspacesMax`)) || 5;
}
static get useSharedLargePackages() { static get useSharedLargePackages() {
return CloudRunnerOptions.getInput(`useSharedLargePackages`) || false; return CloudRunnerOptions.getInput(`useSharedLargePackages`) || false;
} }
static get useLZ4Compression() { static get useLZ4Compression() {
return CloudRunnerOptions.getInput(`useLZ4Compression`) || true; return CloudRunnerOptions.getInput(`useLZ4Compression`) || true;
} }
static ToEnvVarFormat(input) { // ### ### ###
if (input.toUpperCase() === input) { // Retained Workspace
return input; // ### ### ###
static get retainWorkspaces() {
return CloudRunnerOptions.getInput(`retainWorkspaces`) || false;
} }
return input static get retainWorkspacesMax() {
.replace(/([A-Z])/g, ' $1') return Number(CloudRunnerOptions.getInput(`retainWorkspacesMax`)) || 5;
.trim()
.toUpperCase()
.replace(/ /g, '_');
} }
} }
exports["default"] = CloudRunnerOptions; exports["default"] = CloudRunnerOptions;
@ -1398,7 +1436,7 @@ class AWSError {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
cloud_runner_logger_1.default.log('aws error: '); cloud_runner_logger_1.default.log('aws error: ');
core.error(JSON.stringify(error, undefined, 4)); core.error(JSON.stringify(error, undefined, 4));
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
cloud_runner_logger_1.default.log('Getting events and resources for task stack'); cloud_runner_logger_1.default.log('Getting events and resources for task stack');
const events = (yield CF.describeStackEvents({ StackName: taskDefStackName }).promise()).StackEvents; const events = (yield CF.describeStackEvents({ StackName: taskDefStackName }).promise()).StackEvents;
cloud_runner_logger_1.default.log(JSON.stringify(events, undefined, 4)); cloud_runner_logger_1.default.log(JSON.stringify(events, undefined, 4));
@ -3773,7 +3811,7 @@ tree -L 3 ${sharedFolder}
fs_1.writeFileSync(`${workspace}/${entrypointFilePath}`, fileContents, { fs_1.writeFileSync(`${workspace}/${entrypointFilePath}`, fileContents, {
flag: 'w', flag: 'w',
}); });
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
cloud_runner_logger_1.default.log(`Running local-docker: \n ${fileContents}`); cloud_runner_logger_1.default.log(`Running local-docker: \n ${fileContents}`);
} }
yield docker_1.default.run(image, Object.assign({ workspace, actionFolder }, this.buildParameters), false, `"chmod +x /github/workspace/${entrypointFilePath} && /github/workspace/${entrypointFilePath}"`, content, { yield docker_1.default.run(image, Object.assign({ workspace, actionFolder }, this.buildParameters), false, `"chmod +x /github/workspace/${entrypointFilePath} && /github/workspace/${entrypointFilePath}"`, content, {
@ -4023,12 +4061,12 @@ class Caching {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cacheFolder}`); yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${cacheFolder}`);
} }
process.chdir(path_1.default.resolve(sourceFolder, '..')); process.chdir(path_1.default.resolve(sourceFolder, '..'));
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
cloud_runner_logger_1.default.log(`Hashed cache folder ${yield lfs_hashing_1.LfsHashing.hashAllFiles(sourceFolder)} ${sourceFolder} ${path_1.default.basename(sourceFolder)}`); cloud_runner_logger_1.default.log(`Hashed cache folder ${yield lfs_hashing_1.LfsHashing.hashAllFiles(sourceFolder)} ${sourceFolder} ${path_1.default.basename(sourceFolder)}`);
} }
const contents = yield fs_1.default.promises.readdir(path_1.default.basename(sourceFolder)); const contents = yield fs_1.default.promises.readdir(path_1.default.basename(sourceFolder));
cloud_runner_logger_1.default.log(`There is ${contents.length} files/dir in the source folder ${path_1.default.basename(sourceFolder)}`); cloud_runner_logger_1.default.log(`There is ${contents.length} files/dir in the source folder ${path_1.default.basename(sourceFolder)}`);
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
// await CloudRunnerSystem.Run(`tree -L 2 ./..`); // await CloudRunnerSystem.Run(`tree -L 2 ./..`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree -L 2`); yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree -L 2`);
} }
@ -4192,7 +4230,7 @@ class RemoteClient {
} }
static sizeOfFolder(message, folder) { static sizeOfFolder(message, folder) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
cloud_runner_logger_1.default.log(`Size of ${message}`); cloud_runner_logger_1.default.log(`Size of ${message}`);
yield cloud_runner_system_1.CloudRunnerSystem.Run(`du -sh ${folder}`); yield cloud_runner_system_1.CloudRunnerSystem.Run(`du -sh ${folder}`);
} }
@ -4201,7 +4239,7 @@ class RemoteClient {
static cloneRepoWithoutLFSFiles() { static cloneRepoWithoutLFSFiles() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
process.chdir(`${cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute}`); process.chdir(`${cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute}`);
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree -L 3 ${cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute}/..`); yield cloud_runner_system_1.CloudRunnerSystem.Run(`tree -L 3 ${cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute}/..`);
} }
if (fs_1.default.existsSync(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute, `.git`))) { if (fs_1.default.existsSync(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.repoPathAbsolute, `.git`))) {
@ -4235,7 +4273,7 @@ class RemoteClient {
} }
static replaceLargePackageReferencesWithSharedReferences() { static replaceLargePackageReferencesWithSharedReferences() {
const manifest = fs_1.default.readFileSync(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.projectPathAbsolute, `Packages/manifest.json`), 'utf8'); const manifest = fs_1.default.readFileSync(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.projectPathAbsolute, `Packages/manifest.json`), 'utf8');
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
cloud_runner_logger_1.default.log(manifest); cloud_runner_logger_1.default.log(manifest);
} }
if (cloud_runner_1.default.buildParameters.useSharedLargePackages) { if (cloud_runner_1.default.buildParameters.useSharedLargePackages) {
@ -4342,20 +4380,45 @@ exports["default"] = CloudRunnerConstants;
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) { var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod }; return (mod && mod.__esModule) ? mod : { "default": mod };
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Hook = exports.CloudRunnerCustomHooks = void 0; exports.Hook = exports.CloudRunnerCustomHooks = void 0;
const __1 = __nccwpck_require__(41359);
const yaml_1 = __importDefault(__nccwpck_require__(44603)); const yaml_1 = __importDefault(__nccwpck_require__(44603));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144)); const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const remote_client_logger_1 = __nccwpck_require__(59412);
const path_1 = __importDefault(__nccwpck_require__(71017));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(96552));
const fs = __importStar(__nccwpck_require__(57147));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
class CloudRunnerCustomHooks { class CloudRunnerCustomHooks {
// TODO also accept hooks as yaml files in the repo // TODO also accept hooks as yaml files in the repo
static ApplyHooksToCommands(commands, buildParameters) { static ApplyHooksToCommands(commands, buildParameters) {
const hooks = CloudRunnerCustomHooks.getHooks(buildParameters.customJobHooks).filter((x) => x.step.includes(`all`)); const hooks = CloudRunnerCustomHooks.getHooks(buildParameters.customJobHooks).filter((x) => x.step.includes(`all`));
return `echo "---" return `echo "---"
echo "start cloud runner init" echo "start cloud runner init"
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ? '' : '#'} printenv ${cloud_runner_1.default.buildParameters.cloudRunnerDebug ? '' : '#'} printenv
echo "start of cloud runner job" echo "start of cloud runner job"
${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '} ${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
${commands} ${commands}
@ -4376,6 +4439,62 @@ class CloudRunnerCustomHooks {
} }
return output.filter((x) => x.step !== undefined && x.hook !== undefined && x.hook.length > 0); return output.filter((x) => x.step !== undefined && x.hook !== undefined && x.hook.length > 0);
} }
static GetCustomHooksFromFiles(hookLifecycle) {
const results = [];
remote_client_logger_1.RemoteClientLogger.log(`GetCustomStepFiles: ${hookLifecycle}`);
try {
const gameCiCustomStepsPath = path_1.default.join(process.cwd(), `game-ci`, `steps`);
const files = fs.readdirSync(gameCiCustomStepsPath);
for (const file of files) {
if (!cloud_runner_options_1.default.customStepFiles.includes(file)) {
continue;
}
const fileContents = fs.readFileSync(path_1.default.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerCustomHooks.ParseSteps(fileContents)[0];
if (fileContentsObject.hook.includes(hookLifecycle)) {
results.push(fileContentsObject);
}
}
}
catch (error) {
remote_client_logger_1.RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`);
}
remote_client_logger_1.RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
return results;
}
static ConvertYamlSecrets(object) {
if (object.secrets === undefined) {
object.secrets = [];
return;
}
object.secrets = object.secrets.map((x) => {
return {
ParameterKey: x.name,
EnvironmentVariable: __1.Input.ToEnvVarFormat(x.name),
ParameterValue: x.value,
};
});
}
static ParseSteps(steps) {
if (steps === '') {
return [];
}
// if (CloudRunner.buildParameters?.cloudRunnerIntegrationTests) {
cloud_runner_logger_1.default.log(`Parsing build steps: ${steps}`);
// }
const isArray = steps.replace(/\s/g, ``)[0] === `-`;
const object = isArray ? yaml_1.default.parse(steps) : [yaml_1.default.parse(steps)];
for (const step of object) {
CloudRunnerCustomHooks.ConvertYamlSecrets(step);
if (step.secrets === undefined) {
step.secrets = [];
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${steps}`);
}
return object;
}
static getSecrets(hooks) { static getSecrets(hooks) {
const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0); const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0);
// eslint-disable-next-line unicorn/no-array-reduce // eslint-disable-next-line unicorn/no-array-reduce
@ -4440,6 +4559,7 @@ const path_1 = __importDefault(__nccwpck_require__(71017));
const fs = __importStar(__nccwpck_require__(57147)); const fs = __importStar(__nccwpck_require__(57147));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855)); const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(22855));
const input_1 = __importDefault(__nccwpck_require__(91933)); const input_1 = __importDefault(__nccwpck_require__(91933));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(96552));
class CloudRunnerCustomSteps { class CloudRunnerCustomSteps {
static GetCustomStepsFromFiles(hookLifecycle) { static GetCustomStepsFromFiles(hookLifecycle) {
const results = []; const results = [];
@ -4448,6 +4568,9 @@ class CloudRunnerCustomSteps {
const gameCiCustomStepsPath = path_1.default.join(process.cwd(), `game-ci`, `steps`); const gameCiCustomStepsPath = path_1.default.join(process.cwd(), `game-ci`, `steps`);
const files = fs.readdirSync(gameCiCustomStepsPath); const files = fs.readdirSync(gameCiCustomStepsPath);
for (const file of files) { for (const file of files) {
if (!cloud_runner_options_1.default.customStepFiles.includes(file)) {
continue;
}
const fileContents = fs.readFileSync(path_1.default.join(gameCiCustomStepsPath, file), `utf8`); const fileContents = fs.readFileSync(path_1.default.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerCustomSteps.ParseSteps(fileContents)[0]; const fileContentsObject = CloudRunnerCustomSteps.ParseSteps(fileContents)[0];
if (fileContentsObject.hook === hookLifecycle) { if (fileContentsObject.hook === hookLifecycle) {
@ -4459,6 +4582,25 @@ class CloudRunnerCustomSteps {
remote_client_logger_1.RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`); remote_client_logger_1.RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`);
} }
remote_client_logger_1.RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`); remote_client_logger_1.RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
const builtInCustomSteps = [
{
name: 'aws-upload',
commands: '',
secrets: [],
image: '',
hook: '',
},
{
name: 'steam-upload',
commands: '',
secrets: [],
image: '',
hook: '',
},
].filter((x) => cloud_runner_options_1.default.customStepFiles.includes(x.name));
if (builtInCustomSteps.length > 0) {
results.push(...builtInCustomSteps);
}
return results; return results;
} }
static ConvertYamlSecrets(object) { static ConvertYamlSecrets(object) {
@ -4913,13 +5055,13 @@ class FollowLogStreamService {
core.setFailed('unity build failed'); core.setFailed('unity build failed');
core.error('BUILD FAILED!'); core.error('BUILD FAILED!');
} }
else if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests && message.includes(': Listening for Jobs')) { else if (cloud_runner_1.default.buildParameters.cloudRunnerDebug && message.includes(': Listening for Jobs')) {
core.setOutput('cloud runner stop watching', 'true'); core.setOutput('cloud runner stop watching', 'true');
shouldReadLogs = false; shouldReadLogs = false;
shouldCleanup = false; shouldCleanup = false;
core.warning('cloud runner stop watching'); core.warning('cloud runner stop watching');
} }
if (cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests) { if (cloud_runner_1.default.buildParameters.cloudRunnerDebug) {
output += `${message}\n`; output += `${message}\n`;
} }
cloud_runner_logger_1.default.log(`[${cloud_runner_statics_1.CloudRunnerStatics.logPrefix}] ${message}`); cloud_runner_logger_1.default.log(`[${cloud_runner_statics_1.CloudRunnerStatics.logPrefix}] ${message}`);
@ -5082,7 +5224,7 @@ class TaskParameterSerializer {
// if (x.name === `CUSTOM_JOB` || x.name === `GAMECI-CUSTOM_JOB`) { // if (x.name === `CUSTOM_JOB` || x.name === `GAMECI-CUSTOM_JOB`) {
// x.value = base64.encode(x.value); // x.value = base64.encode(x.value);
// } // }
if (buildParameters.cloudRunnerIntegrationTests) { if (buildParameters.cloudRunnerDebug) {
if (Number(x.name) === Number.NaN) { if (Number(x.name) === Number.NaN) {
core.info(`[ERROR] found a number in task param serializer ${JSON.stringify(x)}`); core.info(`[ERROR] found a number in task param serializer ${JSON.stringify(x)}`);
} }
@ -5312,7 +5454,7 @@ class BuildAutomationWorkflow {
const buildHooks = cloud_runner_custom_hooks_1.CloudRunnerCustomHooks.getHooks(cloud_runner_1.default.buildParameters.customJobHooks).filter((x) => x.step.includes(`build`)); const buildHooks = cloud_runner_custom_hooks_1.CloudRunnerCustomHooks.getHooks(cloud_runner_1.default.buildParameters.customJobHooks).filter((x) => x.step.includes(`build`));
const builderPath = cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.builderPathAbsolute, 'dist', `index.js`)); const builderPath = cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.builderPathAbsolute, 'dist', `index.js`));
return `apt-get update > /dev/null return `apt-get update > /dev/null
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``} : ``}
apt-get install -y tar tree npm git-lfs jq git > /dev/null apt-get install -y tar tree npm git-lfs jq git > /dev/null
@ -5332,20 +5474,20 @@ class BuildAutomationWorkflow {
const cloneBuilderCommands = `if [ -e "${cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute)}" ] && [ -e "${cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.builderPathAbsolute, `.git`))}" ]; then echo "Builder Already Exists!"; else ${commands}; fi`; const cloneBuilderCommands = `if [ -e "${cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute)}" ] && [ -e "${cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.builderPathAbsolute, `.git`))}" ]; then echo "Builder Already Exists!"; else ${commands}; fi`;
return `export GIT_DISCOVERY_ACROSS_FILESYSTEM=1 return `export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
echo "game ci cloud runner clone" echo "game ci cloud runner clone"
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``} : ``}
${retainedWorkspaceCommands} ${retainedWorkspaceCommands}
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``} : ``}
${cloneBuilderCommands} ${cloneBuilderCommands}
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``} : ``}
echo "game ci cloud runner bootstrap" echo "game ci cloud runner bootstrap"
node ${builderPath} -m remote-cli-pre-build node ${builderPath} -m remote-cli-pre-build
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``}`; : ``}`;
} }
@ -5365,11 +5507,11 @@ class BuildAutomationWorkflow {
/entrypoint.sh /entrypoint.sh
echo "game ci cloud runner push library to cache" echo "game ci cloud runner push library to cache"
chmod +x ${builderPath} chmod +x ${builderPath}
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``} : ``}
node ${builderPath} -m remote-cli-post-build node ${builderPath} -m remote-cli-post-build
${cloud_runner_1.default.buildParameters.cloudRunnerIntegrationTests ${cloud_runner_1.default.buildParameters.cloudRunnerDebug
? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${cloud_runner_folders_1.CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: ``}`; : ``}`;
} }
@ -5414,7 +5556,7 @@ class CustomWorkflow {
try { try {
cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`); cloud_runner_logger_1.default.log(`Cloud Runner is running in custom job mode`);
let output = ''; let output = '';
if ((_a = cloud_runner_1.default.buildParameters) === null || _a === void 0 ? void 0 : _a.cloudRunnerIntegrationTests) { if ((_a = cloud_runner_1.default.buildParameters) === null || _a === void 0 ? void 0 : _a.cloudRunnerDebug) {
cloud_runner_logger_1.default.log(`Custom Job Description \n${JSON.stringify(buildSteps, undefined, 4)}`); cloud_runner_logger_1.default.log(`Custom Job Description \n${JSON.stringify(buildSteps, undefined, 4)}`);
} }
for (const step of buildSteps) { for (const step of buildSteps) {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -60,7 +60,7 @@ class BuildParameters {
public logId!: string; public logId!: string;
public buildGuid!: string; public buildGuid!: string;
public cloudRunnerBranch!: string; public cloudRunnerBranch!: string;
public cloudRunnerIntegrationTests!: boolean; public cloudRunnerDebug!: boolean;
public cloudRunnerBuilderPlatform!: string | undefined; public cloudRunnerBuilderPlatform!: string | undefined;
public isCliMode!: boolean; public isCliMode!: boolean;
public retainWorkspace!: boolean; public retainWorkspace!: boolean;
@ -128,7 +128,7 @@ class BuildParameters {
runNumber: Input.runNumber, runNumber: Input.runNumber,
branch: Input.branch.replace('/head', '') || (await GitRepoReader.GetBranch()), branch: Input.branch.replace('/head', '') || (await GitRepoReader.GetBranch()),
cloudRunnerBranch: CloudRunnerOptions.cloudRunnerBranch.split('/').reverse()[0], cloudRunnerBranch: CloudRunnerOptions.cloudRunnerBranch.split('/').reverse()[0],
cloudRunnerIntegrationTests: CloudRunnerOptions.cloudRunnerTests, cloudRunnerDebug: CloudRunnerOptions.cloudRunnerDebug,
githubRepo: Input.githubRepo || (await GitRepoReader.GetRemote()) || 'game-ci/unity-builder', githubRepo: Input.githubRepo || (await GitRepoReader.GetRemote()) || 'game-ci/unity-builder',
isCliMode: Cli.isCliMode, isCliMode: Cli.isCliMode,
awsStackName: CloudRunnerOptions.awsBaseStackName, awsStackName: CloudRunnerOptions.awsBaseStackName,

View File

@ -4,6 +4,9 @@ import GitHub from '../github';
const core = require('@actions/core'); const core = require('@actions/core');
class CloudRunnerOptions { class CloudRunnerOptions {
// ### ### ###
// Input Handling
// ### ### ###
public static getInput(query) { public static getInput(query) {
if (GitHub.githubInputEnabled) { if (GitHub.githubInputEnabled) {
const coreInput = core.getInput(query); const coreInput = core.getInput(query);
@ -33,10 +36,30 @@ class CloudRunnerOptions {
return; return;
} }
public static ToEnvVarFormat(input: string) {
if (input.toUpperCase() === input) {
return input;
}
return input
.replace(/([A-Z])/g, ' $1')
.trim()
.toUpperCase()
.replace(/ /g, '_');
}
// ### ### ###
// Provider parameters
// ### ### ###
static get region(): string { static get region(): string {
return CloudRunnerOptions.getInput('region') || 'eu-west-2'; return CloudRunnerOptions.getInput('region') || 'eu-west-2';
} }
// ### ### ###
// Git syncronization parameters
// ### ### ###
static get githubRepo() { static get githubRepo() {
return CloudRunnerOptions.getInput('GITHUB_REPOSITORY') || CloudRunnerOptions.getInput('GITHUB_REPO') || undefined; return CloudRunnerOptions.getInput('GITHUB_REPOSITORY') || CloudRunnerOptions.getInput('GITHUB_REPO') || undefined;
} }
@ -49,6 +72,19 @@ class CloudRunnerOptions {
return ''; return '';
} }
} }
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
// ### ### ###
static get cloudRunnerBuilderPlatform() { static get cloudRunnerBuilderPlatform() {
const input = CloudRunnerOptions.getInput('cloudRunnerBuilderPlatform'); const input = CloudRunnerOptions.getInput('cloudRunnerBuilderPlatform');
if (input) { if (input) {
@ -61,62 +97,10 @@ class CloudRunnerOptions {
return; return;
} }
static get gitSha() {
if (CloudRunnerOptions.getInput(`GITHUB_SHA`)) {
return CloudRunnerOptions.getInput(`GITHUB_SHA`);
} else if (CloudRunnerOptions.getInput(`GitSHA`)) {
return CloudRunnerOptions.getInput(`GitSHA`);
}
}
static get customStepFiles() {
return CloudRunnerOptions.getInput('customStepFiles') || '';
}
static get customHookFiles() {
return CloudRunnerOptions.getInput('customHookFiles') || '';
}
static get customJob() {
return CloudRunnerOptions.getInput('customJob') || '';
}
static customJobHooks() {
return CloudRunnerOptions.getInput('customJobHooks') || '';
}
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 || '';
}
static get cloudRunnerBranch() { static get cloudRunnerBranch() {
return CloudRunnerOptions.getInput('cloudRunnerBranch') || 'cloud-runner-develop'; return CloudRunnerOptions.getInput('cloudRunnerBranch') || 'cloud-runner-develop';
} }
static get postBuildSteps() {
return CloudRunnerOptions.getInput('postBuildSteps') || '';
}
static get preBuildSteps() {
return CloudRunnerOptions.getInput('preBuildSteps') || '';
}
static get awsBaseStackName() {
return CloudRunnerOptions.getInput('awsBaseStackName') || 'game-ci';
}
static get cloudRunnerCluster() { static get cloudRunnerCluster() {
if (Cli.isCliMode) { if (Cli.isCliMode) {
return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'aws'; return CloudRunnerOptions.getInput('cloudRunnerCluster') || 'aws';
@ -133,6 +117,70 @@ class CloudRunnerOptions {
return CloudRunnerOptions.getInput('cloudRunnerMemory'); return CloudRunnerOptions.getInput('cloudRunnerMemory');
} }
static get customJob() {
return CloudRunnerOptions.getInput('customJob') || '';
}
// ### ### ###
// 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
// ### ### ###
static customJobHooks() {
return CloudRunnerOptions.getInput('customJobHooks') || '';
}
static get postBuildSteps() {
return CloudRunnerOptions.getInput('postBuildSteps') || '';
}
static get preBuildSteps() {
return CloudRunnerOptions.getInput('preBuildSteps') || '';
}
// ### ### ###
// Input override handling
// ### ### ###
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 || '';
}
// ### ### ###
// Aws
// ### ### ###
static get awsBaseStackName() {
return CloudRunnerOptions.getInput('awsBaseStackName') || 'game-ci';
}
// ### ### ###
// K8s
// ### ### ###
static get kubeConfig() { static get kubeConfig() {
return CloudRunnerOptions.getInput('kubeConfig') || ''; return CloudRunnerOptions.getInput('kubeConfig') || '';
} }
@ -149,12 +197,20 @@ class CloudRunnerOptions {
return CloudRunnerOptions.getInput('kubeStorageClass') || ''; return CloudRunnerOptions.getInput('kubeStorageClass') || '';
} }
// ### ### ###
// Caching
// ### ### ###
static get cacheKey(): string { static get cacheKey(): string {
return CloudRunnerOptions.getInput('cacheKey') || CloudRunnerOptions.branch; return CloudRunnerOptions.getInput('cacheKey') || CloudRunnerOptions.branch;
} }
static get cloudRunnerTests(): boolean { // ### ### ###
return CloudRunnerOptions.getInput(`cloudRunnerTests`) || false; // Utility Parameters
// ### ### ###
static get cloudRunnerDebug(): boolean {
return CloudRunnerOptions.getInput(`cloudRunnerTests`) || CloudRunnerOptions.getInput(`cloudRunnerDebug`) || false;
} }
static get watchCloudRunnerToEnd(): boolean { static get watchCloudRunnerToEnd(): boolean {
@ -163,14 +219,6 @@ class CloudRunnerOptions {
return !input || input === 'true'; return !input || input === 'true';
} }
public static get retainWorkspaces(): boolean {
return CloudRunnerOptions.getInput(`retainWorkspaces`) || false;
}
static get retainWorkspacesMax(): number {
return Number(CloudRunnerOptions.getInput(`retainWorkspacesMax`)) || 5;
}
public static get useSharedLargePackages(): boolean { public static get useSharedLargePackages(): boolean {
return CloudRunnerOptions.getInput(`useSharedLargePackages`) || false; return CloudRunnerOptions.getInput(`useSharedLargePackages`) || false;
} }
@ -179,16 +227,16 @@ class CloudRunnerOptions {
return CloudRunnerOptions.getInput(`useLZ4Compression`) || true; return CloudRunnerOptions.getInput(`useLZ4Compression`) || true;
} }
public static ToEnvVarFormat(input: string) { // ### ### ###
if (input.toUpperCase() === input) { // Retained Workspace
return input; // ### ### ###
public static get retainWorkspaces(): boolean {
return CloudRunnerOptions.getInput(`retainWorkspaces`) || false;
} }
return input static get retainWorkspacesMax(): number {
.replace(/([A-Z])/g, ' $1') return Number(CloudRunnerOptions.getInput(`retainWorkspacesMax`)) || 5;
.trim()
.toUpperCase()
.replace(/ /g, '_');
} }
} }

View File

@ -7,7 +7,7 @@ export class AWSError {
static async handleStackCreationFailure(error: any, CF: SDK.CloudFormation, taskDefStackName: string) { static async handleStackCreationFailure(error: any, CF: SDK.CloudFormation, taskDefStackName: string) {
CloudRunnerLogger.log('aws error: '); CloudRunnerLogger.log('aws error: ');
core.error(JSON.stringify(error, undefined, 4)); core.error(JSON.stringify(error, undefined, 4));
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
CloudRunnerLogger.log('Getting events and resources for task stack'); CloudRunnerLogger.log('Getting events and resources for task stack');
const events = (await CF.describeStackEvents({ StackName: taskDefStackName }).promise()).StackEvents; const events = (await CF.describeStackEvents({ StackName: taskDefStackName }).promise()).StackEvents;
CloudRunnerLogger.log(JSON.stringify(events, undefined, 4)); CloudRunnerLogger.log(JSON.stringify(events, undefined, 4));

View File

@ -104,7 +104,7 @@ tree -L 3 ${sharedFolder}
flag: 'w', flag: 'w',
}); });
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
CloudRunnerLogger.log(`Running local-docker: \n ${fileContents}`); CloudRunnerLogger.log(`Running local-docker: \n ${fileContents}`);
} }

View File

@ -53,7 +53,7 @@ export class Caching {
} }
process.chdir(path.resolve(sourceFolder, '..')); process.chdir(path.resolve(sourceFolder, '..'));
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
CloudRunnerLogger.log( CloudRunnerLogger.log(
`Hashed cache folder ${await LfsHashing.hashAllFiles(sourceFolder)} ${sourceFolder} ${path.basename( `Hashed cache folder ${await LfsHashing.hashAllFiles(sourceFolder)} ${sourceFolder} ${path.basename(
sourceFolder, sourceFolder,
@ -65,7 +65,7 @@ export class Caching {
`There is ${contents.length} files/dir in the source folder ${path.basename(sourceFolder)}`, `There is ${contents.length} files/dir in the source folder ${path.basename(sourceFolder)}`,
); );
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
// await CloudRunnerSystem.Run(`tree -L 2 ./..`); // await CloudRunnerSystem.Run(`tree -L 2 ./..`);
await CloudRunnerSystem.Run(`tree -L 2`); await CloudRunnerSystem.Run(`tree -L 2`);
} }

View File

@ -55,7 +55,7 @@ export class RemoteClient {
} }
private static async sizeOfFolder(message: string, folder: string) { private static async sizeOfFolder(message: string, folder: string) {
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
CloudRunnerLogger.log(`Size of ${message}`); CloudRunnerLogger.log(`Size of ${message}`);
await CloudRunnerSystem.Run(`du -sh ${folder}`); await CloudRunnerSystem.Run(`du -sh ${folder}`);
} }
@ -63,7 +63,7 @@ export class RemoteClient {
private static async cloneRepoWithoutLFSFiles() { private static async cloneRepoWithoutLFSFiles() {
process.chdir(`${CloudRunnerFolders.repoPathAbsolute}`); process.chdir(`${CloudRunnerFolders.repoPathAbsolute}`);
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
await CloudRunnerSystem.Run(`tree -L 3 ${CloudRunnerFolders.repoPathAbsolute}/..`); await CloudRunnerSystem.Run(`tree -L 3 ${CloudRunnerFolders.repoPathAbsolute}/..`);
} }
@ -108,7 +108,7 @@ export class RemoteClient {
path.join(CloudRunnerFolders.projectPathAbsolute, `Packages/manifest.json`), path.join(CloudRunnerFolders.projectPathAbsolute, `Packages/manifest.json`),
'utf8', 'utf8',
); );
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
CloudRunnerLogger.log(manifest); CloudRunnerLogger.log(manifest);
} }
if (CloudRunner.buildParameters.useSharedLargePackages) { if (CloudRunner.buildParameters.useSharedLargePackages) {

View File

@ -1,7 +1,12 @@
import { BuildParameters } from '../..'; import { BuildParameters, Input } from '../..';
import YAML from 'yaml'; import YAML from 'yaml';
import CloudRunnerSecret from './cloud-runner-secret'; import CloudRunnerSecret from './cloud-runner-secret';
import CloudRunner from '../cloud-runner'; import CloudRunner from '../cloud-runner';
import { RemoteClientLogger } from '../remote-client/remote-client-logger';
import path from 'path';
import CloudRunnerOptions from '../cloud-runner-options';
import * as fs from 'fs';
import CloudRunnerLogger from './cloud-runner-logger';
export class CloudRunnerCustomHooks { export class CloudRunnerCustomHooks {
// TODO also accept hooks as yaml files in the repo // TODO also accept hooks as yaml files in the repo
@ -10,7 +15,7 @@ export class CloudRunnerCustomHooks {
return `echo "---" return `echo "---"
echo "start cloud runner init" echo "start cloud runner init"
${CloudRunner.buildParameters.cloudRunnerIntegrationTests ? '' : '#'} printenv ${CloudRunner.buildParameters.cloudRunnerDebug ? '' : '#'} printenv
echo "start of cloud runner job" echo "start of cloud runner job"
${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '} ${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
${commands} ${commands}
@ -33,6 +38,70 @@ export class CloudRunnerCustomHooks {
return output.filter((x) => x.step !== undefined && x.hook !== undefined && x.hook.length > 0); return output.filter((x) => x.step !== undefined && x.hook !== undefined && x.hook.length > 0);
} }
static GetCustomHooksFromFiles(hookLifecycle: string): Hook[] {
const results: Hook[] = [];
RemoteClientLogger.log(`GetCustomStepFiles: ${hookLifecycle}`);
try {
const gameCiCustomStepsPath = path.join(process.cwd(), `game-ci`, `steps`);
const files = fs.readdirSync(gameCiCustomStepsPath);
for (const file of files) {
if (!CloudRunnerOptions.customStepFiles.includes(file)) {
continue;
}
const fileContents = fs.readFileSync(path.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerCustomHooks.ParseSteps(fileContents)[0];
if (fileContentsObject.hook.includes(hookLifecycle)) {
results.push(fileContentsObject);
}
}
} catch (error) {
RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`);
}
RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
return results;
}
private static ConvertYamlSecrets(object) {
if (object.secrets === undefined) {
object.secrets = [];
return;
}
object.secrets = object.secrets.map((x) => {
return {
ParameterKey: x.name,
EnvironmentVariable: Input.ToEnvVarFormat(x.name),
ParameterValue: x.value,
};
});
}
public static ParseSteps(steps: string): Hook[] {
if (steps === '') {
return [];
}
// if (CloudRunner.buildParameters?.cloudRunnerIntegrationTests) {
CloudRunnerLogger.log(`Parsing build steps: ${steps}`);
// }
const isArray = steps.replace(/\s/g, ``)[0] === `-`;
const object: Hook[] = isArray ? YAML.parse(steps) : [YAML.parse(steps)];
for (const step of object) {
CloudRunnerCustomHooks.ConvertYamlSecrets(step);
if (step.secrets === undefined) {
step.secrets = [];
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${steps}`);
}
return object;
}
public static getSecrets(hooks) { public static getSecrets(hooks) {
const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0); const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0);

View File

@ -8,6 +8,7 @@ import path from 'path';
import * as fs from 'fs'; import * as fs from 'fs';
import CloudRunnerLogger from './cloud-runner-logger'; import CloudRunnerLogger from './cloud-runner-logger';
import Input from '../../input'; import Input from '../../input';
import CloudRunnerOptions from '../cloud-runner-options';
export class CloudRunnerCustomSteps { export class CloudRunnerCustomSteps {
static GetCustomStepsFromFiles(hookLifecycle: string): CustomStep[] { static GetCustomStepsFromFiles(hookLifecycle: string): CustomStep[] {
@ -17,6 +18,9 @@ export class CloudRunnerCustomSteps {
const gameCiCustomStepsPath = path.join(process.cwd(), `game-ci`, `steps`); const gameCiCustomStepsPath = path.join(process.cwd(), `game-ci`, `steps`);
const files = fs.readdirSync(gameCiCustomStepsPath); const files = fs.readdirSync(gameCiCustomStepsPath);
for (const file of files) { for (const file of files) {
if (!CloudRunnerOptions.customStepFiles.includes(file)) {
continue;
}
const fileContents = fs.readFileSync(path.join(gameCiCustomStepsPath, file), `utf8`); const fileContents = fs.readFileSync(path.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerCustomSteps.ParseSteps(fileContents)[0]; const fileContentsObject = CloudRunnerCustomSteps.ParseSteps(fileContents)[0];
if (fileContentsObject.hook === hookLifecycle) { if (fileContentsObject.hook === hookLifecycle) {
@ -28,6 +32,26 @@ export class CloudRunnerCustomSteps {
} }
RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`); RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
const builtInCustomSteps: CustomStep[] = [
{
name: 'aws-upload',
commands: '',
secrets: [],
image: '',
hook: '',
},
{
name: 'steam-upload',
commands: '',
secrets: [],
image: '',
hook: '',
},
].filter((x) => CloudRunnerOptions.customStepFiles.includes(x.name));
if (builtInCustomSteps.length > 0) {
results.push(...builtInCustomSteps);
}
return results; return results;
} }

View File

@ -17,13 +17,13 @@ export class FollowLogStreamService {
core.setOutput('build-result', 'failed'); core.setOutput('build-result', 'failed');
core.setFailed('unity build failed'); core.setFailed('unity build failed');
core.error('BUILD FAILED!'); core.error('BUILD FAILED!');
} else if (CloudRunner.buildParameters.cloudRunnerIntegrationTests && message.includes(': Listening for Jobs')) { } else if (CloudRunner.buildParameters.cloudRunnerDebug && message.includes(': Listening for Jobs')) {
core.setOutput('cloud runner stop watching', 'true'); core.setOutput('cloud runner stop watching', 'true');
shouldReadLogs = false; shouldReadLogs = false;
shouldCleanup = false; shouldCleanup = false;
core.warning('cloud runner stop watching'); core.warning('cloud runner stop watching');
} }
if (CloudRunner.buildParameters.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters.cloudRunnerDebug) {
output += `${message}\n`; output += `${message}\n`;
} }
CloudRunnerLogger.log(`[${CloudRunnerStatics.logPrefix}] ${message}`); CloudRunnerLogger.log(`[${CloudRunnerStatics.logPrefix}] ${message}`);

View File

@ -51,7 +51,7 @@ export class TaskParameterSerializer {
// x.value = base64.encode(x.value); // x.value = base64.encode(x.value);
// } // }
if (buildParameters.cloudRunnerIntegrationTests) { if (buildParameters.cloudRunnerDebug) {
if (Number(x.name) === Number.NaN) { if (Number(x.name) === Number.NaN) {
core.info(`[ERROR] found a number in task param serializer ${JSON.stringify(x)}`); core.info(`[ERROR] found a number in task param serializer ${JSON.stringify(x)}`);
} else { } else {

View File

@ -35,7 +35,7 @@ commands: echo "test"`;
expect(stringObject2.length).toBe(1); expect(stringObject2.length).toBe(1);
expect(stringObject2[0].hook).toBe(`before`); expect(stringObject2[0].hook).toBe(`before`);
}); });
if (CloudRunnerOptions.cloudRunnerTests && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) { if (CloudRunnerOptions.cloudRunnerDebug && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) {
it('Run build once - check for pre and post custom hooks run contents', async () => { it('Run build once - check for pre and post custom hooks run contents', async () => {
const overrides = { const overrides = {
versioning: 'None', versioning: 'None',

View File

@ -18,7 +18,7 @@ async function CreateParameters(overrides) {
describe('Cloud Runner Caching', () => { describe('Cloud Runner Caching', () => {
it('Responds', () => {}); it('Responds', () => {});
setups(); setups();
if (CloudRunnerOptions.cloudRunnerTests && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) { if (CloudRunnerOptions.cloudRunnerDebug && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) {
it('Run one build it should not use cache, run subsequent build which should use cache', async () => { it('Run one build it should not use cache, run subsequent build which should use cache', async () => {
const overrides = { const overrides = {
versioning: 'None', versioning: 'None',

View File

@ -18,7 +18,7 @@ async function CreateParameters(overrides) {
describe('Cloud Runner Retain Workspace', () => { describe('Cloud Runner Retain Workspace', () => {
it('Responds', () => {}); it('Responds', () => {});
setups(); setups();
if (CloudRunnerOptions.cloudRunnerTests && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) { if (CloudRunnerOptions.cloudRunnerDebug && CloudRunnerOptions.cloudRunnerCluster !== `k8s`) {
it('Run one build it should not already be retained, run subsequent build which should use retained workspace', async () => { it('Run one build it should not already be retained, run subsequent build which should use retained workspace', async () => {
const overrides = { const overrides = {
versioning: 'None', versioning: 'None',

View File

@ -28,7 +28,7 @@ describe('Cloud Runner Sync Environments', () => {
const testSecretValue = 'testSecretValue'; const testSecretValue = 'testSecretValue';
it('Responds', () => {}); it('Responds', () => {});
if (CloudRunnerOptions.cloudRunnerTests) { if (CloudRunnerOptions.cloudRunnerDebug) {
it('All build parameters sent to cloud runner as env vars', async () => { it('All build parameters sent to cloud runner as env vars', async () => {
// Setup parameters // Setup parameters
const buildParameter = await CreateParameters({ const buildParameter = await CreateParameters({

View File

@ -18,7 +18,7 @@ async function CreateParameters(overrides) {
describe('Cloud Runner Locking', () => { describe('Cloud Runner Locking', () => {
setups(); setups();
it('Responds', () => {}); it('Responds', () => {});
if (CloudRunnerOptions.cloudRunnerTests) { if (CloudRunnerOptions.cloudRunnerDebug) {
it(`Simple Locking Flow`, async () => { it(`Simple Locking Flow`, async () => {
Cli.options.retainWorkspaces = true; Cli.options.retainWorkspaces = true;
const overrides: any = { const overrides: any = {

View File

@ -97,7 +97,7 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
return `apt-get update > /dev/null return `apt-get update > /dev/null
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
} }
@ -135,26 +135,26 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
return `export GIT_DISCOVERY_ACROSS_FILESYSTEM=1 return `export GIT_DISCOVERY_ACROSS_FILESYSTEM=1
echo "game ci cloud runner clone" echo "game ci cloud runner clone"
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
} }
${retainedWorkspaceCommands} ${retainedWorkspaceCommands}
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
} }
${cloneBuilderCommands} ${cloneBuilderCommands}
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
} }
echo "game ci cloud runner bootstrap" echo "game ci cloud runner bootstrap"
node ${builderPath} -m remote-cli-pre-build node ${builderPath} -m remote-cli-pre-build
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
}`; }`;
@ -178,13 +178,13 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
echo "game ci cloud runner push library to cache" echo "game ci cloud runner push library to cache"
chmod +x ${builderPath} chmod +x ${builderPath}
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
} }
node ${builderPath} -m remote-cli-post-build node ${builderPath} -m remote-cli-post-build
${ ${
CloudRunner.buildParameters.cloudRunnerIntegrationTests CloudRunner.buildParameters.cloudRunnerDebug
? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}` ? `tree -L 2 ${CloudRunnerFolders.uniqueCloudRunnerJobFolderAbsolute}`
: `` : ``
}`; }`;

View File

@ -26,7 +26,7 @@ export class CustomWorkflow {
try { try {
CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`); CloudRunnerLogger.log(`Cloud Runner is running in custom job mode`);
let output = ''; let output = '';
if (CloudRunner.buildParameters?.cloudRunnerIntegrationTests) { if (CloudRunner.buildParameters?.cloudRunnerDebug) {
CloudRunnerLogger.log(`Custom Job Description \n${JSON.stringify(buildSteps, undefined, 4)}`); CloudRunnerLogger.log(`Custom Job Description \n${JSON.stringify(buildSteps, undefined, 4)}`);
} }
for (const step of buildSteps) { for (const step of buildSteps) {