Skip to content

Commit

Permalink
Use --codescanning-config flag of CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardopirovano committed Feb 11, 2022
1 parent 3d2ad0b commit 682e7e7
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 21 deletions.
27 changes: 21 additions & 6 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.

5 changes: 5 additions & 0 deletions lib/codeql.js.map.orig

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/init.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/init.js.map

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

35 changes: 25 additions & 10 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import * as path from "path";
import * as toolrunner from "@actions/exec/lib/toolrunner";
import { IHeaders } from "@actions/http-client/interfaces";
import { default as deepEqual } from "fast-deep-equal";
import * as yaml from "js-yaml";
import { default as queryString } from "query-string";
import * as semver from "semver";

import { isRunningLocalAction, getRelativeScriptPath } from "./actions-util";
import * as api from "./api-client";
import { PackWithVersion } from "./config-utils";
import { Config, PackWithVersion } from "./config-utils";
import * as defaults from "./defaults.json"; // Referenced from codeql-action-sync-tool!
import { errorMatchers } from "./error-matcher";
import { isTracedLanguage, Language } from "./languages";
Expand Down Expand Up @@ -80,8 +81,7 @@ export interface CodeQL {
* Run 'codeql database init --db-cluster'.
*/
databaseInitCluster(
databasePath: string,
languages: Language[],
config: Config,
sourceRoot: string,
processName: string | undefined,
processLevel: number | undefined
Expand Down Expand Up @@ -219,6 +219,7 @@ 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_CONFIG_FILES = "2.7.3";
export const CODEQL_VERSION_ML_POWERED_QUERIES = "2.7.5";

/**
Expand Down Expand Up @@ -691,26 +692,35 @@ async function getCodeQLForCmd(
]);
},
async databaseInitCluster(
databasePath: string,
languages: Language[],
config: Config,
sourceRoot: string,
processName: string | undefined,
processLevel: number | undefined
) {
const extraArgs = languages.map((language) => `--language=${language}`);
if (languages.filter(isTracedLanguage).length > 0) {
const extraArgs = config.languages.map(
(language) => `--language=${language}`
);
if (config.languages.filter(isTracedLanguage).length > 0) {
extraArgs.push("--begin-tracing");
if (processName !== undefined) {
extraArgs.push(`--trace-process-name=${processName}`);
} else {
// We default to 3 if no other arguments are provided since this was the default
// behaviour of the Runner. Note this path never happens in the CodeQL Action
// because that always passes in a process name.
extraArgs.push(`--trace-process-level=${processLevel || 3}`);
}
}
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_CONFIG_FILES)) {
const configLocation = path.resolve(config.tempDir, "user-config.yaml");
fs.writeFileSync(configLocation, yaml.dump(config.originalUserInput));
extraArgs.push(`--codescanning-config=${configLocation}`);
}
await runTool(cmd, [
"database",
"init",
"--db-cluster",
databasePath,
config.dbLocation,
`--source-root=${sourceRoot}`,
...extraArgs,
...getExtraOptionsFromEnv(["database", "init"]),
Expand Down Expand Up @@ -863,7 +873,9 @@ async function getCodeQLForCmd(
if (extraSearchPath !== undefined) {
codeqlArgs.push("--additional-packs", extraSearchPath);
}
codeqlArgs.push(querySuitePath);
if (!(await util.codeQlVersionAbove(this, CODEQL_VERSION_CONFIG_FILES))) {
codeqlArgs.push(querySuitePath);
}
await runTool(cmd, codeqlArgs);
},
async databaseInterpretResults(
Expand Down Expand Up @@ -898,7 +910,10 @@ async function getCodeQLForCmd(
) {
codeqlArgs.push("--sarif-category", automationDetailsId);
}
codeqlArgs.push(databasePath, ...querySuitePaths);
codeqlArgs.push(databasePath);
if (!(await util.codeQlVersionAbove(this, CODEQL_VERSION_CONFIG_FILES))) {
codeqlArgs.push(...querySuitePaths);
}
// capture stdout, which contains analysis summaries
return await runTool(cmd, codeqlArgs);
},
Expand Down
3 changes: 1 addition & 2 deletions src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ export async function runInit(
if (await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
// Init a database cluster
await codeql.databaseInitCluster(
config.dbLocation,
config.languages,
config,
sourceRoot,
processName,
processLevel
Expand Down

0 comments on commit 682e7e7

Please sign in to comment.