Skip to content

Commit 2aa1f55

Browse files
committed
Propagate features into cachePrefix function
1 parent 1ca20ab commit 2aa1f55

File tree

7 files changed

+68
-47
lines changed

7 files changed

+68
-47
lines changed

lib/analyze-action.js

Lines changed: 12 additions & 11 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: 14 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/setup-codeql-action.js

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

lib/start-proxy-action.js

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

src/analyze-action.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,11 @@ async function run() {
438438

439439
// Store dependency cache(s) if dependency caching is enabled.
440440
if (shouldStoreCache(config.dependencyCachingEnabled)) {
441-
const minimizeJavaJars = await features.getValue(
442-
Feature.JavaMinimizeDependencyJars,
443-
codeql,
444-
);
445441
dependencyCacheResults = await uploadDependencyCaches(
442+
codeql,
443+
features,
446444
config,
447445
logger,
448-
minimizeJavaJars,
449446
);
450447
}
451448

src/dependency-caching.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import * as glob from "@actions/glob";
77
import { getTemporaryDirectory } from "./actions-util";
88
import { listActionsCaches } from "./api-client";
99
import { getTotalCacheSize } from "./caching-utils";
10+
import { CodeQL } from "./codeql";
1011
import { Config } from "./config-utils";
1112
import { EnvVar } from "./environment";
13+
import { Feature, Features } from "./feature-flags";
1214
import { KnownLanguage, Language } from "./languages";
1315
import { Logger } from "./logging";
1416
import { getErrorMessage, getRequiredEnvParam } from "./util";
@@ -110,15 +112,18 @@ export type DependencyCacheRestoreStatusReport = DependencyCacheRestoreStatus[];
110112
/**
111113
* Attempts to restore dependency caches for the languages being analyzed.
112114
*
115+
* @param codeql The CodeQL instance to use.
116+
* @param features Information about which FFs are enabled.
113117
* @param languages The languages being analyzed.
114118
* @param logger A logger to record some informational messages to.
115-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
119+
*
116120
* @returns An array of `DependencyCacheRestoreStatus` objects for each analysed language with a caching configuration.
117121
*/
118122
export async function downloadDependencyCaches(
123+
codeql: CodeQL,
124+
features: Features,
119125
languages: Language[],
120126
logger: Logger,
121-
minimizeJavaJars: boolean,
122127
): Promise<DependencyCacheRestoreStatusReport> {
123128
const status: DependencyCacheRestoreStatusReport = [];
124129

@@ -144,9 +149,9 @@ export async function downloadDependencyCaches(
144149
continue;
145150
}
146151

147-
const primaryKey = await cacheKey(language, cacheConfig, minimizeJavaJars);
152+
const primaryKey = await cacheKey(codeql, features, language, cacheConfig);
148153
const restoreKeys: string[] = [
149-
await cachePrefix(language, minimizeJavaJars),
154+
await cachePrefix(codeql, features, language),
150155
];
151156

152157
logger.info(
@@ -203,16 +208,18 @@ export type DependencyCacheUploadStatusReport = DependencyCacheUploadStatus[];
203208
/**
204209
* Attempts to store caches for the languages that were analyzed.
205210
*
211+
* @param codeql The CodeQL instance to use.
212+
* @param features Information about which FFs are enabled.
206213
* @param config The configuration for this workflow.
207214
* @param logger A logger to record some informational messages to.
208-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
209215
*
210216
* @returns An array of `DependencyCacheUploadStatus` objects for each analysed language with a caching configuration.
211217
*/
212218
export async function uploadDependencyCaches(
219+
codeql: CodeQL,
220+
features: Features,
213221
config: Config,
214222
logger: Logger,
215-
minimizeJavaJars: boolean,
216223
): Promise<DependencyCacheUploadStatusReport> {
217224
const status: DependencyCacheUploadStatusReport = [];
218225
for (const language of config.languages) {
@@ -258,7 +265,7 @@ export async function uploadDependencyCaches(
258265
continue;
259266
}
260267

261-
const key = await cacheKey(language, cacheConfig, minimizeJavaJars);
268+
const key = await cacheKey(codeql, features, language, cacheConfig);
262269

263270
logger.info(
264271
`Uploading cache of size ${size} for ${language} with key ${key}...`,
@@ -299,31 +306,35 @@ export async function uploadDependencyCaches(
299306
/**
300307
* Computes a cache key for the specified language.
301308
*
309+
* @param codeql The CodeQL instance to use.
310+
* @param features Information about which FFs are enabled.
302311
* @param language The language being analyzed.
303312
* @param cacheConfig The cache configuration for the language.
304-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
305313
* @returns A cache key capturing information about the project(s) being analyzed in the specified language.
306314
*/
307315
async function cacheKey(
316+
codeql: CodeQL,
317+
features: Features,
308318
language: Language,
309319
cacheConfig: CacheConfig,
310-
minimizeJavaJars: boolean = false,
311320
): Promise<string> {
312321
const hash = await glob.hashFiles(cacheConfig.hash.join("\n"));
313-
return `${await cachePrefix(language, minimizeJavaJars)}${hash}`;
322+
return `${await cachePrefix(codeql, features, language)}${hash}`;
314323
}
315324

316325
/**
317326
* Constructs a prefix for the cache key, comprised of a CodeQL-specific prefix, a version number that
318327
* can be changed to invalidate old caches, the runner's operating system, and the specified language name.
319328
*
329+
* @param codeql The CodeQL instance to use.
330+
* @param features Information about which FFs are enabled.
320331
* @param language The language being analyzed.
321-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
322332
* @returns The prefix that identifies what a cache is for.
323333
*/
324334
async function cachePrefix(
335+
codeql: CodeQL,
336+
features: Features,
325337
language: Language,
326-
minimizeJavaJars: boolean,
327338
): Promise<string> {
328339
const runnerOs = getRequiredEnvParam("RUNNER_OS");
329340
const customPrefix = process.env[EnvVar.DEPENDENCY_CACHING_PREFIX];
@@ -334,6 +345,10 @@ async function cachePrefix(
334345
}
335346

336347
// To ensure a safe rollout of JAR minimization, we change the key when the feature is enabled.
348+
const minimizeJavaJars = await features.getValue(
349+
Feature.JavaMinimizeDependencyJars,
350+
codeql,
351+
);
337352
if (language === KnownLanguage.java && minimizeJavaJars) {
338353
prefix = `minify-${prefix}`;
339354
}

src/init-action.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,12 @@ async function run() {
578578
}
579579

580580
// Restore dependency cache(s), if they exist.
581-
const minimizeJavaJars = await features.getValue(
582-
Feature.JavaMinimizeDependencyJars,
583-
codeql,
584-
);
585581
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
586582
dependencyCachingResults = await downloadDependencyCaches(
583+
codeql,
584+
features,
587585
config.languages,
588586
logger,
589-
minimizeJavaJars,
590587
);
591588
}
592589

@@ -648,7 +645,7 @@ async function run() {
648645
`${EnvVar.JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS} is already set to '${process.env[EnvVar.JAVA_EXTRACTOR_MINIMIZE_DEPENDENCY_JARS]}', so the Action will not override it.`,
649646
);
650647
} else if (
651-
minimizeJavaJars &&
648+
(await features.getValue(Feature.JavaMinimizeDependencyJars, codeql)) &&
652649
config.dependencyCachingEnabled &&
653650
config.buildMode === BuildMode.None &&
654651
config.languages.includes(KnownLanguage.java)

0 commit comments

Comments
 (0)