Ensure that we have files to calculate the hash for the cache key from

This commit is contained in:
Michael B. Gale 2024-07-23 12:38:04 +01:00
parent 9d1353fe5f
commit 5afaeede1c
No known key found for this signature in database
GPG key ID: FF5E2765BD00628F
3 changed files with 45 additions and 5 deletions

View file

@ -65,6 +65,9 @@ const CODEQL_DEFAULT_CACHE_CONFIG = {
hash: ["**/go.sum"],
},
};
async function makeGlobber(files) {
return glob.create(files.join("\n"));
}
/**
* Attempts to restore dependency caches for the languages being analyzed.
*
@ -80,6 +83,13 @@ async function downloadDependencyCaches(languages, logger) {
logger.info(`Skipping download of dependency cache for ${language} as we have no caching configuration for it.`);
continue;
}
// Check that we can find files to calculate the hash for the cache key from, so we don't end up
// with an empty string.
const globber = await makeGlobber(cacheConfig.hash);
if ((await globber.glob()).length === 0) {
logger.info(`Skipping download of dependency cache for ${language} as we cannot calculate a hash for the cache key.`);
continue;
}
const primaryKey = await cacheKey(language, cacheConfig);
const restoreKeys = [await cachePrefix(language)];
logger.info(`Downloading cache for ${language} with key ${primaryKey} and restore keys ${restoreKeys.join(", ")}`);
@ -104,8 +114,14 @@ async function uploadDependencyCaches(config, logger) {
logger.info(`Skipping upload of dependency cache for ${language} as we have no caching configuration for it.`);
continue;
}
const globber = await glob.create(cacheConfig.hash.join("\n"));
const size = await (0, caching_utils_1.getTotalCacheSize)(await globber.glob(), logger);
// Check that we can find files to calculate the hash for the cache key from, so we don't end up
// with an empty string.
const globber = await makeGlobber(cacheConfig.hash);
if ((await globber.glob()).length === 0) {
logger.info(`Skipping upload of dependency cache for ${language} as we cannot calculate a hash for the cache key.`);
continue;
}
const size = await (0, caching_utils_1.getTotalCacheSize)(cacheConfig.paths, logger);
const key = await cacheKey(language, cacheConfig);
logger.info(`Uploading cache of size ${size} for ${language} with key ${key}`);
await actionsCache.saveCache(cacheConfig.paths, key);