Skip to content

Commit

Permalink
Remove flags for CLI v2.6.2 and earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Nov 11, 2022
1 parent b45e925 commit ea990a3
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 126 deletions.
38 changes: 3 additions & 35 deletions lib/analyze.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/analyze.js.map

Large diffs are not rendered by default.

23 changes: 6 additions & 17 deletions lib/codeql.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/codeql.js.map

Large diffs are not rendered by default.

58 changes: 4 additions & 54 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import * as yaml from "js-yaml";

import { DatabaseCreationTimings } from "./actions-util";
import * as analysisPaths from "./analysis-paths";
import {
CodeQL,
CODEQL_VERSION_COUNTS_LINES,
CODEQL_VERSION_NEW_TRACING,
getCodeQL,
} from "./codeql";
import { CodeQL, CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { countLoc } from "./count-loc";
import { FeatureEnablement } from "./feature-flags";
Expand Down Expand Up @@ -221,10 +216,9 @@ export async function runQueries(
let locPromise: Promise<Partial<Record<Language, number>>> = Promise.resolve(
{}
);
const cliCanCountBaseline = await cliCanCountLoC();
const countLocDebugMode =
process.env["INTERNAL_CODEQL_ACTION_DEBUG_LOC"] || config.debugMode;
if (!cliCanCountBaseline || countLocDebugMode) {
if (countLocDebugMode) {
// count the number of lines in the background
locPromise = countLoc(
path.resolve(),
Expand Down Expand Up @@ -346,20 +340,15 @@ export async function runQueries(
sarifFile,
config.debugMode
);
if (!cliCanCountBaseline) {
await injectLinesOfCode(sarifFile, language, locPromise);
}
statusReport[`interpret_results_${language}_duration_ms`] =
new Date().getTime() - startTimeInterpretResults;
logger.endGroup();
logger.info(analysisSummary);
}
if (!cliCanCountBaseline || countLocDebugMode) {
if (countLocDebugMode) {
printLinesOfCodeSummary(logger, language, await locPromise);
}
if (cliCanCountBaseline) {
logger.info(await runPrintLinesOfCode(language));
}
logger.info(await runPrintLinesOfCode(language));
} catch (e) {
logger.info(String(e));
if (e instanceof Error) {
Expand Down Expand Up @@ -394,13 +383,6 @@ export async function runQueries(
);
}

async function cliCanCountLoC() {
return await util.codeQlVersionAbove(
await getCodeQL(config.codeQLCmd),
CODEQL_VERSION_COUNTS_LINES
);
}

async function runPrintLinesOfCode(language: Language): Promise<string> {
const databasePath = util.getCodeQLDatabasePath(config, language);
return await codeql.databasePrintBaseline(databasePath);
Expand Down Expand Up @@ -554,38 +536,6 @@ export async function runCleanup(
logger.endGroup();
}

async function injectLinesOfCode(
sarifFile: string,
language: Language,
locPromise: Promise<Partial<Record<Language, number>>>
) {
const lineCounts = await locPromise;
if (language in lineCounts) {
const sarif = JSON.parse(fs.readFileSync(sarifFile, "utf8"));

if (Array.isArray(sarif.runs)) {
for (const run of sarif.runs) {
run.properties = run.properties || {};
run.properties.metricResults = run.properties.metricResults || [];
for (const metric of run.properties.metricResults) {
// Baseline is inserted when matching rule has tag lines-of-code
if (metric.rule && metric.rule.toolComponent) {
const matchingRule =
run.tool.extensions[metric.rule.toolComponent.index].rules[
metric.rule.index
];
if (matchingRule.properties.tags?.includes("lines-of-code")) {
metric.baseline = lineCounts[language];
}
}
}
}
}

fs.writeFileSync(sarifFile, JSON.stringify(sarif));
}
}

function printLinesOfCodeSummary(
logger: Logger,
language: Language,
Expand Down
23 changes: 5 additions & 18 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,6 @@ const CODEQL_MINIMUM_VERSION = "2.6.3";
* For convenience, please keep these in descending order. Once a version
* flag is older than the oldest supported version above, it may be removed.
*/
const CODEQL_VERSION_RAM_FINALIZE = "2.5.8";
const CODEQL_VERSION_DIAGNOSTICS = "2.5.6";
const CODEQL_VERSION_METRICS = "2.5.5";
const CODEQL_VERSION_GROUP_RULES = "2.5.5";
const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
export const CODEQL_VERSION_COUNTS_LINES = "2.6.2";
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
const CODEQL_VERSION_LUA_TRACER_CONFIG = "2.10.0";
export const CODEQL_VERSION_CONFIG_FILES = "2.10.1";
Expand Down Expand Up @@ -970,11 +964,10 @@ async function getCodeQLForCmd(
"finalize",
"--finalize-dataset",
threadsFlag,
memoryFlag,
...getExtraOptionsFromEnv(["database", "finalize"]),
databasePath,
];
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_RAM_FINALIZE))
args.push(memoryFlag);
await toolrunnerErrorCatcher(cmd, args, errorMatchers);
},
async resolveLanguages() {
Expand Down Expand Up @@ -1077,20 +1070,14 @@ async function getCodeQLForCmd(
verbosityFlag,
`--output=${sarifFile}`,
addSnippetsFlag,
"--print-diagnostics-summary",
"--print-metrics-summary",
"--sarif-group-rules-by-pack",
...getExtraOptionsFromEnv(["database", "interpret-results"]),
];
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_DIAGNOSTICS))
codeqlArgs.push("--print-diagnostics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_METRICS))
codeqlArgs.push("--print-metrics-summary");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_GROUP_RULES))
codeqlArgs.push("--sarif-group-rules-by-pack");
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_CUSTOM_QUERY_HELP))
codeqlArgs.push("--sarif-add-query-help");
if (
automationDetailsId !== undefined &&
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))
) {
if (automationDetailsId !== undefined) {
codeqlArgs.push("--sarif-category", automationDetailsId);
}
if (
Expand Down

0 comments on commit ea990a3

Please sign in to comment.