Skip to content

Commit

Permalink
Ensure that we have files to calculate the hash for the cache key from
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael B. Gale committed Oct 29, 2024
1 parent 9d1353f commit 5afaeed
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
20 changes: 18 additions & 2 deletions lib/dependency-caching.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/dependency-caching.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 26 additions & 2 deletions src/dependency-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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)];

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 5afaeed

Please sign in to comment.