Simple override cache push and pull override to allow pure cloud storage driven caching

pull/353/head
Frostebite 2022-03-06 02:04:27 +00:00
parent a8be343564
commit d8278dc24a
3 changed files with 36 additions and 9 deletions

19
dist/index.js vendored
View File

@ -630,7 +630,7 @@ class Caching {
}
// eslint-disable-next-line func-style
const formatFunction = function (format) {
const arguments_ = Array.prototype.slice.call([path_1.default.resolve(sourceFolder, '..'), cacheFolder], 1);
const arguments_ = Array.prototype.slice.call([path_1.default.resolve(sourceFolder, '..'), cacheFolder, cacheKey], 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
@ -638,9 +638,10 @@ class Caching {
yield cloud_runner_system_1.CloudRunnerSystem.Run(`zip ${cacheKey}.zip ${path_1.default.basename(sourceFolder)}`);
console_1.assert(fs_1.default.existsSync(`${cacheKey}.zip`), 'cache zip exists');
console_1.assert(fs_1.default.existsSync(path_1.default.basename(sourceFolder)), 'source folder exists');
yield (process.env.CLOUD_RUNNER_OVERRIDE_CACHE_PUSH
? cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_OVERRIDE_CACHE_PUSH))
: cloud_runner_system_1.CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`));
if (process.env.CLOUD_RUNNER_PRE_CACHE_PUSH) {
cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PUSH));
}
cloud_runner_system_1.CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`);
remote_client_logger_1.RemoteClientLogger.log(`moved ${cacheKey}.zip to ${cacheFolder}`);
console_1.assert(fs_1.default.existsSync(`${path_1.default.join(cacheFolder, cacheKey)}.zip`), 'cache zip exists inside cache folder');
if (__1.Input.cloudRunnerTests) {
@ -671,6 +672,16 @@ class Caching {
process.chdir(cacheFolder);
const cacheSelection = cacheKey !== `` && fs_1.default.existsSync(`${cacheKey}.zip`) ? cacheKey : latestInBranch;
yield cloud_runner_logger_1.default.log(`cache key ${cacheKey} selection ${cacheSelection}`);
// eslint-disable-next-line func-style
const formatFunction = function (format) {
const arguments_ = Array.prototype.slice.call([path_1.default.resolve(destinationFolder, '..'), cacheFolder, cacheKey], 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
};
if (process.env.CLOUD_RUNNER_PRE_CACHE_PULL) {
cloud_runner_system_1.CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PULL));
}
if (fs_1.default.existsSync(`${cacheSelection}.zip`)) {
const resultsFolder = `results${cloud_runner_state_1.CloudRunnerState.buildParams.buildGuid}`;
yield cloud_runner_system_1.CloudRunnerSystem.Run(`mkdir -p ${resultsFolder}`);

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,7 @@ export class Caching {
}
// eslint-disable-next-line func-style
const formatFunction = function (format: string) {
const arguments_ = Array.prototype.slice.call([path.resolve(sourceFolder, '..'), cacheFolder], 1);
const arguments_ = Array.prototype.slice.call([path.resolve(sourceFolder, '..'), cacheFolder, cacheKey], 1);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
@ -38,9 +38,10 @@ export class Caching {
await CloudRunnerSystem.Run(`zip ${cacheKey}.zip ${path.basename(sourceFolder)}`);
assert(fs.existsSync(`${cacheKey}.zip`), 'cache zip exists');
assert(fs.existsSync(path.basename(sourceFolder)), 'source folder exists');
await (process.env.CLOUD_RUNNER_OVERRIDE_CACHE_PUSH
? CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_OVERRIDE_CACHE_PUSH))
: CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`));
if (process.env.CLOUD_RUNNER_PRE_CACHE_PUSH) {
CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PUSH));
}
CloudRunnerSystem.Run(`mv ${cacheKey}.zip ${cacheFolder}`);
RemoteClientLogger.log(`moved ${cacheKey}.zip to ${cacheFolder}`);
assert(fs.existsSync(`${path.join(cacheFolder, cacheKey)}.zip`), 'cache zip exists inside cache folder');
@ -74,6 +75,21 @@ export class Caching {
const cacheSelection = cacheKey !== `` && fs.existsSync(`${cacheKey}.zip`) ? cacheKey : latestInBranch;
await CloudRunnerLogger.log(`cache key ${cacheKey} selection ${cacheSelection}`);
// eslint-disable-next-line func-style
const formatFunction = function (format: string) {
const arguments_ = Array.prototype.slice.call(
[path.resolve(destinationFolder, '..'), cacheFolder, cacheKey],
1,
);
return format.replace(/{(\d+)}/g, function (match, number) {
return typeof arguments_[number] != 'undefined' ? arguments_[number] : match;
});
};
if (process.env.CLOUD_RUNNER_PRE_CACHE_PULL) {
CloudRunnerSystem.Run(formatFunction(process.env.CLOUD_RUNNER_PRE_CACHE_PULL));
}
if (fs.existsSync(`${cacheSelection}.zip`)) {
const resultsFolder = `results${CloudRunnerState.buildParams.buildGuid}`;
await CloudRunnerSystem.Run(`mkdir -p ${resultsFolder}`);