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:
24
lib/analyze-action-post.js
generated
24
lib/analyze-action-post.js
generated
@@ -120768,6 +120768,9 @@ var glob = __toESM(require_glob3());
|
|||||||
function getJavaTempDependencyDir() {
|
function getJavaTempDependencyDir() {
|
||||||
return (0, import_path.join)(getTemporaryDirectory(), "codeql_java", "repository");
|
return (0, import_path.join)(getTemporaryDirectory(), "codeql_java", "repository");
|
||||||
}
|
}
|
||||||
|
function getCsharpTempDependencyDir() {
|
||||||
|
return (0, import_path.join)(getTemporaryDirectory(), "codeql_csharp", "repository");
|
||||||
|
}
|
||||||
|
|
||||||
// src/debug-artifacts.ts
|
// src/debug-artifacts.ts
|
||||||
function sanitizeArtifactName(name) {
|
function sanitizeArtifactName(name) {
|
||||||
@@ -120888,14 +120891,19 @@ async function runWrapper() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const javaTempDependencyDir = getJavaTempDependencyDir();
|
const tempDependencyDirs = [
|
||||||
if (fs6.existsSync(javaTempDependencyDir)) {
|
getJavaTempDependencyDir(),
|
||||||
try {
|
getCsharpTempDependencyDir()
|
||||||
fs6.rmSync(javaTempDependencyDir, { recursive: true });
|
];
|
||||||
} catch (error4) {
|
for (const tempDependencyDir of tempDependencyDirs) {
|
||||||
logger.info(
|
if (fs6.existsSync(tempDependencyDir)) {
|
||||||
`Failed to remove temporary Java dependencies directory: ${getErrorMessage(error4)}`
|
try {
|
||||||
);
|
fs6.rmSync(tempDependencyDir, { recursive: true });
|
||||||
|
} catch (error4) {
|
||||||
|
logger.info(
|
||||||
|
`Failed to remove temporary dependencies directory: ${getErrorMessage(error4)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error4) {
|
} catch (error4) {
|
||||||
|
|||||||
13
lib/analyze-action.js
generated
13
lib/analyze-action.js
generated
@@ -91327,7 +91327,7 @@ async function setupPythonExtractor(logger) {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
async function runExtraction(codeql, config, logger) {
|
async function runExtraction(codeql, features, config, logger) {
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
if (dbIsFinalized(config, language, logger)) {
|
if (dbIsFinalized(config, language, logger)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -91347,6 +91347,9 @@ async function runExtraction(codeql, config, logger) {
|
|||||||
if (language === "java" /* java */ && config.buildMode === "none" /* None */) {
|
if (language === "java" /* java */ && config.buildMode === "none" /* None */) {
|
||||||
process.env["CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_DEPENDENCY_DIR"] = getJavaTempDependencyDir();
|
process.env["CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_DEPENDENCY_DIR"] = getJavaTempDependencyDir();
|
||||||
}
|
}
|
||||||
|
if (language === "csharp" /* csharp */ && config.buildMode === "none" /* None */ && await features.getValue("csharp_cache_bmn" /* CsharpCacheBuildModeNone */)) {
|
||||||
|
process.env["CODEQL_EXTRACTOR_CSHARP_OPTION_BUILDLESS_DEPENDENCY_DIR"] = getCsharpTempDependencyDir();
|
||||||
|
}
|
||||||
await codeql.extractUsingBuildMode(config, language);
|
await codeql.extractUsingBuildMode(config, language);
|
||||||
} else {
|
} else {
|
||||||
await codeql.extractScannedLanguage(config, language);
|
await codeql.extractScannedLanguage(config, language);
|
||||||
@@ -91372,9 +91375,9 @@ function dbIsFinalized(config, language, logger) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function finalizeDatabaseCreation(codeql, config, threadsFlag, memoryFlag, logger) {
|
async function finalizeDatabaseCreation(codeql, features, config, threadsFlag, memoryFlag, logger) {
|
||||||
const extractionStart = import_perf_hooks2.performance.now();
|
const extractionStart = import_perf_hooks2.performance.now();
|
||||||
await runExtraction(codeql, config, logger);
|
await runExtraction(codeql, features, config, logger);
|
||||||
const extractionTime = import_perf_hooks2.performance.now() - extractionStart;
|
const extractionTime = import_perf_hooks2.performance.now() - extractionStart;
|
||||||
const trapImportStart = import_perf_hooks2.performance.now();
|
const trapImportStart = import_perf_hooks2.performance.now();
|
||||||
for (const language of config.languages) {
|
for (const language of config.languages) {
|
||||||
@@ -91629,7 +91632,7 @@ async function runQueries(sarifFolder, memoryFlag, threadsFlag, diffRangePackDir
|
|||||||
return perQueryAlertCounts;
|
return perQueryAlertCounts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function runFinalize(outputDir, threadsFlag, memoryFlag, codeql, config, logger) {
|
async function runFinalize(features, outputDir, threadsFlag, memoryFlag, codeql, config, logger) {
|
||||||
try {
|
try {
|
||||||
await fs12.promises.rm(outputDir, { force: true, recursive: true });
|
await fs12.promises.rm(outputDir, { force: true, recursive: true });
|
||||||
} catch (error4) {
|
} catch (error4) {
|
||||||
@@ -91640,6 +91643,7 @@ async function runFinalize(outputDir, threadsFlag, memoryFlag, codeql, config, l
|
|||||||
await fs12.promises.mkdir(outputDir, { recursive: true });
|
await fs12.promises.mkdir(outputDir, { recursive: true });
|
||||||
const timings = await finalizeDatabaseCreation(
|
const timings = await finalizeDatabaseCreation(
|
||||||
codeql,
|
codeql,
|
||||||
|
features,
|
||||||
config,
|
config,
|
||||||
threadsFlag,
|
threadsFlag,
|
||||||
memoryFlag,
|
memoryFlag,
|
||||||
@@ -93974,6 +93978,7 @@ async function run() {
|
|||||||
await warnIfGoInstalledAfterInit(config, logger);
|
await warnIfGoInstalledAfterInit(config, logger);
|
||||||
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
||||||
dbCreationTimings = await runFinalize(
|
dbCreationTimings = await runFinalize(
|
||||||
|
features,
|
||||||
outputDir,
|
outputDir,
|
||||||
threads,
|
threads,
|
||||||
memory,
|
memory,
|
||||||
|
|||||||
@@ -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.
|
// wait for the action promise to complete before starting verification.
|
||||||
await analyzeAction.runPromise;
|
await analyzeAction.runPromise;
|
||||||
|
|
||||||
t.assert(runFinalizeStub.calledOnce);
|
t.assert(
|
||||||
t.deepEqual(runFinalizeStub.firstCall.args[1], "--threads=-1");
|
runFinalizeStub.calledOnceWith(
|
||||||
t.deepEqual(runFinalizeStub.firstCall.args[2], "--ram=4992");
|
sinon.match.any,
|
||||||
t.assert(runQueriesStub.calledOnce);
|
sinon.match.any,
|
||||||
t.deepEqual(runQueriesStub.firstCall.args[2], "--threads=-1");
|
"--threads=-1",
|
||||||
t.deepEqual(runQueriesStub.firstCall.args[1], "--ram=4992");
|
"--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.
|
// wait for the action promise to complete before starting verification.
|
||||||
await analyzeAction.runPromise;
|
await analyzeAction.runPromise;
|
||||||
|
|
||||||
t.assert(runFinalizeStub.calledOnce);
|
t.assert(
|
||||||
t.deepEqual(runFinalizeStub.firstCall.args[1], "--threads=-1");
|
runFinalizeStub.calledOnceWith(
|
||||||
t.deepEqual(runFinalizeStub.firstCall.args[2], "--ram=3012");
|
sinon.match.any,
|
||||||
t.assert(runQueriesStub.calledOnce);
|
sinon.match.any,
|
||||||
t.deepEqual(runQueriesStub.firstCall.args[2], "--threads=-1");
|
"--threads=-1",
|
||||||
t.deepEqual(runQueriesStub.firstCall.args[1], "--ram=3012");
|
"--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 { getCodeQL } from "./codeql";
|
||||||
import { getConfig } from "./config-utils";
|
import { getConfig } from "./config-utils";
|
||||||
import * as debugArtifacts from "./debug-artifacts";
|
import * as debugArtifacts from "./debug-artifacts";
|
||||||
import { getJavaTempDependencyDir } from "./dependency-caching";
|
import {
|
||||||
|
getCsharpTempDependencyDir,
|
||||||
|
getJavaTempDependencyDir,
|
||||||
|
} from "./dependency-caching";
|
||||||
import { EnvVar } from "./environment";
|
import { EnvVar } from "./environment";
|
||||||
import { getActionsLogger } from "./logging";
|
import { getActionsLogger } from "./logging";
|
||||||
import { checkGitHubVersionInRange, getErrorMessage } from "./util";
|
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
|
// to the temp directory. Clean these up so they don't persist unnecessarily
|
||||||
// long on self-hosted runners.
|
// long on self-hosted runners.
|
||||||
const javaTempDependencyDir = getJavaTempDependencyDir();
|
const tempDependencyDirs = [
|
||||||
if (fs.existsSync(javaTempDependencyDir)) {
|
getJavaTempDependencyDir(),
|
||||||
try {
|
getCsharpTempDependencyDir(),
|
||||||
fs.rmSync(javaTempDependencyDir, { recursive: true });
|
];
|
||||||
} catch (error) {
|
for (const tempDependencyDir of tempDependencyDirs) {
|
||||||
logger.info(
|
if (fs.existsSync(tempDependencyDir)) {
|
||||||
`Failed to remove temporary Java dependencies directory: ${getErrorMessage(error)}`,
|
try {
|
||||||
);
|
fs.rmSync(tempDependencyDir, { recursive: true });
|
||||||
|
} catch (error) {
|
||||||
|
logger.info(
|
||||||
|
`Failed to remove temporary dependencies directory: ${getErrorMessage(error)}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -315,6 +315,7 @@ async function run() {
|
|||||||
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
await runAutobuildIfLegacyGoWorkflow(config, logger);
|
||||||
|
|
||||||
dbCreationTimings = await runFinalize(
|
dbCreationTimings = await runFinalize(
|
||||||
|
features,
|
||||||
outputDir,
|
outputDir,
|
||||||
threads,
|
threads,
|
||||||
memory,
|
memory,
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ import * as analyses from "./analyses";
|
|||||||
import { setupCppAutobuild } from "./autobuild";
|
import { setupCppAutobuild } from "./autobuild";
|
||||||
import { type CodeQL } from "./codeql";
|
import { type CodeQL } from "./codeql";
|
||||||
import * as configUtils from "./config-utils";
|
import * as configUtils from "./config-utils";
|
||||||
import { getJavaTempDependencyDir } from "./dependency-caching";
|
import {
|
||||||
|
getCsharpTempDependencyDir,
|
||||||
|
getJavaTempDependencyDir,
|
||||||
|
} from "./dependency-caching";
|
||||||
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
|
import { addDiagnostic, makeDiagnostic } from "./diagnostics";
|
||||||
import {
|
import {
|
||||||
DiffThunkRange,
|
DiffThunkRange,
|
||||||
@@ -98,6 +101,7 @@ async function setupPythonExtractor(logger: Logger) {
|
|||||||
|
|
||||||
export async function runExtraction(
|
export async function runExtraction(
|
||||||
codeql: CodeQL,
|
codeql: CodeQL,
|
||||||
|
features: FeatureEnablement,
|
||||||
config: configUtils.Config,
|
config: configUtils.Config,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
) {
|
) {
|
||||||
@@ -122,7 +126,7 @@ export async function runExtraction(
|
|||||||
await setupCppAutobuild(codeql, logger);
|
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
|
// 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
|
// 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).
|
// 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"] =
|
process.env["CODEQL_EXTRACTOR_JAVA_OPTION_BUILDLESS_DEPENDENCY_DIR"] =
|
||||||
getJavaTempDependencyDir();
|
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);
|
await codeql.extractUsingBuildMode(config, language);
|
||||||
} else {
|
} else {
|
||||||
@@ -177,13 +190,14 @@ export function dbIsFinalized(
|
|||||||
|
|
||||||
async function finalizeDatabaseCreation(
|
async function finalizeDatabaseCreation(
|
||||||
codeql: CodeQL,
|
codeql: CodeQL,
|
||||||
|
features: FeatureEnablement,
|
||||||
config: configUtils.Config,
|
config: configUtils.Config,
|
||||||
threadsFlag: string,
|
threadsFlag: string,
|
||||||
memoryFlag: string,
|
memoryFlag: string,
|
||||||
logger: Logger,
|
logger: Logger,
|
||||||
): Promise<DatabaseCreationTimings> {
|
): Promise<DatabaseCreationTimings> {
|
||||||
const extractionStart = performance.now();
|
const extractionStart = performance.now();
|
||||||
await runExtraction(codeql, config, logger);
|
await runExtraction(codeql, features, config, logger);
|
||||||
const extractionTime = performance.now() - extractionStart;
|
const extractionTime = performance.now() - extractionStart;
|
||||||
|
|
||||||
const trapImportStart = performance.now();
|
const trapImportStart = performance.now();
|
||||||
@@ -597,6 +611,7 @@ export async function runQueries(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function runFinalize(
|
export async function runFinalize(
|
||||||
|
features: FeatureEnablement,
|
||||||
outputDir: string,
|
outputDir: string,
|
||||||
threadsFlag: string,
|
threadsFlag: string,
|
||||||
memoryFlag: string,
|
memoryFlag: string,
|
||||||
@@ -615,6 +630,7 @@ export async function runFinalize(
|
|||||||
|
|
||||||
const timings = await finalizeDatabaseCreation(
|
const timings = await finalizeDatabaseCreation(
|
||||||
codeql,
|
codeql,
|
||||||
|
features,
|
||||||
config,
|
config,
|
||||||
threadsFlag,
|
threadsFlag,
|
||||||
memoryFlag,
|
memoryFlag,
|
||||||
|
|||||||
Reference in New Issue
Block a user