Skip to content

Commit

Permalink
Use supportsFeature check for merging SARIF files
Browse files Browse the repository at this point in the history
  • Loading branch information
koesie10 committed Mar 22, 2024
1 parent 2bbafcd commit e20c273
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 9 deletions.
3 changes: 1 addition & 2 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/tools-features.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tools-features.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions lib/upload-lib.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/upload-lib.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
1 change: 1 addition & 0 deletions src/tools-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum ToolsFeature {
InformsAboutUnsupportedPathFilters = "informsAboutUnsupportedPathFilters",
SetsCodeqlRunnerEnvVar = "setsCodeqlRunnerEnvVar",
TraceCommandUseBuildMode = "traceCommandUseBuildMode",
SarifMergeRunsFromEqualCategory = "sarifMergeRunsFromEqualCategory",
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/upload-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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-"));
Expand Down

0 comments on commit e20c273

Please sign in to comment.