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
3 changed files with 45 additions and 5 deletions

View File

@@ -51,6 +51,10 @@ const CODEQL_DEFAULT_CACHE_CONFIG: { [language: string]: CacheConfig } = {
},
};
async function makeGlobber(files: string[]): Promise<glob.Globber> {
return glob.create(files.join("\n"));
}
/**
* Attempts to restore dependency caches for the languages being analyzed.
*
@@ -74,6 +78,17 @@ export async function downloadDependencyCaches(
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: string[] = [await cachePrefix(language)];
@@ -115,9 +130,18 @@ export async function uploadDependencyCaches(config: Config, logger: Logger) {
continue;
}
const globber = await glob.create(cacheConfig.hash.join("\n"));
const size = await 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 getTotalCacheSize(cacheConfig.paths, logger);
const key = await cacheKey(language, cacheConfig);
logger.info(