Merge pull request #1487 from github/aeisenberg/queries-check
Fix a bug in cli config parsing
This commit is contained in:
commit
e0fd640b0c
6 changed files with 42 additions and 24 deletions
14
lib/analyze.js
generated
14
lib/analyze.js
generated
|
|
@ -127,12 +127,6 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
||||||
const queries = config.queries[language];
|
const queries = config.queries[language];
|
||||||
const queryFilters = validateQueryFilters(config.originalUserInput["query-filters"]);
|
const queryFilters = validateQueryFilters(config.originalUserInput["query-filters"]);
|
||||||
const packsWithVersion = config.packs[language] || [];
|
const packsWithVersion = config.packs[language] || [];
|
||||||
const hasBuiltinQueries = (queries === null || queries === void 0 ? void 0 : queries.builtin.length) > 0;
|
|
||||||
const hasCustomQueries = (queries === null || queries === void 0 ? void 0 : 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 {
|
try {
|
||||||
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
|
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
|
||||||
// If we are using the code scanning config in the CLI,
|
// If we are using the code scanning config in the CLI,
|
||||||
|
|
@ -158,6 +152,14 @@ async function runQueries(sarifFolder, memoryFlag, addSnippetsFlag, threadsFlag,
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// config was generated by the action, so must be interpreted by the action.
|
// config was generated by the action, so must be interpreted by the action.
|
||||||
|
const hasBuiltinQueries = (queries === null || queries === void 0 ? void 0 : queries.builtin.length) > 0;
|
||||||
|
const hasCustomQueries = (queries === null || queries === void 0 ? void 0 : 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}`);
|
logger.startGroup(`Running queries for ${language}`);
|
||||||
const querySuitePaths = [];
|
const querySuitePaths = [];
|
||||||
if (queries["builtin"].length > 0) {
|
if (queries["builtin"].length > 0) {
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
10
lib/codeql.js
generated
10
lib/codeql.js
generated
|
|
@ -518,7 +518,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
...getExtraOptionsFromEnv(["database", "init"]),
|
...getExtraOptionsFromEnv(["database", "init"]),
|
||||||
]);
|
]);
|
||||||
},
|
},
|
||||||
async databaseInitCluster(config, sourceRoot, processName, featureEnablement) {
|
async databaseInitCluster(config, sourceRoot, processName, featureEnablement, logger) {
|
||||||
const extraArgs = config.languages.map((language) => `--language=${language}`);
|
const extraArgs = config.languages.map((language) => `--language=${language}`);
|
||||||
if (config.languages.filter((l) => (0, languages_1.isTracedLanguage)(l)).length > 0) {
|
if (config.languages.filter((l) => (0, languages_1.isTracedLanguage)(l)).length > 0) {
|
||||||
extraArgs.push("--begin-tracing");
|
extraArgs.push("--begin-tracing");
|
||||||
|
|
@ -537,7 +537,7 @@ async function getCodeQLForCmd(cmd, checkVersion) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// A config file is only generated if the CliConfigFileEnabled feature flag is enabled.
|
// A config file is only generated if the CliConfigFileEnabled feature flag is enabled.
|
||||||
const configLocation = await generateCodeScanningConfig(codeql, config, featureEnablement);
|
const configLocation = await generateCodeScanningConfig(codeql, config, featureEnablement, logger);
|
||||||
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
||||||
let externalRepositoryToken;
|
let externalRepositoryToken;
|
||||||
if (configLocation) {
|
if (configLocation) {
|
||||||
|
|
@ -923,7 +923,7 @@ async function runTool(cmd, args = [], opts = {}) {
|
||||||
* @param config The configuration to use.
|
* @param config The configuration to use.
|
||||||
* @returns the path to the generated user configuration file.
|
* @returns the path to the generated user configuration file.
|
||||||
*/
|
*/
|
||||||
async function generateCodeScanningConfig(codeql, config, featureEnablement) {
|
async function generateCodeScanningConfig(codeql, config, featureEnablement, logger) {
|
||||||
var _a;
|
var _a;
|
||||||
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
|
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -982,6 +982,10 @@ async function generateCodeScanningConfig(codeql, config, featureEnablement) {
|
||||||
augmentedConfig.packs["javascript"].push(packString);
|
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();
|
||||||
fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
|
fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
|
||||||
return configLocation;
|
return configLocation;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -222,16 +222,6 @@ export async function runQueries(
|
||||||
);
|
);
|
||||||
const packsWithVersion = config.packs[language] || [];
|
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 {
|
try {
|
||||||
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
|
if (await util.useCodeScanningConfigInCli(codeql, featureEnablement)) {
|
||||||
// If we are using the code scanning config in the CLI,
|
// If we are using the code scanning config in the CLI,
|
||||||
|
|
@ -262,6 +252,21 @@ export async function runQueries(
|
||||||
logger.info(analysisSummary);
|
logger.info(analysisSummary);
|
||||||
} else {
|
} else {
|
||||||
// config was generated by the action, so must be interpreted by the action.
|
// 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}`);
|
logger.startGroup(`Running queries for ${language}`);
|
||||||
const querySuitePaths: string[] = [];
|
const querySuitePaths: string[] = [];
|
||||||
if (queries["builtin"].length > 0) {
|
if (queries["builtin"].length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -855,7 +855,8 @@ async function getCodeQLForCmd(
|
||||||
config: Config,
|
config: Config,
|
||||||
sourceRoot: string,
|
sourceRoot: string,
|
||||||
processName: string | undefined,
|
processName: string | undefined,
|
||||||
featureEnablement: FeatureEnablement
|
featureEnablement: FeatureEnablement,
|
||||||
|
logger: Logger
|
||||||
) {
|
) {
|
||||||
const extraArgs = config.languages.map(
|
const extraArgs = config.languages.map(
|
||||||
(language) => `--language=${language}`
|
(language) => `--language=${language}`
|
||||||
|
|
@ -888,7 +889,8 @@ async function getCodeQLForCmd(
|
||||||
const configLocation = await generateCodeScanningConfig(
|
const configLocation = await generateCodeScanningConfig(
|
||||||
codeql,
|
codeql,
|
||||||
config,
|
config,
|
||||||
featureEnablement
|
featureEnablement,
|
||||||
|
logger
|
||||||
);
|
);
|
||||||
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
// Only pass external repository token if a config file is going to be parsed by the CLI.
|
||||||
let externalRepositoryToken: string | undefined;
|
let externalRepositoryToken: string | undefined;
|
||||||
|
|
@ -1386,7 +1388,8 @@ async function runTool(
|
||||||
async function generateCodeScanningConfig(
|
async function generateCodeScanningConfig(
|
||||||
codeql: CodeQL,
|
codeql: CodeQL,
|
||||||
config: Config,
|
config: Config,
|
||||||
featureEnablement: FeatureEnablement
|
featureEnablement: FeatureEnablement,
|
||||||
|
logger: Logger
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
|
if (!(await util.useCodeScanningConfigInCli(codeql, featureEnablement))) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -1448,6 +1451,10 @@ async function generateCodeScanningConfig(
|
||||||
augmentedConfig.packs["javascript"].push(packString);
|
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();
|
||||||
|
|
||||||
fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
|
fs.writeFileSync(configLocation, yaml.dump(augmentedConfig));
|
||||||
return configLocation;
|
return configLocation;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue