Use supportsFeature check for merging SARIF files

This commit is contained in:
Koen Vlaswinkel 2024-03-22 14:14:34 +01:00
parent 2bbafcdd7f
commit e20c273295
9 changed files with 27 additions and 9 deletions

View file

@ -61,8 +61,7 @@ export const featureConfig: Record<
> = {
[Feature.CliSarifMerge]: {
envVar: "CODEQL_ACTION_CLI_SARIF_MERGE",
// This feature is only supported in 2.17.0, but we'll want to test this feature
// with nightly builds before that. We'll update this to 2.17.0 once it's released.
// This is guarded by a `supportsFeature` check rather than by a version check.
minimumVersion: undefined,
defaultValue: false,
},

View file

@ -6,6 +6,7 @@ export enum ToolsFeature {
InformsAboutUnsupportedPathFilters = "informsAboutUnsupportedPathFilters",
SetsCodeqlRunnerEnvVar = "setsCodeqlRunnerEnvVar",
TraceCommandUseBuildMode = "traceCommandUseBuildMode",
SarifMergeRunsFromEqualCategory = "sarifMergeRunsFromEqualCategory",
}
/**

View file

@ -19,13 +19,14 @@ import * as fingerprints from "./fingerprints";
import { initCodeQL } from "./init";
import { Logger } from "./logging";
import { parseRepositoryNwo, RepositoryNwo } from "./repository";
import { ToolsFeature } from "./tools-features";
import * as util from "./util";
import {
SarifFile,
ConfigurationError,
wrapError,
getRequiredEnvParam,
GitHubVersion,
SarifFile,
wrapError,
} from "./util";
const GENERIC_403_MSG =
@ -134,6 +135,18 @@ async function combineSarifFilesUsingCLI(
codeQL = initCodeQLResult.codeql;
}
if (
!(await codeQL.supportsFeature(
ToolsFeature.SarifMergeRunsFromEqualCategory,
))
) {
logger.warning(
"The CodeQL CLI does not support merging SARIF files. Merging files in the action.",
);
return combineSarifFiles(sarifFiles);
}
const baseTempDir = path.resolve(tempDir, "combined-sarif");
fs.mkdirSync(baseTempDir, { recursive: true });
const outputDirectory = fs.mkdtempSync(path.resolve(baseTempDir, "output-"));