pull/524/head
Frostebite 2023-03-26 23:00:04 +01:00
parent 06a31057bb
commit 59e821356f
13 changed files with 462 additions and 462 deletions

840
dist/index.js generated vendored
View File

@ -1804,7 +1804,7 @@ const zlib = __importStar(__nccwpck_require__(65628));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(42864));
const __1 = __nccwpck_require__(41359);
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const cloud_runner_command_hook_1 = __nccwpck_require__(38960);
const command_hook_service_1 = __nccwpck_require__(96159);
const follow_log_stream_service_1 = __nccwpck_require__(40266);
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
const github_1 = __importDefault(__nccwpck_require__(83654));
@ -1825,7 +1825,7 @@ class AWSTaskRunner {
{
name: taskDef.taskDefStackName,
environment,
command: ['-c', cloud_runner_command_hook_1.CloudRunnerCommandHooks.ApplyHooksToCommands(commands, cloud_runner_1.default.buildParameters)],
command: ['-c', command_hook_service_1.CommandHookService.ApplyHooksToCommands(commands, cloud_runner_1.default.buildParameters)],
},
],
},
@ -3118,7 +3118,7 @@ const node_fs_1 = __nccwpck_require__(87561);
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const cloud_runner_system_1 = __nccwpck_require__(4197);
const fs = __importStar(__nccwpck_require__(87561));
const cloud_runner_command_hook_1 = __nccwpck_require__(38960);
const command_hook_service_1 = __nccwpck_require__(96159);
class LocalDockerCloudRunner {
listResources() {
return new Promise((resolve) => resolve([]));
@ -3192,7 +3192,7 @@ set -e
mkdir -p /github/workspace/cloud-runner-cache
mkdir -p /data/cache
cp -a /github/workspace/cloud-runner-cache/. ${sharedFolder}
${cloud_runner_command_hook_1.CloudRunnerCommandHooks.ApplyHooksToCommands(commands, this.buildParameters)}
${command_hook_service_1.CommandHookService.ApplyHooksToCommands(commands, this.buildParameters)}
cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
`;
node_fs_1.writeFileSync(`${workspace}/${entrypointFilePath}`, fileContents, {
@ -3482,7 +3482,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const client_node_1 = __nccwpck_require__(89679);
const cloud_runner_command_hook_1 = __nccwpck_require__(38960);
const command_hook_service_1 = __nccwpck_require__(96159);
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
class KubernetesJobSpecFactory {
static getJobSpec(command, image, mountdir, workingDirectory, environment, secrets, buildGuid, buildParameters, secretName, pvcName, jobName, k8s, containerName) {
@ -3571,7 +3571,7 @@ class KubernetesJobSpecFactory {
command: ['/bin/sh'],
args: [
'-c',
`${cloud_runner_command_hook_1.CloudRunnerCommandHooks.ApplyHooksToCommands(`${command}\nsleep 2m`, cloud_runner_1.default.buildParameters)}`,
`${command_hook_service_1.CommandHookService.ApplyHooksToCommands(`${command}\nsleep 2m`, cloud_runner_1.default.buildParameters)}`,
],
workingDir: `${workingDirectory}`,
resources: {
@ -4517,410 +4517,6 @@ class RemoteClientLogger {
exports.RemoteClientLogger = RemoteClientLogger;
/***/ }),
/***/ 38960:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerCommandHooks = void 0;
const __1 = __nccwpck_require__(41359);
const yaml_1 = __importDefault(__nccwpck_require__(44603));
const remote_client_logger_1 = __nccwpck_require__(59412);
const node_path_1 = __importDefault(__nccwpck_require__(49411));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
const fs = __importStar(__nccwpck_require__(87561));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(42864));
// import CloudRunnerLogger from './cloud-runner-logger';
class CloudRunnerCommandHooks {
static ApplyHooksToCommands(commands, buildParameters) {
const hooks = CloudRunnerCommandHooks.getHooks(buildParameters.commandHooks);
cloud_runner_logger_1.default.log(`Applying hooks ${hooks.length}`);
return `echo "---"
echo "start cloud runner init"
${cloud_runner_options_1.default.cloudRunnerDebug ? `printenv` : `#`}
echo "start of cloud runner job"
${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
${commands}
${hooks.filter((x) => x.hook.includes(`after`)).map((x) => x.commands) || ' '}
echo "end of cloud runner job"
echo "---${buildParameters.logId}"`;
}
static getHooks(customCommandHooks) {
const experimentHooks = customCommandHooks;
let output = new Array();
if (experimentHooks && experimentHooks !== '') {
try {
output = yaml_1.default.parse(experimentHooks);
}
catch (error) {
throw error;
}
}
return [
...output.filter((x) => x.hook !== undefined && x.hook.length > 0),
...CloudRunnerCommandHooks.GetCustomHooksFromFiles(`before`),
...CloudRunnerCommandHooks.GetCustomHooksFromFiles(`after`),
];
}
static GetCustomHooksFromFiles(hookLifecycle) {
const results = [];
// RemoteClientLogger.log(`GetCustomHookFiles: ${hookLifecycle}`);
try {
const gameCiCustomHooksPath = node_path_1.default.join(process.cwd(), `game-ci`, `command-hooks`);
const files = fs.readdirSync(gameCiCustomHooksPath);
for (const file of files) {
if (!cloud_runner_options_1.default.commandHookFiles.includes(file.replace(`.yaml`, ``))) {
continue;
}
const fileContents = fs.readFileSync(node_path_1.default.join(gameCiCustomHooksPath, file), `utf8`);
const fileContentsObject = CloudRunnerCommandHooks.ParseHooks(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)}`);
}
// RemoteClientLogger.log(`Active Steps From Hooks: \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 ParseHooks(hooks) {
if (hooks === '') {
return [];
}
// if (CloudRunner.buildParameters?.cloudRunnerIntegrationTests) {
// CloudRunnerLogger.log(`Parsing build hooks: ${steps}`);
// }
const isArray = hooks.replace(/\s/g, ``)[0] === `-`;
const object = isArray ? yaml_1.default.parse(hooks) : [yaml_1.default.parse(hooks)];
for (const hook of object) {
CloudRunnerCommandHooks.ConvertYamlSecrets(hook);
if (hook.secrets === undefined) {
hook.secrets = [];
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${hooks}`);
}
return object;
}
static getSecrets(hooks) {
const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0);
// eslint-disable-next-line unicorn/no-array-reduce
return secrets.length > 0 ? secrets.reduce((x, y) => [...x, ...y]) : [];
}
}
exports.CloudRunnerCommandHooks = CloudRunnerCommandHooks;
/***/ }),
/***/ 18313:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CloudRunnerContainerHook = void 0;
const yaml_1 = __importDefault(__nccwpck_require__(44603));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const core = __importStar(__nccwpck_require__(42186));
const custom_workflow_1 = __nccwpck_require__(3786);
const remote_client_logger_1 = __nccwpck_require__(59412);
const node_path_1 = __importDefault(__nccwpck_require__(49411));
const node_fs_1 = __importDefault(__nccwpck_require__(87561));
const input_1 = __importDefault(__nccwpck_require__(91933));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
class CloudRunnerContainerHook {
static GetContainerHooksFromFiles(hookLifecycle) {
const results = [];
try {
const gameCiCustomStepsPath = node_path_1.default.join(process.cwd(), `game-ci`, `container-hooks`);
const files = node_fs_1.default.readdirSync(gameCiCustomStepsPath);
for (const file of files) {
if (!cloud_runner_options_1.default.containerHookFiles.includes(file.replace(`.yaml`, ``))) {
// RemoteClientLogger.log(`Skipping CustomStepFile: ${file}`);
continue;
}
const fileContents = node_fs_1.default.readFileSync(node_path_1.default.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerContainerHook.ParseContainerHooks(fileContents)[0];
if (fileContentsObject.hook === hookLifecycle) {
results.push(fileContentsObject);
}
}
}
catch (error) {
remote_client_logger_1.RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`);
}
// RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
const builtInContainerHooks = CloudRunnerContainerHook.ParseContainerHooks(`- name: aws-s3-upload-build
image: amazon/aws-cli
hook: after
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 cp /data/cache/$CACHE_KEY/build/build-${cloud_runner_1.default.buildParameters.buildGuid}.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''} s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build/build-$BUILD_GUID.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
rm /data/cache/$CACHE_KEY/build/build-${cloud_runner_1.default.buildParameters.buildGuid}.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
secrets:
- name: awsAccessKeyId
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: awsSecretAccessKey
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: awsDefaultRegion
value: ${process.env.AWS_REGION || ``}
- name: aws-s3-pull-build
image: amazon/aws-cli
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/ || true
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build || true
mkdir -p /data/cache/$CACHE_KEY/build/
aws s3 cp s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build/build-$BUILD_GUID_TARGET.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''} /data/cache/$CACHE_KEY/build/build-$BUILD_GUID_TARGET.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
secrets:
- name: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
- name: AWS_DEFAULT_REGION
- name: BUILD_GUID_TARGET
- name: steam-deploy-client
image: steamcmd/steamcmd
commands: |
apt-get update
apt-get install -y curl tar coreutils git tree > /dev/null
curl -s https://gist.githubusercontent.com/frostebite/1d56f5505b36b403b64193b7a6e54cdc/raw/fa6639ed4ef750c4268ea319d63aa80f52712ffb/deploy-client-steam.sh | bash
secrets:
- name: STEAM_USERNAME
- name: STEAM_PASSWORD
- name: STEAM_APPID
- name: STEAM_SSFN_FILE_NAME
- name: STEAM_SSFN_FILE_CONTENTS
- name: STEAM_CONFIG_VDF_1
- name: STEAM_CONFIG_VDF_2
- name: STEAM_CONFIG_VDF_3
- name: STEAM_CONFIG_VDF_4
- name: BUILD_GUID_TARGET
- name: RELEASE_BRANCH
- name: steam-deploy-project
image: steamcmd/steamcmd
commands: |
apt-get update
apt-get install -y curl tar coreutils git tree > /dev/null
curl -s https://gist.githubusercontent.com/frostebite/969da6a41002a0e901174124b643709f/raw/02403e53fb292026cba81ddcf4ff35fc1eba111d/steam-deploy-project.sh | bash
secrets:
- name: STEAM_USERNAME
- name: STEAM_PASSWORD
- name: STEAM_APPID
- name: STEAM_SSFN_FILE_NAME
- name: STEAM_SSFN_FILE_CONTENTS
- name: STEAM_CONFIG_VDF_1
- name: STEAM_CONFIG_VDF_2
- name: STEAM_CONFIG_VDF_3
- name: STEAM_CONFIG_VDF_4
- name: BUILD_GUID_2
- name: RELEASE_BRANCH
- name: aws-s3-upload-cache
image: amazon/aws-cli
hook: after
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 cp --recursive /data/cache/$CACHE_KEY/lfs s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/lfs
rm -r /data/cache/$CACHE_KEY/lfs
aws s3 cp --recursive /data/cache/$CACHE_KEY/Library s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/Library
rm -r /data/cache/$CACHE_KEY/Library
secrets:
- name: AWS_ACCESS_KEY_ID
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: AWS_SECRET_ACCESS_KEY
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: AWS_DEFAULT_REGION
value: ${process.env.AWS_REGION || ``}
- name: aws-s3-pull-cache
image: amazon/aws-cli
hook: before
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
mkdir -p /data/cache/$CACHE_KEY/Library/
mkdir -p /data/cache/$CACHE_KEY/lfs/
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/ || true
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/ || true
BUCKET1="${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/Library/"
aws s3 ls $BUCKET1 || true
OBJECT1="$(aws s3 ls $BUCKET1 | sort | tail -n 1 | awk '{print $4}' || '')"
aws s3 cp s3://$BUCKET1$OBJECT1 /data/cache/$CACHE_KEY/Library/ || true
BUCKET2="${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/lfs/"
aws s3 ls $BUCKET2 || true
OBJECT2="$(aws s3 ls $BUCKET2 | sort | tail -n 1 | awk '{print $4}' || '')"
aws s3 cp s3://$BUCKET2$OBJECT2 /data/cache/$CACHE_KEY/lfs/ || true
secrets:
- name: AWS_ACCESS_KEY_ID
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: AWS_SECRET_ACCESS_KEY
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: AWS_DEFAULT_REGION
value: ${process.env.AWS_REGION || ``}
- name: debug-cache
image: ubuntu
hook: after
commands: |
apt-get update > /dev/null
${cloud_runner_options_1.default.cloudRunnerDebug ? `apt-get install -y tree > /dev/null` : `#`}
${cloud_runner_options_1.default.cloudRunnerDebug ? `tree -L 3 /data/cache` : `#`}
secrets:
- name: awsAccessKeyId
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: awsSecretAccessKey
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: awsDefaultRegion
value: ${process.env.AWS_REGION || ``}`).filter((x) => cloud_runner_options_1.default.containerHookFiles.includes(x.name) && x.hook === hookLifecycle);
if (builtInContainerHooks.length > 0) {
results.push(...builtInContainerHooks);
}
return results;
}
static ConvertYamlSecrets(object) {
if (object.secrets === undefined) {
object.secrets = [];
return;
}
object.secrets = object.secrets.map((x) => {
return {
ParameterKey: x.name,
EnvironmentVariable: input_1.default.ToEnvVarFormat(x.name),
ParameterValue: x.value,
};
});
}
static ParseContainerHooks(steps) {
if (steps === '') {
return [];
}
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) {
CloudRunnerContainerHook.ConvertYamlSecrets(step);
if (step.secrets === undefined) {
step.secrets = [];
}
else {
for (const secret of step.secrets) {
if (secret.ParameterValue === undefined && process.env[secret.EnvironmentVariable] !== undefined) {
if (cloud_runner_1.default.buildParameters?.cloudRunnerDebug) {
// CloudRunnerLogger.log(`Injecting custom step ${step.name} from env var ${secret.ParameterKey}`);
}
secret.ParameterValue = process.env[secret.ParameterKey] || ``;
}
}
}
if (step.image === undefined) {
step.image = `ubuntu`;
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${steps}`);
}
return object;
}
static async RunPostBuildSteps(cloudRunnerStepState) {
let output = ``;
const steps = [
...CloudRunnerContainerHook.ParseContainerHooks(cloud_runner_1.default.buildParameters.postBuildContainerHooks),
...CloudRunnerContainerHook.GetContainerHooksFromFiles(`after`),
];
if (steps.length > 0) {
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.startGroup('post build steps');
output += await custom_workflow_1.CustomWorkflow.runContainerJob(steps, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.endGroup();
}
return output;
}
static async RunPreBuildSteps(cloudRunnerStepState) {
let output = ``;
const steps = [
...CloudRunnerContainerHook.ParseContainerHooks(cloud_runner_1.default.buildParameters.preBuildContainerHooks),
...CloudRunnerContainerHook.GetContainerHooksFromFiles(`before`),
];
if (steps.length > 0) {
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.startGroup('pre build steps');
output += await custom_workflow_1.CustomWorkflow.runContainerJob(steps, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.endGroup();
}
return output;
}
}
exports.CloudRunnerContainerHook = CloudRunnerContainerHook;
/***/ }),
/***/ 42864:
@ -5368,7 +4964,7 @@ const input_1 = __importDefault(__nccwpck_require__(91933));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
const cloud_runner_options_reader_1 = __importDefault(__nccwpck_require__(96879));
const cloud_runner_query_override_1 = __importDefault(__nccwpck_require__(52207));
const cloud_runner_command_hook_1 = __nccwpck_require__(38960);
const command_hook_service_1 = __nccwpck_require__(96159);
class TaskParameterSerializer {
static createCloudRunnerEnvironmentVariables(buildParameters) {
const result = this.uniqBy([
@ -5380,7 +4976,7 @@ class TaskParameterSerializer {
...TaskParameterSerializer.serializeFromObject(buildParameters),
...TaskParameterSerializer.serializeInput(),
...TaskParameterSerializer.serializeCloudRunnerOptions(),
...cloud_runner_command_hook_1.CloudRunnerCommandHooks.getSecrets(cloud_runner_command_hook_1.CloudRunnerCommandHooks.getHooks(buildParameters.commandHooks)),
...command_hook_service_1.CommandHookService.getSecrets(command_hook_service_1.CommandHookService.getHooks(buildParameters.commandHooks)),
]
.filter((x) => !TaskParameterSerializer.blockedParameterNames.has(x.name) &&
x.value !== '' &&
@ -5502,6 +5098,410 @@ TaskParameterSerializer.blockedParameterNames = new Set([
]);
/***/ }),
/***/ 96159:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CommandHookService = void 0;
const __1 = __nccwpck_require__(41359);
const yaml_1 = __importDefault(__nccwpck_require__(44603));
const remote_client_logger_1 = __nccwpck_require__(59412);
const node_path_1 = __importDefault(__nccwpck_require__(49411));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
const fs = __importStar(__nccwpck_require__(87561));
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(42864));
// import CloudRunnerLogger from './cloud-runner-logger';
class CommandHookService {
static ApplyHooksToCommands(commands, buildParameters) {
const hooks = CommandHookService.getHooks(buildParameters.commandHooks);
cloud_runner_logger_1.default.log(`Applying hooks ${hooks.length}`);
return `echo "---"
echo "start cloud runner init"
${cloud_runner_options_1.default.cloudRunnerDebug ? `printenv` : `#`}
echo "start of cloud runner job"
${hooks.filter((x) => x.hook.includes(`before`)).map((x) => x.commands) || ' '}
${commands}
${hooks.filter((x) => x.hook.includes(`after`)).map((x) => x.commands) || ' '}
echo "end of cloud runner job"
echo "---${buildParameters.logId}"`;
}
static getHooks(customCommandHooks) {
const experimentHooks = customCommandHooks;
let output = new Array();
if (experimentHooks && experimentHooks !== '') {
try {
output = yaml_1.default.parse(experimentHooks);
}
catch (error) {
throw error;
}
}
return [
...output.filter((x) => x.hook !== undefined && x.hook.length > 0),
...CommandHookService.GetCustomHooksFromFiles(`before`),
...CommandHookService.GetCustomHooksFromFiles(`after`),
];
}
static GetCustomHooksFromFiles(hookLifecycle) {
const results = [];
// RemoteClientLogger.log(`GetCustomHookFiles: ${hookLifecycle}`);
try {
const gameCiCustomHooksPath = node_path_1.default.join(process.cwd(), `game-ci`, `command-hooks`);
const files = fs.readdirSync(gameCiCustomHooksPath);
for (const file of files) {
if (!cloud_runner_options_1.default.commandHookFiles.includes(file.replace(`.yaml`, ``))) {
continue;
}
const fileContents = fs.readFileSync(node_path_1.default.join(gameCiCustomHooksPath, file), `utf8`);
const fileContentsObject = CommandHookService.ParseHooks(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)}`);
}
// RemoteClientLogger.log(`Active Steps From Hooks: \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 ParseHooks(hooks) {
if (hooks === '') {
return [];
}
// if (CloudRunner.buildParameters?.cloudRunnerIntegrationTests) {
// CloudRunnerLogger.log(`Parsing build hooks: ${steps}`);
// }
const isArray = hooks.replace(/\s/g, ``)[0] === `-`;
const object = isArray ? yaml_1.default.parse(hooks) : [yaml_1.default.parse(hooks)];
for (const hook of object) {
CommandHookService.ConvertYamlSecrets(hook);
if (hook.secrets === undefined) {
hook.secrets = [];
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${hooks}`);
}
return object;
}
static getSecrets(hooks) {
const secrets = hooks.map((x) => x.secrets).filter((x) => x !== undefined && x.length > 0);
// eslint-disable-next-line unicorn/no-array-reduce
return secrets.length > 0 ? secrets.reduce((x, y) => [...x, ...y]) : [];
}
}
exports.CommandHookService = CommandHookService;
/***/ }),
/***/ 24785:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"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) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ContainerHookService = void 0;
const yaml_1 = __importDefault(__nccwpck_require__(44603));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const core = __importStar(__nccwpck_require__(42186));
const custom_workflow_1 = __nccwpck_require__(3786);
const remote_client_logger_1 = __nccwpck_require__(59412);
const node_path_1 = __importDefault(__nccwpck_require__(49411));
const node_fs_1 = __importDefault(__nccwpck_require__(87561));
const input_1 = __importDefault(__nccwpck_require__(91933));
const cloud_runner_options_1 = __importDefault(__nccwpck_require__(66965));
class ContainerHookService {
static GetContainerHooksFromFiles(hookLifecycle) {
const results = [];
try {
const gameCiCustomStepsPath = node_path_1.default.join(process.cwd(), `game-ci`, `container-hooks`);
const files = node_fs_1.default.readdirSync(gameCiCustomStepsPath);
for (const file of files) {
if (!cloud_runner_options_1.default.containerHookFiles.includes(file.replace(`.yaml`, ``))) {
// RemoteClientLogger.log(`Skipping CustomStepFile: ${file}`);
continue;
}
const fileContents = node_fs_1.default.readFileSync(node_path_1.default.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = ContainerHookService.ParseContainerHooks(fileContents)[0];
if (fileContentsObject.hook === hookLifecycle) {
results.push(fileContentsObject);
}
}
}
catch (error) {
remote_client_logger_1.RemoteClientLogger.log(`Failed Getting: ${hookLifecycle} \n ${JSON.stringify(error, undefined, 4)}`);
}
// RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
const builtInContainerHooks = ContainerHookService.ParseContainerHooks(`- name: aws-s3-upload-build
image: amazon/aws-cli
hook: after
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 cp /data/cache/$CACHE_KEY/build/build-${cloud_runner_1.default.buildParameters.buildGuid}.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''} s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build/build-$BUILD_GUID.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
rm /data/cache/$CACHE_KEY/build/build-${cloud_runner_1.default.buildParameters.buildGuid}.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
secrets:
- name: awsAccessKeyId
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: awsSecretAccessKey
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: awsDefaultRegion
value: ${process.env.AWS_REGION || ``}
- name: aws-s3-pull-build
image: amazon/aws-cli
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/ || true
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build || true
mkdir -p /data/cache/$CACHE_KEY/build/
aws s3 cp s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/build/build-$BUILD_GUID_TARGET.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''} /data/cache/$CACHE_KEY/build/build-$BUILD_GUID_TARGET.tar${cloud_runner_1.default.buildParameters.useCompressionStrategy ? '.lz4' : ''}
secrets:
- name: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
- name: AWS_DEFAULT_REGION
- name: BUILD_GUID_TARGET
- name: steam-deploy-client
image: steamcmd/steamcmd
commands: |
apt-get update
apt-get install -y curl tar coreutils git tree > /dev/null
curl -s https://gist.githubusercontent.com/frostebite/1d56f5505b36b403b64193b7a6e54cdc/raw/fa6639ed4ef750c4268ea319d63aa80f52712ffb/deploy-client-steam.sh | bash
secrets:
- name: STEAM_USERNAME
- name: STEAM_PASSWORD
- name: STEAM_APPID
- name: STEAM_SSFN_FILE_NAME
- name: STEAM_SSFN_FILE_CONTENTS
- name: STEAM_CONFIG_VDF_1
- name: STEAM_CONFIG_VDF_2
- name: STEAM_CONFIG_VDF_3
- name: STEAM_CONFIG_VDF_4
- name: BUILD_GUID_TARGET
- name: RELEASE_BRANCH
- name: steam-deploy-project
image: steamcmd/steamcmd
commands: |
apt-get update
apt-get install -y curl tar coreutils git tree > /dev/null
curl -s https://gist.githubusercontent.com/frostebite/969da6a41002a0e901174124b643709f/raw/02403e53fb292026cba81ddcf4ff35fc1eba111d/steam-deploy-project.sh | bash
secrets:
- name: STEAM_USERNAME
- name: STEAM_PASSWORD
- name: STEAM_APPID
- name: STEAM_SSFN_FILE_NAME
- name: STEAM_SSFN_FILE_CONTENTS
- name: STEAM_CONFIG_VDF_1
- name: STEAM_CONFIG_VDF_2
- name: STEAM_CONFIG_VDF_3
- name: STEAM_CONFIG_VDF_4
- name: BUILD_GUID_2
- name: RELEASE_BRANCH
- name: aws-s3-upload-cache
image: amazon/aws-cli
hook: after
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
aws s3 cp --recursive /data/cache/$CACHE_KEY/lfs s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/lfs
rm -r /data/cache/$CACHE_KEY/lfs
aws s3 cp --recursive /data/cache/$CACHE_KEY/Library s3://${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/Library
rm -r /data/cache/$CACHE_KEY/Library
secrets:
- name: AWS_ACCESS_KEY_ID
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: AWS_SECRET_ACCESS_KEY
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: AWS_DEFAULT_REGION
value: ${process.env.AWS_REGION || ``}
- name: aws-s3-pull-cache
image: amazon/aws-cli
hook: before
commands: |
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile default
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile default
aws configure set region $AWS_DEFAULT_REGION --profile default
mkdir -p /data/cache/$CACHE_KEY/Library/
mkdir -p /data/cache/$CACHE_KEY/lfs/
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/ || true
aws s3 ls ${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/ || true
BUCKET1="${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/Library/"
aws s3 ls $BUCKET1 || true
OBJECT1="$(aws s3 ls $BUCKET1 | sort | tail -n 1 | awk '{print $4}' || '')"
aws s3 cp s3://$BUCKET1$OBJECT1 /data/cache/$CACHE_KEY/Library/ || true
BUCKET2="${cloud_runner_1.default.buildParameters.awsStackName}/cloud-runner-cache/$CACHE_KEY/lfs/"
aws s3 ls $BUCKET2 || true
OBJECT2="$(aws s3 ls $BUCKET2 | sort | tail -n 1 | awk '{print $4}' || '')"
aws s3 cp s3://$BUCKET2$OBJECT2 /data/cache/$CACHE_KEY/lfs/ || true
secrets:
- name: AWS_ACCESS_KEY_ID
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: AWS_SECRET_ACCESS_KEY
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: AWS_DEFAULT_REGION
value: ${process.env.AWS_REGION || ``}
- name: debug-cache
image: ubuntu
hook: after
commands: |
apt-get update > /dev/null
${cloud_runner_options_1.default.cloudRunnerDebug ? `apt-get install -y tree > /dev/null` : `#`}
${cloud_runner_options_1.default.cloudRunnerDebug ? `tree -L 3 /data/cache` : `#`}
secrets:
- name: awsAccessKeyId
value: ${process.env.AWS_ACCESS_KEY_ID || ``}
- name: awsSecretAccessKey
value: ${process.env.AWS_SECRET_ACCESS_KEY || ``}
- name: awsDefaultRegion
value: ${process.env.AWS_REGION || ``}`).filter((x) => cloud_runner_options_1.default.containerHookFiles.includes(x.name) && x.hook === hookLifecycle);
if (builtInContainerHooks.length > 0) {
results.push(...builtInContainerHooks);
}
return results;
}
static ConvertYamlSecrets(object) {
if (object.secrets === undefined) {
object.secrets = [];
return;
}
object.secrets = object.secrets.map((x) => {
return {
ParameterKey: x.name,
EnvironmentVariable: input_1.default.ToEnvVarFormat(x.name),
ParameterValue: x.value,
};
});
}
static ParseContainerHooks(steps) {
if (steps === '') {
return [];
}
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) {
ContainerHookService.ConvertYamlSecrets(step);
if (step.secrets === undefined) {
step.secrets = [];
}
else {
for (const secret of step.secrets) {
if (secret.ParameterValue === undefined && process.env[secret.EnvironmentVariable] !== undefined) {
if (cloud_runner_1.default.buildParameters?.cloudRunnerDebug) {
// CloudRunnerLogger.log(`Injecting custom step ${step.name} from env var ${secret.ParameterKey}`);
}
secret.ParameterValue = process.env[secret.ParameterKey] || ``;
}
}
}
if (step.image === undefined) {
step.image = `ubuntu`;
}
}
if (object === undefined) {
throw new Error(`Failed to parse ${steps}`);
}
return object;
}
static async RunPostBuildSteps(cloudRunnerStepState) {
let output = ``;
const steps = [
...ContainerHookService.ParseContainerHooks(cloud_runner_1.default.buildParameters.postBuildContainerHooks),
...ContainerHookService.GetContainerHooksFromFiles(`after`),
];
if (steps.length > 0) {
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.startGroup('post build steps');
output += await custom_workflow_1.CustomWorkflow.runContainerJob(steps, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.endGroup();
}
return output;
}
static async RunPreBuildSteps(cloudRunnerStepState) {
let output = ``;
const steps = [
...ContainerHookService.ParseContainerHooks(cloud_runner_1.default.buildParameters.preBuildContainerHooks),
...ContainerHookService.GetContainerHooksFromFiles(`before`),
];
if (steps.length > 0) {
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.startGroup('pre build steps');
output += await custom_workflow_1.CustomWorkflow.runContainerJob(steps, cloudRunnerStepState.environment, cloudRunnerStepState.secrets);
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.endGroup();
}
return output;
}
}
exports.ContainerHookService = ContainerHookService;
/***/ }),
/***/ 16785:
@ -5661,10 +5661,10 @@ exports.BuildAutomationWorkflow = void 0;
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(42864));
const cloud_runner_folders_1 = __nccwpck_require__(77795);
const core = __importStar(__nccwpck_require__(42186));
const cloud_runner_command_hook_1 = __nccwpck_require__(38960);
const command_hook_service_1 = __nccwpck_require__(96159);
const node_path_1 = __importDefault(__nccwpck_require__(49411));
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
const cloud_runner_container_hook_1 = __nccwpck_require__(18313);
const container_hook_service_1 = __nccwpck_require__(24785);
class BuildAutomationWorkflow {
async run(cloudRunnerStepState) {
return await BuildAutomationWorkflow.standardBuildAutomation(cloudRunnerStepState.image, cloudRunnerStepState);
@ -5673,7 +5673,7 @@ class BuildAutomationWorkflow {
// TODO accept post and pre build steps as yaml files in the repo
cloud_runner_logger_1.default.log(`Cloud Runner is running standard build automation`);
let output = '';
output += await cloud_runner_container_hook_1.CloudRunnerContainerHook.RunPreBuildSteps(cloudRunnerStepState);
output += await container_hook_service_1.ContainerHookService.RunPreBuildSteps(cloudRunnerStepState);
cloud_runner_logger_1.default.logWithTime('Configurable pre build step(s) time');
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.startGroup('build');
@ -5684,14 +5684,14 @@ class BuildAutomationWorkflow {
if (!cloud_runner_1.default.buildParameters.isCliMode)
core.endGroup();
cloud_runner_logger_1.default.logWithTime('Build time');
output += await cloud_runner_container_hook_1.CloudRunnerContainerHook.RunPostBuildSteps(cloudRunnerStepState);
output += await container_hook_service_1.ContainerHookService.RunPostBuildSteps(cloudRunnerStepState);
cloud_runner_logger_1.default.logWithTime('Configurable post build step(s) time');
cloud_runner_logger_1.default.log(`Cloud Runner finished running standard build automation`);
return output;
}
static get BuildWorkflow() {
const setupHooks = cloud_runner_command_hook_1.CloudRunnerCommandHooks.getHooks(cloud_runner_1.default.buildParameters.commandHooks).filter((x) => x.step?.includes(`setup`));
const buildHooks = cloud_runner_command_hook_1.CloudRunnerCommandHooks.getHooks(cloud_runner_1.default.buildParameters.commandHooks).filter((x) => x.step?.includes(`build`));
const setupHooks = command_hook_service_1.CommandHookService.getHooks(cloud_runner_1.default.buildParameters.commandHooks).filter((x) => x.step?.includes(`setup`));
const buildHooks = command_hook_service_1.CommandHookService.getHooks(cloud_runner_1.default.buildParameters.commandHooks).filter((x) => x.step?.includes(`build`));
const builderPath = cloud_runner_folders_1.CloudRunnerFolders.ToLinuxFolder(node_path_1.default.join(cloud_runner_folders_1.CloudRunnerFolders.builderPathAbsolute, 'dist', `index.js`));
return `apt-get update > /dev/null
apt-get install -y curl tar tree npm git-lfs jq git > /dev/null
@ -5751,11 +5751,11 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.CustomWorkflow = void 0;
const cloud_runner_logger_1 = __importDefault(__nccwpck_require__(42864));
const cloud_runner_folders_1 = __nccwpck_require__(77795);
const cloud_runner_container_hook_1 = __nccwpck_require__(18313);
const container_hook_service_1 = __nccwpck_require__(24785);
const cloud_runner_1 = __importDefault(__nccwpck_require__(79144));
class CustomWorkflow {
static async runContainerJobFromString(buildSteps, environmentVariables, secrets) {
return await CustomWorkflow.runContainerJob(cloud_runner_container_hook_1.CloudRunnerContainerHook.ParseContainerHooks(buildSteps), environmentVariables, secrets);
return await CustomWorkflow.runContainerJob(container_hook_service_1.ContainerHookService.ParseContainerHooks(buildSteps), environmentVariables, secrets);
}
static async runContainerJob(steps, environmentVariables, secrets) {
try {

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@ import * as zlib from 'node:zlib';
import CloudRunnerLogger from '../../services/core/cloud-runner-logger';
import { Input } from '../../..';
import CloudRunner from '../../cloud-runner';
import { CloudRunnerCommandHooks } from '../../services/cloud-runner-hooks/cloud-runner-command-hook';
import { CommandHookService } from '../../services/hooks/command-hook-service';
import { FollowLogStreamService } from '../../services/core/follow-log-stream-service';
import CloudRunnerOptions from '../../options/cloud-runner-options';
import GitHub from '../../../github';
@ -41,7 +41,7 @@ class AWSTaskRunner {
{
name: taskDef.taskDefStackName,
environment,
command: ['-c', CloudRunnerCommandHooks.ApplyHooksToCommands(commands, CloudRunner.buildParameters)],
command: ['-c', CommandHookService.ApplyHooksToCommands(commands, CloudRunner.buildParameters)],
},
],
},

View File

@ -11,7 +11,7 @@ import { ProviderResource } from '../provider-resource';
import { ProviderWorkflow } from '../provider-workflow';
import { CloudRunnerSystem } from '../../services/core/cloud-runner-system';
import * as fs from 'node:fs';
import { CloudRunnerCommandHooks } from '../../services/cloud-runner-hooks/cloud-runner-command-hook';
import { CommandHookService } from '../../services/hooks/command-hook-service';
import { StringKeyValuePair } from '../../../shared-types';
class LocalDockerCloudRunner implements ProviderInterface {
@ -119,7 +119,7 @@ set -e
mkdir -p /github/workspace/cloud-runner-cache
mkdir -p /data/cache
cp -a /github/workspace/cloud-runner-cache/. ${sharedFolder}
${CloudRunnerCommandHooks.ApplyHooksToCommands(commands, this.buildParameters)}
${CommandHookService.ApplyHooksToCommands(commands, this.buildParameters)}
cp -a ${sharedFolder}. /github/workspace/cloud-runner-cache/
`;
writeFileSync(`${workspace}/${entrypointFilePath}`, fileContents, {

View File

@ -1,6 +1,6 @@
import { V1EnvVar, V1EnvVarSource, V1SecretKeySelector } from '@kubernetes/client-node';
import BuildParameters from '../../../build-parameters';
import { CloudRunnerCommandHooks } from '../../services/cloud-runner-hooks/cloud-runner-command-hook';
import { CommandHookService } from '../../services/hooks/command-hook-service';
import CloudRunnerEnvironmentVariable from '../../options/cloud-runner-environment-variable';
import CloudRunnerSecret from '../../options/cloud-runner-secret';
import CloudRunner from '../../cloud-runner';
@ -108,7 +108,7 @@ class KubernetesJobSpecFactory {
command: ['/bin/sh'],
args: [
'-c',
`${CloudRunnerCommandHooks.ApplyHooksToCommands(`${command}\nsleep 2m`, CloudRunner.buildParameters)}`,
`${CommandHookService.ApplyHooksToCommands(`${command}\nsleep 2m`, CloudRunner.buildParameters)}`,
],
workingDir: `${workingDirectory}`,

View File

@ -5,7 +5,7 @@ import CloudRunnerEnvironmentVariable from '../../options/cloud-runner-environme
import CloudRunnerOptionsReader from '../../options/cloud-runner-options-reader';
import CloudRunnerQueryOverride from '../../options/cloud-runner-query-override';
import CloudRunnerSecret from '../../options/cloud-runner-secret';
import { CloudRunnerCommandHooks } from '../cloud-runner-hooks/cloud-runner-command-hook';
import { CommandHookService } from '../hooks/command-hook-service';
export class TaskParameterSerializer {
static readonly blockedParameterNames: Set<string> = new Set([
@ -32,7 +32,7 @@ export class TaskParameterSerializer {
...TaskParameterSerializer.serializeFromObject(buildParameters),
...TaskParameterSerializer.serializeInput(),
...TaskParameterSerializer.serializeCloudRunnerOptions(),
...CloudRunnerCommandHooks.getSecrets(CloudRunnerCommandHooks.getHooks(buildParameters.commandHooks)),
...CommandHookService.getSecrets(CommandHookService.getHooks(buildParameters.commandHooks)),
]
.filter(
(x) =>

View File

@ -9,9 +9,9 @@ import { CommandHook } from './command-hook';
// import CloudRunnerLogger from './cloud-runner-logger';
export class CloudRunnerCommandHooks {
export class CommandHookService {
public static ApplyHooksToCommands(commands: string, buildParameters: BuildParameters): string {
const hooks = CloudRunnerCommandHooks.getHooks(buildParameters.commandHooks);
const hooks = CommandHookService.getHooks(buildParameters.commandHooks);
CloudRunnerLogger.log(`Applying hooks ${hooks.length}`);
return `echo "---"
@ -38,8 +38,8 @@ echo "---${buildParameters.logId}"`;
return [
...output.filter((x) => x.hook !== undefined && x.hook.length > 0),
...CloudRunnerCommandHooks.GetCustomHooksFromFiles(`before`),
...CloudRunnerCommandHooks.GetCustomHooksFromFiles(`after`),
...CommandHookService.GetCustomHooksFromFiles(`before`),
...CommandHookService.GetCustomHooksFromFiles(`after`),
];
}
@ -55,7 +55,7 @@ echo "---${buildParameters.logId}"`;
continue;
}
const fileContents = fs.readFileSync(path.join(gameCiCustomHooksPath, file), `utf8`);
const fileContentsObject = CloudRunnerCommandHooks.ParseHooks(fileContents)[0];
const fileContentsObject = CommandHookService.ParseHooks(fileContents)[0];
if (fileContentsObject.hook.includes(hookLifecycle)) {
results.push(fileContentsObject);
}
@ -97,7 +97,7 @@ echo "---${buildParameters.logId}"`;
const isArray = hooks.replace(/\s/g, ``)[0] === `-`;
const object: CommandHook[] = isArray ? YAML.parse(hooks) : [YAML.parse(hooks)];
for (const hook of object) {
CloudRunnerCommandHooks.ConvertYamlSecrets(hook);
CommandHookService.ConvertYamlSecrets(hook);
if (hook.secrets === undefined) {
hook.secrets = [];
}

View File

@ -10,7 +10,7 @@ import CloudRunnerOptions from '../../options/cloud-runner-options';
import { ContainerHook as ContainerHook } from './container-hook';
import { CloudRunnerStepParameters } from '../../options/cloud-runner-step-parameters';
export class CloudRunnerContainerHook {
export class ContainerHookService {
static GetContainerHooksFromFiles(hookLifecycle: string): ContainerHook[] {
const results: ContainerHook[] = [];
try {
@ -22,7 +22,7 @@ export class CloudRunnerContainerHook {
continue;
}
const fileContents = fs.readFileSync(path.join(gameCiCustomStepsPath, file), `utf8`);
const fileContentsObject = CloudRunnerContainerHook.ParseContainerHooks(fileContents)[0];
const fileContentsObject = ContainerHookService.ParseContainerHooks(fileContents)[0];
if (fileContentsObject.hook === hookLifecycle) {
results.push(fileContentsObject);
}
@ -33,7 +33,7 @@ export class CloudRunnerContainerHook {
// RemoteClientLogger.log(`Active Steps From Files: \n ${JSON.stringify(results, undefined, 4)}`);
const builtInContainerHooks: ContainerHook[] = CloudRunnerContainerHook.ParseContainerHooks(
const builtInContainerHooks: ContainerHook[] = ContainerHookService.ParseContainerHooks(
`- name: aws-s3-upload-build
image: amazon/aws-cli
hook: after
@ -205,7 +205,7 @@ export class CloudRunnerContainerHook {
const isArray = steps.replace(/\s/g, ``)[0] === `-`;
const object: ContainerHook[] = isArray ? YAML.parse(steps) : [YAML.parse(steps)];
for (const step of object) {
CloudRunnerContainerHook.ConvertYamlSecrets(step);
ContainerHookService.ConvertYamlSecrets(step);
if (step.secrets === undefined) {
step.secrets = [];
} else {
@ -232,8 +232,8 @@ export class CloudRunnerContainerHook {
static async RunPostBuildSteps(cloudRunnerStepState: CloudRunnerStepParameters) {
let output = ``;
const steps: ContainerHook[] = [
...CloudRunnerContainerHook.ParseContainerHooks(CloudRunner.buildParameters.postBuildContainerHooks),
...CloudRunnerContainerHook.GetContainerHooksFromFiles(`after`),
...ContainerHookService.ParseContainerHooks(CloudRunner.buildParameters.postBuildContainerHooks),
...ContainerHookService.GetContainerHooksFromFiles(`after`),
];
if (steps.length > 0) {
@ -251,8 +251,8 @@ export class CloudRunnerContainerHook {
static async RunPreBuildSteps(cloudRunnerStepState: CloudRunnerStepParameters) {
let output = ``;
const steps: ContainerHook[] = [
...CloudRunnerContainerHook.ParseContainerHooks(CloudRunner.buildParameters.preBuildContainerHooks),
...CloudRunnerContainerHook.GetContainerHooksFromFiles(`before`),
...ContainerHookService.ParseContainerHooks(CloudRunner.buildParameters.preBuildContainerHooks),
...ContainerHookService.GetContainerHooksFromFiles(`before`),
];
if (steps.length > 0) {

View File

@ -6,8 +6,8 @@ import CloudRunnerLogger from '../services/core/cloud-runner-logger';
import { v4 as uuidv4 } from 'uuid';
import CloudRunnerOptions from '../options/cloud-runner-options';
import setups from './cloud-runner-suite.test';
import { CloudRunnerContainerHook } from '../services/cloud-runner-hooks/cloud-runner-container-hook';
import { CloudRunnerCommandHooks } from '../services/cloud-runner-hooks/cloud-runner-command-hook';
import { ContainerHookService } from '../services/hooks/container-hook-service';
import { CommandHookService } from '../services/hooks/command-hook-service';
async function CreateParameters(overrides: any) {
if (overrides) {
@ -33,8 +33,8 @@ commands: echo "test"`;
cacheKey: `test-case-${uuidv4()}`,
};
CloudRunner.setup(await CreateParameters(overrides));
const stringObject = CloudRunnerContainerHook.ParseContainerHooks(yamlString);
const stringObject2 = CloudRunnerContainerHook.ParseContainerHooks(yamlString2);
const stringObject = ContainerHookService.ParseContainerHooks(yamlString);
const stringObject2 = ContainerHookService.ParseContainerHooks(yamlString2);
CloudRunnerLogger.log(yamlString);
CloudRunnerLogger.log(JSON.stringify(stringObject, undefined, 4));
@ -44,7 +44,7 @@ commands: echo "test"`;
expect(stringObject2.length).toBe(1);
expect(stringObject2[0].hook).toBe(`before`);
const getCustomStepsFromFiles = CloudRunnerContainerHook.GetContainerHooksFromFiles(`before`);
const getCustomStepsFromFiles = ContainerHookService.GetContainerHooksFromFiles(`before`);
CloudRunnerLogger.log(JSON.stringify(getCustomStepsFromFiles, undefined, 4));
});
if (CloudRunnerOptions.cloudRunnerDebug && CloudRunnerOptions.providerStrategy !== `k8s`) {
@ -60,8 +60,8 @@ commands: echo "test"`;
};
const buildParameter2 = await CreateParameters(overrides);
await CloudRunner.setup(buildParameter2);
const beforeHooks = CloudRunnerCommandHooks.GetCustomHooksFromFiles(`before`);
const afterHooks = CloudRunnerCommandHooks.GetCustomHooksFromFiles(`after`);
const beforeHooks = CommandHookService.GetCustomHooksFromFiles(`before`);
const afterHooks = CommandHookService.GetCustomHooksFromFiles(`after`);
expect(beforeHooks).toHaveLength(1);
expect(afterHooks).toHaveLength(1);
});
@ -73,12 +73,12 @@ commands: echo "test"`;
targetPlatform: 'StandaloneLinux64',
cacheKey: `test-case-${uuidv4()}`,
containerHookFiles: `my-test-step-pre-build,my-test-step-post-build`,
customHookFiles: `my-test-hook-pre-build,my-test-hook-post-build`,
commandHookFiles: `my-test-hook-pre-build,my-test-hook-post-build`,
};
const buildParameter2 = await CreateParameters(overrides);
await CloudRunner.setup(buildParameter2);
const beforeSteps = CloudRunnerContainerHook.GetContainerHooksFromFiles(`before`);
const afterSteps = CloudRunnerContainerHook.GetContainerHooksFromFiles(`after`);
const beforeSteps = ContainerHookService.GetContainerHooksFromFiles(`before`);
const afterSteps = ContainerHookService.GetContainerHooksFromFiles(`after`);
expect(beforeSteps).toHaveLength(1);
expect(afterSteps).toHaveLength(1);
});

View File

@ -3,10 +3,10 @@ import { CloudRunnerFolders } from '../options/cloud-runner-folders';
import { CloudRunnerStepParameters } from '../options/cloud-runner-step-parameters';
import { WorkflowInterface } from './workflow-interface';
import * as core from '@actions/core';
import { CloudRunnerCommandHooks } from '../services/cloud-runner-hooks/cloud-runner-command-hook';
import { CommandHookService } from '../services/hooks/command-hook-service';
import path from 'node:path';
import CloudRunner from '../cloud-runner';
import { CloudRunnerContainerHook } from '../services/cloud-runner-hooks/cloud-runner-container-hook';
import { ContainerHookService } from '../services/hooks/container-hook-service';
export class BuildAutomationWorkflow implements WorkflowInterface {
async run(cloudRunnerStepState: CloudRunnerStepParameters) {
@ -19,7 +19,7 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
let output = '';
output += await CloudRunnerContainerHook.RunPreBuildSteps(cloudRunnerStepState);
output += await ContainerHookService.RunPreBuildSteps(cloudRunnerStepState);
CloudRunnerLogger.logWithTime('Configurable pre build step(s) time');
if (!CloudRunner.buildParameters.isCliMode) core.startGroup('build');
@ -39,7 +39,7 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
if (!CloudRunner.buildParameters.isCliMode) core.endGroup();
CloudRunnerLogger.logWithTime('Build time');
output += await CloudRunnerContainerHook.RunPostBuildSteps(cloudRunnerStepState);
output += await ContainerHookService.RunPostBuildSteps(cloudRunnerStepState);
CloudRunnerLogger.logWithTime('Configurable post build step(s) time');
CloudRunnerLogger.log(`Cloud Runner finished running standard build automation`);
@ -48,10 +48,10 @@ export class BuildAutomationWorkflow implements WorkflowInterface {
}
private static get BuildWorkflow() {
const setupHooks = CloudRunnerCommandHooks.getHooks(CloudRunner.buildParameters.commandHooks).filter((x) =>
const setupHooks = CommandHookService.getHooks(CloudRunner.buildParameters.commandHooks).filter((x) =>
x.step?.includes(`setup`),
);
const buildHooks = CloudRunnerCommandHooks.getHooks(CloudRunner.buildParameters.commandHooks).filter((x) =>
const buildHooks = CommandHookService.getHooks(CloudRunner.buildParameters.commandHooks).filter((x) =>
x.step?.includes(`build`),
);
const builderPath = CloudRunnerFolders.ToLinuxFolder(

View File

@ -2,8 +2,8 @@ import CloudRunnerLogger from '../services/core/cloud-runner-logger';
import CloudRunnerSecret from '../options/cloud-runner-secret';
import { CloudRunnerFolders } from '../options/cloud-runner-folders';
import CloudRunnerEnvironmentVariable from '../options/cloud-runner-environment-variable';
import { CloudRunnerContainerHook } from '../services/cloud-runner-hooks/cloud-runner-container-hook';
import { ContainerHook } from '../services/cloud-runner-hooks/container-hook';
import { ContainerHookService } from '../services/hooks/container-hook-service';
import { ContainerHook } from '../services/hooks/container-hook';
import CloudRunner from '../cloud-runner';
export class CustomWorkflow {
@ -13,7 +13,7 @@ export class CustomWorkflow {
secrets: CloudRunnerSecret[],
): Promise<string> {
return await CustomWorkflow.runContainerJob(
CloudRunnerContainerHook.ParseContainerHooks(buildSteps),
ContainerHookService.ParseContainerHooks(buildSteps),
environmentVariables,
secrets,
);