Skip to content

Commit d854ba6

Browse files
committed
Pass FeatureEnablement to getDependencyPaths
1 parent cf8b7a6 commit d854ba6

File tree

4 files changed

+36
-18
lines changed

4 files changed

+36
-18
lines changed

lib/analyze-action.js

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init-action.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dependency-caching.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ test("checkHashPatterns - logs when no patterns match", async (t) => {
126126
const features = createFeatures([]);
127127
const messages: LoggedMessage[] = [];
128128
const config: CacheConfig = {
129-
getDependencyPaths: () => [],
129+
getDependencyPaths: async () => [],
130130
getHashPatterns: async () => undefined,
131131
};
132132

@@ -155,7 +155,7 @@ test("checkHashPatterns - returns patterns when patterns match", async (t) => {
155155
fs.writeFileSync(path.join(tmpDir, "test.java"), "");
156156

157157
const config: CacheConfig = {
158-
getDependencyPaths: () => [],
158+
getDependencyPaths: async () => [],
159159
getHashPatterns: async () => makePatternCheck(patterns),
160160
};
161161

src/dependency-caching.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import { getErrorMessage, getRequiredEnvParam } from "./util";
2020
*/
2121
export interface CacheConfig {
2222
/** Gets the paths of directories on the runner that should be included in the cache. */
23-
getDependencyPaths: () => string[];
23+
getDependencyPaths: (
24+
codeql: CodeQL,
25+
features: FeatureEnablement,
26+
) => Promise<string[]>;
2427
/**
2528
* Gets an array of glob patterns for the paths of files whose contents affect which dependencies are used
2629
* by a project. This function also checks whether there are any matching files and returns
@@ -55,7 +58,7 @@ export function getJavaTempDependencyDir(): string {
5558
* @returns The paths of directories on the runner that should be included in a dependency cache
5659
* for a Java analysis.
5760
*/
58-
export function getJavaDependencyDirs(): string[] {
61+
export async function getJavaDependencyDirs(): Promise<string[]> {
5962
return [
6063
// Maven
6164
join(os.homedir(), ".m2", "repository"),
@@ -66,14 +69,23 @@ export function getJavaDependencyDirs(): string[] {
6669
];
6770
}
6871

72+
/**
73+
* Returns a path to a directory intended to be used to store dependencies
74+
* for the C# `build-mode: none` extractor.
75+
* @returns The path to the directory that should be used by the `build-mode: none` extractor.
76+
*/
77+
export function getCsharpTempDependencyDir(): string {
78+
return join(getTemporaryDirectory(), "codeql_csharp", "repository");
79+
}
80+
6981
/**
7082
* Returns an array of paths of directories on the runner that should be included in a dependency cache
7183
* for a C# analysis.
7284
*
7385
* @returns The paths of directories on the runner that should be included in a dependency cache
7486
* for a C# analysis.
7587
*/
76-
export function getCsharpDependencyDirs(): string[] {
88+
export async function getCsharpDependencyDirs(): Promise<string[]> {
7789
return [join(os.homedir(), ".nuget", "packages")];
7890
}
7991

@@ -173,7 +185,7 @@ const defaultCacheConfigs: { [language: string]: CacheConfig } = {
173185
getHashPatterns: getCsharpHashPatterns,
174186
},
175187
go: {
176-
getDependencyPaths: () => [join(os.homedir(), "go", "pkg", "mod")],
188+
getDependencyPaths: async () => [join(os.homedir(), "go", "pkg", "mod")],
177189
getHashPatterns: async () => internal.makePatternCheck(["**/go.sum"]),
178190
},
179191
};
@@ -291,7 +303,7 @@ export async function downloadDependencyCaches(
291303

292304
const start = performance.now();
293305
const hitKey = await actionsCache.restoreCache(
294-
cacheConfig.getDependencyPaths(),
306+
await cacheConfig.getDependencyPaths(codeql, features),
295307
primaryKey,
296308
restoreKeys,
297309
);
@@ -387,7 +399,7 @@ export async function uploadDependencyCaches(
387399
// with the dependency caches. For this, we could use the Cache API to check whether other workflows
388400
// are using the quota and how full it is.
389401
const size = await getTotalCacheSize(
390-
cacheConfig.getDependencyPaths(),
402+
await cacheConfig.getDependencyPaths(codeql, features),
391403
logger,
392404
true,
393405
);
@@ -409,7 +421,10 @@ export async function uploadDependencyCaches(
409421

410422
try {
411423
const start = performance.now();
412-
await actionsCache.saveCache(cacheConfig.getDependencyPaths(), key);
424+
await actionsCache.saveCache(
425+
await cacheConfig.getDependencyPaths(codeql, features),
426+
key,
427+
);
413428
const upload_duration_ms = Math.round(performance.now() - start);
414429

415430
status.push({

0 commit comments

Comments
 (0)