@@ -21,11 +21,11 @@ interface CacheConfig {
2121 /** Gets the paths of directories on the runner that should be included in the cache. */
2222 getDependencyPaths : ( ) => string [ ] ;
2323 /**
24- * Patterns for the paths of files whose contents affect which dependencies are used
24+ * Gets patterns for the paths of files whose contents affect which dependencies are used
2525 * by a project. We find all files which match these patterns, calculate a hash for
2626 * their contents, and use that hash as part of the cache key.
2727 */
28- hash : string [ ] ;
28+ getHashPatterns : ( codeql : CodeQL , features : Features ) => Promise < string [ ] > ;
2929}
3030
3131const CODEQL_DEPENDENCY_CACHE_PREFIX = "codeql-dependencies" ;
@@ -65,7 +65,7 @@ export function getJavaDependencyDirs(): string[] {
6565const defaultCacheConfigs : { [ language : string ] : CacheConfig } = {
6666 java : {
6767 getDependencyPaths : getJavaDependencyDirs ,
68- hash : [
68+ getHashPatterns : async ( ) => [
6969 // Maven
7070 "**/pom.xml" ,
7171 // Gradle
@@ -79,7 +79,7 @@ const defaultCacheConfigs: { [language: string]: CacheConfig } = {
7979 } ,
8080 csharp : {
8181 getDependencyPaths : ( ) => [ join ( os . homedir ( ) , ".nuget" , "packages" ) ] ,
82- hash : [
82+ getHashPatterns : async ( ) => [
8383 // NuGet
8484 "**/packages.lock.json" ,
8585 // Paket
@@ -88,7 +88,7 @@ const defaultCacheConfigs: { [language: string]: CacheConfig } = {
8888 } ,
8989 go : {
9090 getDependencyPaths : ( ) => [ join ( os . homedir ( ) , "go" , "pkg" , "mod" ) ] ,
91- hash : [ "**/go.sum" ] ,
91+ getHashPatterns : async ( ) => [ "**/go.sum" ] ,
9292 } ,
9393} ;
9494
@@ -125,7 +125,8 @@ export async function downloadDependencyCaches(
125125
126126 // Check that we can find files to calculate the hash for the cache key from, so we don't end up
127127 // with an empty string.
128- const globber = await makeGlobber ( cacheConfig . hash ) ;
128+ const patterns = await cacheConfig . getHashPatterns ( codeql , features ) ;
129+ const globber = await makeGlobber ( patterns ) ;
129130
130131 if ( ( await globber . glob ( ) ) . length === 0 ) {
131132 logger . info (
@@ -134,7 +135,7 @@ export async function downloadDependencyCaches(
134135 continue ;
135136 }
136137
137- const primaryKey = await cacheKey ( codeql , features , language , cacheConfig ) ;
138+ const primaryKey = await cacheKey ( codeql , features , language , patterns ) ;
138139 const restoreKeys : string [ ] = [
139140 await cachePrefix ( codeql , features , language ) ,
140141 ] ;
@@ -188,7 +189,8 @@ export async function uploadDependencyCaches(
188189
189190 // Check that we can find files to calculate the hash for the cache key from, so we don't end up
190191 // with an empty string.
191- const globber = await makeGlobber ( cacheConfig . hash ) ;
192+ const patterns = await cacheConfig . getHashPatterns ( codeql , features ) ;
193+ const globber = await makeGlobber ( patterns ) ;
192194
193195 if ( ( await globber . glob ( ) ) . length === 0 ) {
194196 logger . info (
@@ -221,7 +223,7 @@ export async function uploadDependencyCaches(
221223 continue ;
222224 }
223225
224- const key = await cacheKey ( codeql , features , language , cacheConfig ) ;
226+ const key = await cacheKey ( codeql , features , language , patterns ) ;
225227
226228 logger . info (
227229 `Uploading cache of size ${ size } for ${ language } with key ${ key } ...` ,
@@ -259,9 +261,9 @@ async function cacheKey(
259261 codeql : CodeQL ,
260262 features : Features ,
261263 language : Language ,
262- cacheConfig : CacheConfig ,
264+ patterns : string [ ] ,
263265) : Promise < string > {
264- const hash = await glob . hashFiles ( cacheConfig . hash . join ( "\n" ) ) ;
266+ const hash = await glob . hashFiles ( patterns . join ( "\n" ) ) ;
265267 return `${ await cachePrefix ( codeql , features , language ) } ${ hash } ` ;
266268}
267269
0 commit comments