mirror of
https://github.com/github/codeql-action.git
synced 2025-12-06 07:48:17 +08:00
Configure temp dependency dir for C# extractor when FF is enabled
And also clean it up.
This commit is contained in:
@@ -74,11 +74,20 @@ test("analyze action with RAM & threads from environment variables", async (t) =
|
||||
// wait for the action promise to complete before starting verification.
|
||||
await analyzeAction.runPromise;
|
||||
|
||||
t.assert(runFinalizeStub.calledOnce);
|
||||
t.deepEqual(runFinalizeStub.firstCall.args[1], "--threads=-1");
|
||||
t.deepEqual(runFinalizeStub.firstCall.args[2], "--ram=4992");
|
||||
t.assert(runQueriesStub.calledOnce);
|
||||
t.deepEqual(runQueriesStub.firstCall.args[2], "--threads=-1");
|
||||
t.deepEqual(runQueriesStub.firstCall.args[1], "--ram=4992");
|
||||
t.assert(
|
||||
runFinalizeStub.calledOnceWith(
|
||||
sinon.match.any,
|
||||
sinon.match.any,
|
||||
"--threads=-1",
|
||||
"--ram=4992",
|
||||
),
|
||||
);
|
||||
t.assert(
|
||||
runQueriesStub.calledOnceWith(
|
||||
sinon.match.any,
|
||||
"--ram=4992",
|
||||
"--threads=-1",
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,11 +72,20 @@ test("analyze action with RAM & threads from action inputs", async (t) => {
|
||||
// wait for the action promise to complete before starting verification.
|
||||
await analyzeAction.runPromise;
|
||||
|
||||
t.assert(runFinalizeStub.calledOnce);
|
||||
t.deepEqual(runFinalizeStub.firstCall.args[1], "--threads=-1");
|
||||
t.deepEqual(runFinalizeStub.firstCall.args[2], "--ram=3012");
|
||||
t.assert(runQueriesStub.calledOnce);
|
||||
t.deepEqual(runQueriesStub.firstCall.args[2], "--threads=-1");
|
||||
t.deepEqual(runQueriesStub.firstCall.args[1], "--ram=3012");
|
||||
t.assert(
|
||||
runFinalizeStub.calledOnceWith(
|
||||
sinon.match.any,
|
||||
sinon.match.any,
|
||||
"--threads=-1",
|
||||
"--ram=3012",
|
||||
),
|
||||
);
|
||||
t.assert(
|
||||
runQueriesStub.calledOnceWith(
|
||||
sinon.match.any,
|
||||
"--ram=3012",
|
||||
"--threads=-1",
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,7 +12,10 @@ import { getGitHubVersion } from "./api-client";
|
||||
import { getCodeQL } from "./codeql";
|
||||
import { getConfig } from "./config-utils";
|
||||
import * as debugArtifacts from "./debug-artifacts";
|
||||
import { getJavaTempDependencyDir } from "./dependency-caching";
|
||||
import {
|
||||
getCsharpTempDependencyDir,
|
||||
getJavaTempDependencyDir,
|
||||
} from "./dependency-caching";
|
||||
import { EnvVar } from "./environment";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { checkGitHubVersionInRange, getErrorMessage } from "./util";
|
||||
@@ -42,17 +45,22 @@ async function runWrapper() {
|
||||
}
|
||||
}
|
||||
|
||||
// If we analysed Java in build-mode: none, we may have downloaded dependencies
|
||||
// If we analysed Java or C# in build-mode: none, we may have downloaded dependencies
|
||||
// to the temp directory. Clean these up so they don't persist unnecessarily
|
||||
// long on self-hosted runners.
|
||||
const javaTempDependencyDir = getJavaTempDependencyDir();
|
||||
if (fs.existsSync(javaTempDependencyDir)) {
|
||||
try {
|
||||
fs.rmSync(javaTempDependencyDir, { recursive: true });
|
||||
} catch (error) {
|
||||
logger.info(
|
||||
`Failed to remove temporary Java dependencies directory: ${getErrorMessage(error)}`,
|
||||
);
|
||||
const tempDependencyDirs = [
|
||||
getJavaTempDependencyDir(),
|
||||
getCsharpTempDependencyDir(),
|
||||
];
|
||||
for (const tempDependencyDir of tempDependencyDirs) {
|
||||
if (fs.existsSync(tempDependencyDir)) {
|
||||
try {
|
||||
fs.rmSync(tempDependencyDir, { recursive: true });
|
||||
} catch (error) {
|
||||
logger.info(
|
||||
`Failed to remove temporary dependencies directory: ${getErrorMessage(error)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -315,6 +315,7 @@ async function run() {
|
||||
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
||||
|
||||
dbCreationTimings = await runFinalize(
|
||||
features,
|
||||
outputDir,
|
||||
threads,
|
||||
memory,
|
||||
|
||||
@@ -10,7 +10,10 @@ import * as analyses from "./analyses";
|
||||
import { setupCppAutobuild } from "./autobuild";
|
||||
import { type CodeQL } from "./codeql";
|
||||
import * as configUtils from "./config-utils";
|
||||
import { getJavaTempDependencyDir } from "./dependency-caching";
|
||||
import {
|
||||
getCsharpTempDependencyDir,
|
||||
getJavaTempDependencyDir,
|
||||
} from "./dependency-caching";
|
||||
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
|
||||
import {
|
||||
DiffThunkRange,
|
||||
@@ -98,6 +101,7 @@ async function setupPythonExtractor(logger: Logger) {
|
||||
|
||||
export async function runExtraction(
|
||||
codeql: CodeQL,
|
||||
features: FeatureEnablement,
|
||||
config: configUtils.Config,
|
||||
logger: Logger,
|
||||
) {
|
||||
@@ -122,7 +126,7 @@ export async function runExtraction(
|
||||
await setupCppAutobuild(codeql, logger);
|
||||
}
|
||||
|
||||
// The Java `build-mode: none` extractor places dependencies (.jar files) in the
|
||||
// The Java and C# `build-mode: none` extractors place dependencies in the
|
||||
// database scratch directory by default. For dependency caching purposes, we want
|
||||
// a stable path that caches can be restored into and that we can cache at the
|
||||
// end of the workflow (i.e. that does not get removed when the scratch directory is).
|
||||
@@ -133,6 +137,15 @@ export async function runExtraction(
|
||||
process.env["CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_DEPENDENCY_DIR"] =
|
||||
getJavaTempDependencyDir();
|
||||
}
|
||||
if (
|
||||
language === KnownLanguage.csharp &&
|
||||
config.buildMode === BuildMode.None &&
|
||||
(await features.getValue(Feature.CsharpCacheBuildModeNone))
|
||||
) {
|
||||
process.env[
|
||||
"CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS_DEPENDENCY_DIR"
|
||||
] = getCsharpTempDependencyDir();
|
||||
}
|
||||
|
||||
await codeql.extractUsingBuildMode(config, language);
|
||||
} else {
|
||||
@@ -177,13 +190,14 @@ export function dbIsFinalized(
|
||||
|
||||
async function finalizeDatabaseCreation(
|
||||
codeql: CodeQL,
|
||||
features: FeatureEnablement,
|
||||
config: configUtils.Config,
|
||||
threadsFlag: string,
|
||||
memoryFlag: string,
|
||||
logger: Logger,
|
||||
): Promise<DatabaseCreationTimings> {
|
||||
const extractionStart = performance.now();
|
||||
await runExtraction(codeql, config, logger);
|
||||
await runExtraction(codeql, features, config, logger);
|
||||
const extractionTime = performance.now() - extractionStart;
|
||||
|
||||
const trapImportStart = performance.now();
|
||||
@@ -597,6 +611,7 @@ export async function runQueries(
|
||||
}
|
||||
|
||||
export async function runFinalize(
|
||||
features: FeatureEnablement,
|
||||
outputDir: string,
|
||||
threadsFlag: string,
|
||||
memoryFlag: string,
|
||||
@@ -615,6 +630,7 @@ export async function runFinalize(
|
||||
|
||||
const timings = await finalizeDatabaseCreation(
|
||||
codeql,
|
||||
features,
|
||||
config,
|
||||
threadsFlag,
|
||||
memoryFlag,
|
||||
|
||||
Reference in New Issue
Block a user