Skip to content

Commit 8ea9aef

Browse files
committed
Propagate features into cachePrefix function
1 parent 71654c1 commit 8ea9aef

File tree

5 files changed

+55
-47
lines changed

5 files changed

+55
-47
lines changed

lib/analyze-action.js

Lines changed: 10 additions & 10 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.

src/analyze-action.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { uploadDatabases } from "./database-upload";
2929
import { uploadDependencyCaches } from "./dependency-caching";
3030
import { getDiffInformedAnalysisBranches } from "./diff-informed-analysis-utils";
3131
import { EnvVar } from "./environment";
32-
import { Feature, Features } from "./feature-flags";
32+
import { Features } from "./feature-flags";
3333
import { KnownLanguage } from "./languages";
3434
import { getActionsLogger, Logger } from "./logging";
3535
import { uploadOverlayBaseDatabaseToCache } from "./overlay-database-utils";
@@ -384,11 +384,7 @@ async function run() {
384384

385385
// Store dependency cache(s) if dependency caching is enabled.
386386
if (shouldStoreCache(config.dependencyCachingEnabled)) {
387-
const minimizeJavaJars = await features.getValue(
388-
Feature.JavaMinimizeDependencyJars,
389-
codeql,
390-
);
391-
await uploadDependencyCaches(config, logger, minimizeJavaJars);
387+
await uploadDependencyCaches(codeql, features, config, logger);
392388
}
393389

394390
// We don't upload results in test mode, so don't wait for processing

src/dependency-caching.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import * as glob from "@actions/glob";
66

77
import { getTemporaryDirectory } from "./actions-util";
88
import { getTotalCacheSize } from "./caching-utils";
9+
import { CodeQL } from "./codeql";
910
import { Config } from "./config-utils";
1011
import { EnvVar } from "./environment";
12+
import { Feature, Features } from "./feature-flags";
1113
import { KnownLanguage, Language } from "./languages";
1214
import { Logger } from "./logging";
1315
import { getRequiredEnvParam } from "./util";
@@ -87,15 +89,17 @@ async function makeGlobber(patterns: string[]): Promise<glob.Globber> {
8789
/**
8890
* Attempts to restore dependency caches for the languages being analyzed.
8991
*
92+
* @param codeql The CodeQL instance to use.
93+
* @param features Information about which FFs are enabled.
9094
* @param languages The languages being analyzed.
9195
* @param logger A logger to record some informational messages to.
92-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
9396
* @returns A list of languages for which dependency caches were restored.
9497
*/
9598
export async function downloadDependencyCaches(
99+
codeql: CodeQL,
100+
features: Features,
96101
languages: Language[],
97102
logger: Logger,
98-
minimizeJavaJars: boolean,
99103
): Promise<Language[]> {
100104
const restoredCaches: Language[] = [];
101105

@@ -120,9 +124,9 @@ export async function downloadDependencyCaches(
120124
continue;
121125
}
122126

123-
const primaryKey = await cacheKey(language, cacheConfig, minimizeJavaJars);
127+
const primaryKey = await cacheKey(codeql, features, language, cacheConfig);
124128
const restoreKeys: string[] = [
125-
await cachePrefix(language, minimizeJavaJars),
129+
await cachePrefix(codeql, features, language),
126130
];
127131

128132
logger.info(
@@ -151,14 +155,16 @@ export async function downloadDependencyCaches(
151155
/**
152156
* Attempts to store caches for the languages that were analyzed.
153157
*
158+
* @param codeql The CodeQL instance to use.
159+
* @param features Information about which FFs are enabled.
154160
* @param config The configuration for this workflow.
155161
* @param logger A logger to record some informational messages to.
156-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
157162
*/
158163
export async function uploadDependencyCaches(
164+
codeql: CodeQL,
165+
features: Features,
159166
config: Config,
160167
logger: Logger,
161-
minimizeJavaJars: boolean,
162168
): Promise<void> {
163169
for (const language of config.languages) {
164170
const cacheConfig = getDefaultCacheConfig()[language];
@@ -201,7 +207,7 @@ export async function uploadDependencyCaches(
201207
continue;
202208
}
203209

204-
const key = await cacheKey(language, cacheConfig, minimizeJavaJars);
210+
const key = await cacheKey(codeql, features, language, cacheConfig);
205211

206212
logger.info(
207213
`Uploading cache of size ${size} for ${language} with key ${key}...`,
@@ -229,31 +235,35 @@ export async function uploadDependencyCaches(
229235
/**
230236
* Computes a cache key for the specified language.
231237
*
238+
* @param codeql The CodeQL instance to use.
239+
* @param features Information about which FFs are enabled.
232240
* @param language The language being analyzed.
233241
* @param cacheConfig The cache configuration for the language.
234-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
235242
* @returns A cache key capturing information about the project(s) being analyzed in the specified language.
236243
*/
237244
async function cacheKey(
245+
codeql: CodeQL,
246+
features: Features,
238247
language: Language,
239248
cacheConfig: CacheConfig,
240-
minimizeJavaJars: boolean = false,
241249
): Promise<string> {
242250
const hash = await glob.hashFiles(cacheConfig.hash.join("\n"));
243-
return `${await cachePrefix(language, minimizeJavaJars)}${hash}`;
251+
return `${await cachePrefix(codeql, features, language)}${hash}`;
244252
}
245253

246254
/**
247255
* Constructs a prefix for the cache key, comprised of a CodeQL-specific prefix, a version number that
248256
* can be changed to invalidate old caches, the runner's operating system, and the specified language name.
249257
*
258+
* @param codeql The CodeQL instance to use.
259+
* @param features Information about which FFs are enabled.
250260
* @param language The language being analyzed.
251-
* @param minimizeJavaJars Whether the Java extractor should rewrite downloaded JARs to minimize their size.
252261
* @returns The prefix that identifies what a cache is for.
253262
*/
254263
async function cachePrefix(
264+
codeql: CodeQL,
265+
features: Features,
255266
language: Language,
256-
minimizeJavaJars: boolean,
257267
): Promise<string> {
258268
const runnerOs = getRequiredEnvParam("RUNNER_OS");
259269
const customPrefix = process.env[EnvVar.DEPENDENCY_CACHING_PREFIX];
@@ -264,6 +274,10 @@ async function cachePrefix(
264274
}
265275

266276
// To ensure a safe rollout of JAR minimization, we change the key when the feature is enabled.
277+
const minimizeJavaJars = await features.getValue(
278+
Feature.JavaMinimizeDependencyJars,
279+
codeql,
280+
);
267281
if (language === KnownLanguage.java && minimizeJavaJars) {
268282
prefix = `minify-${prefix}`;
269283
}

src/init-action.ts

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

549549
// Restore dependency cache(s), if they exist.
550-
const minimizeJavaJars = await features.getValue(
551-
Feature.JavaMinimizeDependencyJars,
552-
codeql,
553-
);
554550
if (shouldRestoreCache(config.dependencyCachingEnabled)) {
555551
await downloadDependencyCaches(
552+
codeql,
553+
features,
556554
config.languages,
557555
logger,
558-
minimizeJavaJars,
559556
);
560557
}
561558

@@ -617,7 +614,7 @@ async function run() {
617614
`${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.`,
618615
);
619616
} else if (
620-
minimizeJavaJars &&
617+
(await features.getValue(Feature.JavaMinimizeDependencyJars, codeql)) &&
621618
config.dependencyCachingEnabled &&
622619
config.buildMode === BuildMode.None &&
623620
config.languages.includes(KnownLanguage.java)

0 commit comments

Comments
 (0)