Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change hash to be a function that can use Features
  • Loading branch information
mbg committed Nov 5, 2025
commit ab1c84236a1357778c5741c52f065d31a9fc7fe9
15 changes: 8 additions & 7 deletions lib/analyze-action.js

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

15 changes: 8 additions & 7 deletions lib/init-action.js

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

24 changes: 13 additions & 11 deletions src/dependency-caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ interface CacheConfig {
/** Gets the paths of directories on the runner that should be included in the cache. */
getDependencyPaths: () => string[];
/**
* Patterns for the paths of files whose contents affect which dependencies are used
* Gets patterns for the paths of files whose contents affect which dependencies are used
* by a project. We find all files which match these patterns, calculate a hash for
* their contents, and use that hash as part of the cache key.
*/
hash: string[];
getHashPatterns: (codeql: CodeQL, features: Features) => Promise<string[]>;
}

const CODEQL_DEPENDENCY_CACHE_PREFIX = "codeql-dependencies";
Expand Down Expand Up @@ -66,7 +66,7 @@ export function getJavaDependencyDirs(): string[] {
const defaultCacheConfigs: { [language: string]: CacheConfig } = {
java: {
getDependencyPaths: getJavaDependencyDirs,
hash: [
getHashPatterns: async () => [
// Maven
"**/pom.xml",
// Gradle
Expand All @@ -80,7 +80,7 @@ const defaultCacheConfigs: { [language: string]: CacheConfig } = {
},
csharp: {
getDependencyPaths: () => [join(os.homedir(), ".nuget", "packages")],
hash: [
getHashPatterns: async () => [
// NuGet
"**/packages.lock.json",
// Paket
Expand All @@ -89,7 +89,7 @@ const defaultCacheConfigs: { [language: string]: CacheConfig } = {
},
go: {
getDependencyPaths: () => [join(os.homedir(), "go", "pkg", "mod")],
hash: ["**/go.sum"],
getHashPatterns: async () => ["**/go.sum"],
},
};

Expand Down Expand Up @@ -149,7 +149,8 @@ export async function downloadDependencyCaches(

// 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);
const patterns = await cacheConfig.getHashPatterns(codeql, features);
const globber = await makeGlobber(patterns);

if ((await globber.glob()).length === 0) {
status.push({ language, hit_kind: CacheHitKind.NoHash });
Expand All @@ -159,7 +160,7 @@ export async function downloadDependencyCaches(
continue;
}

const primaryKey = await cacheKey(codeql, features, language, cacheConfig);
const primaryKey = await cacheKey(codeql, features, language, patterns);
const restoreKeys: string[] = [
await cachePrefix(codeql, features, language),
];
Expand Down Expand Up @@ -244,7 +245,8 @@ export async function uploadDependencyCaches(

// 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);
const patterns = await cacheConfig.getHashPatterns(codeql, features);
const globber = await makeGlobber(patterns);

if ((await globber.glob()).length === 0) {
status.push({ language, result: CacheStoreResult.NoHash });
Expand Down Expand Up @@ -279,7 +281,7 @@ export async function uploadDependencyCaches(
continue;
}

const key = await cacheKey(codeql, features, language, cacheConfig);
const key = await cacheKey(codeql, features, language, patterns);

logger.info(
`Uploading cache of size ${size} for ${language} with key ${key}...`,
Expand Down Expand Up @@ -330,9 +332,9 @@ async function cacheKey(
codeql: CodeQL,
features: Features,
language: Language,
cacheConfig: CacheConfig,
patterns: string[],
): Promise<string> {
const hash = await glob.hashFiles(cacheConfig.hash.join("\n"));
const hash = await glob.hashFiles(patterns.join("\n"));
return `${await cachePrefix(codeql, features, language)}${hash}`;
}

Expand Down