Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug in cli config parsing #1487

Merged
merged 1 commit into from
Jan 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 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.

10 changes: 7 additions & 3 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.

25 changes: 15 additions & 10 deletions src/analyze.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,16 +222,6 @@ export async function runQueries(
);
const packsWithVersion = config.packs[language] || [];

const hasBuiltinQueries = queries?.builtin.length > 0;
const hasCustomQueries = queries?.custom.length > 0;
const hasPackWithCustomQueries = packsWithVersion.length > 0;

if (!hasBuiltinQueries && !hasCustomQueries && !hasPackWithCustomQueries) {
throw new Error(
`Unable to analyze ${language} as no queries were selected for this language`
);
}

try {
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
// If we are using the code scanning config in the CLI,
Expand Down Expand Up @@ -262,6 +252,21 @@ export async function runQueries(
logger.info(analysisSummary);
} else {
// config was generated by the action, so must be interpreted by the action.

const hasBuiltinQueries = queries?.builtin.length > 0;
const hasCustomQueries = queries?.custom.length > 0;
const hasPackWithCustomQueries = packsWithVersion.length > 0;

if (
!hasBuiltinQueries &&
!hasCustomQueries &&
!hasPackWithCustomQueries
) {
throw new Error(
`Unable to analyze ${language} as no queries were selected for this language`
);
}

logger.startGroup(`Running queries for ${language}`);
const querySuitePaths: string[] = [];
if (queries["builtin"].length > 0) {
Expand Down
13 changes: 10 additions & 3 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,8 @@ async function getCodeQLForCmd(
config: Config,
sourceRoot: string,
processName: string | undefined,
featureEnablement: FeatureEnablement
featureEnablement: FeatureEnablement,
logger: Logger
) {
const extraArgs = config.languages.map(
(language) => `--language=${language}`
Expand Down Expand Up @@ -888,7 +889,8 @@ async function getCodeQLForCmd(
const configLocation = await generateCodeScanningConfig(
codeql,
config,
featureEnablement
featureEnablement,
logger
);
// Only pass external repository token if a config file is going to be parsed by the CLI.
let externalRepositoryToken: string | undefined;
Expand Down Expand Up @@ -1386,7 +1388,8 @@ async function runTool(
async function generateCodeScanningConfig(
codeql: CodeQL,
config: Config,
featureEnablement: FeatureEnablement
featureEnablement: FeatureEnablement,
logger: Logger
): Promise<string | undefined> {
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
return;
Expand Down Expand Up @@ -1448,6 +1451,10 @@ async function generateCodeScanningConfig(
augmentedConfig.packs["javascript"].push(packString);
}
}
logger.info(`Writing augmented user configuration file to ${configLocation}`);
logger.startGroup("Augmented user configuration file contents");
logger.info(yaml.dump(augmentedConfig));
logger.endGroup();
Comment on lines +1454 to +1457
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this makes sense as info while we're rolling out the flag, but let's consider making this debug afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
return configLocation;
Expand Down