Skip to content

Commit 682e7e7

Browse files
Use --codescanning-config flag of CLI
1 parent 3d2ad0b commit 682e7e7

File tree

7 files changed

+55
-21
lines changed

7 files changed

+55
-21
lines changed

lib/codeql.js

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map.orig

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

lib/init.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/init.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import * as path from "path";
44
import * as toolrunner from "@actions/exec/lib/toolrunner";
55
import { IHeaders } from "@actions/http-client/interfaces";
66
import { default as deepEqual } from "fast-deep-equal";
7+
import * as yaml from "js-yaml";
78
import { default as queryString } from "query-string";
89
import * as semver from "semver";
910

1011
import { isRunningLocalAction, getRelativeScriptPath } from "./actions-util";
1112
import * as api from "./api-client";
12-
import { PackWithVersion } from "./config-utils";
13+
import { Config, PackWithVersion } from "./config-utils";
1314
import * as defaults from "./defaults.json"; // Referenced from codeql-action-sync-tool!
1415
import { errorMatchers } from "./error-matcher";
1516
import { isTracedLanguage, Language } from "./languages";
@@ -80,8 +81,7 @@ export interface CodeQL {
8081
* Run 'codeql database init --db-cluster'.
8182
*/
8283
databaseInitCluster(
83-
databasePath: string,
84-
languages: Language[],
84+
config: Config,
8585
sourceRoot: string,
8686
processName: string | undefined,
8787
processLevel: number | undefined
@@ -219,6 +219,7 @@ const CODEQL_VERSION_GROUP_RULES = "2.5.5";
219219
const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
220220
export const CODEQL_VERSION_COUNTS_LINES = "2.6.2";
221221
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
222+
const CODEQL_VERSION_CONFIG_FILES = "2.7.3";
222223
export const CODEQL_VERSION_ML_POWERED_QUERIES = "2.7.5";
223224

224225
/**
@@ -691,26 +692,35 @@ async function getCodeQLForCmd(
691692
]);
692693
},
693694
async databaseInitCluster(
694-
databasePath: string,
695-
languages: Language[],
695+
config: Config,
696696
sourceRoot: string,
697697
processName: string | undefined,
698698
processLevel: number | undefined
699699
) {
700-
const extraArgs = languages.map((language) => `--language=${language}`);
701-
if (languages.filter(isTracedLanguage).length > 0) {
700+
const extraArgs = config.languages.map(
701+
(language) => `--language=${language}`
702+
);
703+
if (config.languages.filter(isTracedLanguage).length > 0) {
702704
extraArgs.push("--begin-tracing");
703705
if (processName !== undefined) {
704706
extraArgs.push(`--trace-process-name=${processName}`);
705707
} else {
708+
// We default to 3 if no other arguments are provided since this was the default
709+
// behaviour of the Runner. Note this path never happens in the CodeQL Action
710+
// because that always passes in a process name.
706711
extraArgs.push(`--trace-process-level=${processLevel || 3}`);
707712
}
708713
}
714+
if (await util.codeQlVersionAbove(codeql, CODEQL_VERSION_CONFIG_FILES)) {
715+
const configLocation = path.resolve(config.tempDir, "user-config.yaml");
716+
fs.writeFileSync(configLocation, yaml.dump(config.originalUserInput));
717+
extraArgs.push(`--codescanning-config=${configLocation}`);
718+
}
709719
await runTool(cmd, [
710720
"database",
711721
"init",
712722
"--db-cluster",
713-
databasePath,
723+
config.dbLocation,
714724
`--source-root=${sourceRoot}`,
715725
...extraArgs,
716726
...getExtraOptionsFromEnv(["database", "init"]),
@@ -863,7 +873,9 @@ async function getCodeQLForCmd(
863873
if (extraSearchPath !== undefined) {
864874
codeqlArgs.push("--additional-packs", extraSearchPath);
865875
}
866-
codeqlArgs.push(querySuitePath);
876+
if (!(await util.codeQlVersionAbove(this, CODEQL_VERSION_CONFIG_FILES))) {
877+
codeqlArgs.push(querySuitePath);
878+
}
867879
await runTool(cmd, codeqlArgs);
868880
},
869881
async databaseInterpretResults(
@@ -898,7 +910,10 @@ async function getCodeQLForCmd(
898910
) {
899911
codeqlArgs.push("--sarif-category", automationDetailsId);
900912
}
901-
codeqlArgs.push(databasePath, ...querySuitePaths);
913+
codeqlArgs.push(databasePath);
914+
if (!(await util.codeQlVersionAbove(this, CODEQL_VERSION_CONFIG_FILES))) {
915+
codeqlArgs.push(...querySuitePaths);
916+
}
902917
// capture stdout, which contains analysis summaries
903918
return await runTool(cmd, codeqlArgs);
904919
},

src/init.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export async function runInit(
9595
if (await codeQlVersionAbove(codeql, CODEQL_VERSION_NEW_TRACING)) {
9696
// Init a database cluster
9797
await codeql.databaseInitCluster(
98-
config.dbLocation,
99-
config.languages,
98+
config,
10099
sourceRoot,
101100
processName,
102101
processLevel

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy