@@ -4,12 +4,13 @@ import * as path from "path";
4
4
import * as toolrunner from "@actions/exec/lib/toolrunner" ;
5
5
import { IHeaders } from "@actions/http-client/interfaces" ;
6
6
import { default as deepEqual } from "fast-deep-equal" ;
7
+ import * as yaml from "js-yaml" ;
7
8
import { default as queryString } from "query-string" ;
8
9
import * as semver from "semver" ;
9
10
10
11
import { isRunningLocalAction , getRelativeScriptPath } from "./actions-util" ;
11
12
import * as api from "./api-client" ;
12
- import { PackWithVersion } from "./config-utils" ;
13
+ import { Config , PackWithVersion } from "./config-utils" ;
13
14
import * as defaults from "./defaults.json" ; // Referenced from codeql-action-sync-tool!
14
15
import { errorMatchers } from "./error-matcher" ;
15
16
import { isTracedLanguage , Language } from "./languages" ;
@@ -80,8 +81,7 @@ export interface CodeQL {
80
81
* Run 'codeql database init --db-cluster'.
81
82
*/
82
83
databaseInitCluster (
83
- databasePath : string ,
84
- languages : Language [ ] ,
84
+ config : Config ,
85
85
sourceRoot : string ,
86
86
processName : string | undefined ,
87
87
processLevel : number | undefined
@@ -219,6 +219,7 @@ const CODEQL_VERSION_GROUP_RULES = "2.5.5";
219
219
const CODEQL_VERSION_SARIF_GROUP = "2.5.3" ;
220
220
export const CODEQL_VERSION_COUNTS_LINES = "2.6.2" ;
221
221
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1" ;
222
+ const CODEQL_VERSION_CONFIG_FILES = "2.7.3" ;
222
223
export const CODEQL_VERSION_ML_POWERED_QUERIES = "2.7.5" ;
223
224
224
225
/**
@@ -691,26 +692,35 @@ async function getCodeQLForCmd(
691
692
] ) ;
692
693
} ,
693
694
async databaseInitCluster (
694
- databasePath : string ,
695
- languages : Language [ ] ,
695
+ config : Config ,
696
696
sourceRoot : string ,
697
697
processName : string | undefined ,
698
698
processLevel : number | undefined
699
699
) {
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 ) {
702
704
extraArgs . push ( "--begin-tracing" ) ;
703
705
if ( processName !== undefined ) {
704
706
extraArgs . push ( `--trace-process-name=${ processName } ` ) ;
705
707
} 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.
706
711
extraArgs . push ( `--trace-process-level=${ processLevel || 3 } ` ) ;
707
712
}
708
713
}
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
+ }
709
719
await runTool ( cmd , [
710
720
"database" ,
711
721
"init" ,
712
722
"--db-cluster" ,
713
- databasePath ,
723
+ config . dbLocation ,
714
724
`--source-root=${ sourceRoot } ` ,
715
725
...extraArgs ,
716
726
...getExtraOptionsFromEnv ( [ "database" , "init" ] ) ,
@@ -863,7 +873,9 @@ async function getCodeQLForCmd(
863
873
if ( extraSearchPath !== undefined ) {
864
874
codeqlArgs . push ( "--additional-packs" , extraSearchPath ) ;
865
875
}
866
- codeqlArgs . push ( querySuitePath ) ;
876
+ if ( ! ( await util . codeQlVersionAbove ( this , CODEQL_VERSION_CONFIG_FILES ) ) ) {
877
+ codeqlArgs . push ( querySuitePath ) ;
878
+ }
867
879
await runTool ( cmd , codeqlArgs ) ;
868
880
} ,
869
881
async databaseInterpretResults (
@@ -898,7 +910,10 @@ async function getCodeQLForCmd(
898
910
) {
899
911
codeqlArgs . push ( "--sarif-category" , automationDetailsId ) ;
900
912
}
901
- codeqlArgs . push ( databasePath , ...querySuitePaths ) ;
913
+ codeqlArgs . push ( databasePath ) ;
914
+ if ( ! ( await util . codeQlVersionAbove ( this , CODEQL_VERSION_CONFIG_FILES ) ) ) {
915
+ codeqlArgs . push ( ...querySuitePaths ) ;
916
+ }
902
917
// capture stdout, which contains analysis summaries
903
918
return await runTool ( cmd , codeqlArgs ) ;
904
919
} ,
0 commit comments