mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 09:18:47 +00:00
Include getCsharpTempDependencyDir in C# caches if FF is enabled
This commit is contained in:
@@ -20,6 +20,8 @@ import {
|
||||
downloadDependencyCaches,
|
||||
CacheHitKind,
|
||||
cacheKey,
|
||||
getCsharpDependencyDirs,
|
||||
getCsharpTempDependencyDir,
|
||||
} from "./dependency-caching";
|
||||
import { Feature } from "./feature-flags";
|
||||
import { KnownLanguage } from "./languages";
|
||||
@@ -38,6 +40,28 @@ function makeAbsolutePatterns(tmpDir: string, patterns: string[]): string[] {
|
||||
return patterns.map((pattern) => path.join(tmpDir, pattern));
|
||||
}
|
||||
|
||||
test("getCsharpDependencyDirs - does not include BMN dir if FF is enabled", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
process.env["RUNNER_TEMP"] = tmpDir;
|
||||
const codeql = createStubCodeQL({});
|
||||
const features = createFeatures([]);
|
||||
|
||||
const results = await getCsharpDependencyDirs(codeql, features);
|
||||
t.false(results.includes(getCsharpTempDependencyDir()));
|
||||
});
|
||||
});
|
||||
|
||||
test("getCsharpDependencyDirs - includes BMN dir if FF is enabled", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
process.env["RUNNER_TEMP"] = tmpDir;
|
||||
const codeql = createStubCodeQL({});
|
||||
const features = createFeatures([Feature.CsharpCacheBuildModeNone]);
|
||||
|
||||
const results = await getCsharpDependencyDirs(codeql, features);
|
||||
t.assert(results.includes(getCsharpTempDependencyDir()));
|
||||
});
|
||||
});
|
||||
|
||||
test("makePatternCheck - returns undefined if no patterns match", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
fs.writeFileSync(path.join(tmpDir, "test.java"), "");
|
||||
@@ -387,3 +411,28 @@ test("getFeaturePrefix - non-C# - returns '' if CsharpNewCacheKey is enabled", a
|
||||
t.deepEqual(result, "", `Expected no feature prefix for ${knownLanguage}`);
|
||||
}
|
||||
});
|
||||
|
||||
test("getFeaturePrefix - C# - returns prefix if CsharpCacheBuildModeNone is enabled", async (t) => {
|
||||
const codeql = createStubCodeQL({});
|
||||
const features = createFeatures([Feature.CsharpCacheBuildModeNone]);
|
||||
|
||||
const result = await getFeaturePrefix(codeql, features, KnownLanguage.csharp);
|
||||
t.notDeepEqual(result, "");
|
||||
t.assert(result.endsWith("-"));
|
||||
// Check the length of the prefix, which should correspond to `cacheKeyHashLength` + 1 for the trailing `-`.
|
||||
t.is(result.length, cacheKeyHashLength + 1);
|
||||
});
|
||||
|
||||
test("getFeaturePrefix - non-C# - returns '' if CsharpCacheBuildModeNone is enabled", async (t) => {
|
||||
const codeql = createStubCodeQL({});
|
||||
const features = createFeatures([Feature.CsharpCacheBuildModeNone]);
|
||||
|
||||
for (const knownLanguage of Object.values(KnownLanguage)) {
|
||||
// Skip C# since we expect a result for it, which is tested in the previous test.
|
||||
if (knownLanguage === KnownLanguage.csharp) {
|
||||
continue;
|
||||
}
|
||||
const result = await getFeaturePrefix(codeql, features, knownLanguage);
|
||||
t.deepEqual(result, "", `Expected no feature prefix for ${knownLanguage}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -85,8 +85,20 @@ export function getCsharpTempDependencyDir(): string {
|
||||
* @returns The paths of directories on the runner that should be included in a dependency cache
|
||||
* for a C# analysis.
|
||||
*/
|
||||
export async function getCsharpDependencyDirs(): Promise<string[]> {
|
||||
return [join(os.homedir(), ".nuget", "packages")];
|
||||
export async function getCsharpDependencyDirs(
|
||||
codeql: CodeQL,
|
||||
features: FeatureEnablement,
|
||||
): Promise<string[]> {
|
||||
const dirs = [
|
||||
// Nuget
|
||||
join(os.homedir(), ".nuget", "packages"),
|
||||
];
|
||||
|
||||
if (await features.getValue(Feature.CsharpCacheBuildModeNone, codeql)) {
|
||||
dirs.push(getCsharpTempDependencyDir());
|
||||
}
|
||||
|
||||
return dirs;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -512,6 +524,7 @@ export async function getFeaturePrefix(
|
||||
}
|
||||
} else if (language === KnownLanguage.csharp) {
|
||||
await addFeatureIfEnabled(Feature.CsharpNewCacheKey);
|
||||
await addFeatureIfEnabled(Feature.CsharpCacheBuildModeNone);
|
||||
}
|
||||
|
||||
// If any features that affect the cache are enabled, return a feature prefix by
|
||||
|
||||
Reference in New Issue
Block a user