Skip to content

Commit 9b1206e

Browse files
committed
Fix a bug in cli config parsing
When the config specifies queries in external repositories and no other queries and cli config parsing is enabled, the analyze job is not able to find any queries to run and it fails. This PR fixes the problem. Also add some logging statements when writing a copy of the user config file.
1 parent 40cfcb0 commit 9b1206e

File tree

6 files changed

+42
-24
lines changed

6 files changed

+42
-24
lines changed

lib/analyze.js

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

lib/analyze.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

Lines changed: 7 additions & 3 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.

src/analyze.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,6 @@ export async function runQueries(
222222
);
223223
const packsWithVersion = config.packs[language] || [];
224224

225-
const hasBuiltinQueries = queries?.builtin.length > 0;
226-
const hasCustomQueries = queries?.custom.length > 0;
227-
const hasPackWithCustomQueries = packsWithVersion.length > 0;
228-
229-
if (!hasBuiltinQueries && !hasCustomQueries && !hasPackWithCustomQueries) {
230-
throw new Error(
231-
`Unable to analyze ${language} as no queries were selected for this language`
232-
);
233-
}
234-
235225
try {
236226
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
237227
// If we are using the code scanning config in the CLI,
@@ -262,6 +252,21 @@ export async function runQueries(
262252
logger.info(analysisSummary);
263253
} else {
264254
// config was generated by the action, so must be interpreted by the action.
255+
256+
const hasBuiltinQueries = queries?.builtin.length > 0;
257+
const hasCustomQueries = queries?.custom.length > 0;
258+
const hasPackWithCustomQueries = packsWithVersion.length > 0;
259+
260+
if (
261+
!hasBuiltinQueries &&
262+
!hasCustomQueries &&
263+
!hasPackWithCustomQueries
264+
) {
265+
throw new Error(
266+
`Unable to analyze ${language} as no queries were selected for this language`
267+
);
268+
}
269+
265270
logger.startGroup(`Running queries for ${language}`);
266271
const querySuitePaths: string[] = [];
267272
if (queries["builtin"].length > 0) {

src/codeql.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ async function getCodeQLForCmd(
855855
config: Config,
856856
sourceRoot: string,
857857
processName: string | undefined,
858-
featureEnablement: FeatureEnablement
858+
featureEnablement: FeatureEnablement,
859+
logger: Logger
859860
) {
860861
const extraArgs = config.languages.map(
861862
(language) => `--language=${language}`
@@ -888,7 +889,8 @@ async function getCodeQLForCmd(
888889
const configLocation = await generateCodeScanningConfig(
889890
codeql,
890891
config,
891-
featureEnablement
892+
featureEnablement,
893+
logger
892894
);
893895
// Only pass external repository token if a config file is going to be parsed by the CLI.
894896
let externalRepositoryToken: string | undefined;
@@ -1386,7 +1388,8 @@ async function runTool(
13861388
async function generateCodeScanningConfig(
13871389
codeql: CodeQL,
13881390
config: Config,
1389-
featureEnablement: FeatureEnablement
1391+
featureEnablement: FeatureEnablement,
1392+
logger: Logger
13901393
): Promise<string | undefined> {
13911394
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
13921395
return;
@@ -1448,6 +1451,10 @@ async function generateCodeScanningConfig(
14481451
augmentedConfig.packs["javascript"].push(packString);
14491452
}
14501453
}
1454+
logger.info(`Writing augmented user configuration file to ${configLocation}`);
1455+
logger.startGroup("Augmented user configuration file contents");
1456+
logger.info(yaml.dump(augmentedConfig));
1457+
logger.endGroup();
14511458

14521459
fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
14531460
return configLocation;

0 commit comments

Comments
 (0)