Omit --sarif-codescanning-config if the config file doesn't exist

This commit is contained in:
Michael B. Gale
2026-10-16 12:23:00 +01:00
parent 4935fda41a
commit b5557b885e
2 changed files with 21 additions and 6 deletions

8
lib/entry-points.js generated
View File

@@ -177438,14 +177438,16 @@ async function getCodeQLForCmd(logger2, cmd, checkVersion) {
await new toolrunner3.ToolRunner(cmd, args).exec();
},
async diagnosticsExport(sarifFile, automationDetailsId, config, diagnosticDir) {
let configPath = getGeneratedCodeScanningConfigPath(config);
if (diagnosticDir !== void 0 && !fs17.existsSync(configPath)) {
configPath = void 0;
}
const args = [
"diagnostics",
"export",
"--format=sarif-latest",
`--output=${sarifFile}`,
`--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath(
config
)}`,
...configPath !== void 0 ? [`--sarif-codescanning-config=${configPath}`] : [],
...diagnosticDir !== void 0 ? [`--diagnostic-dir=${diagnosticDir}`] : [],
...getExtraOptionsFromEnv(["diagnostics", "export"])
];

View File

@@ -918,14 +918,27 @@ async function getCodeQLForCmd(
config: ActionConfig<"tempDir">,
diagnosticDir: string | undefined,
): Promise<void> {
// We may be exporting diagnostics for a failed SARIF, in which case the configuration
// file may not have been written to disk and there may not be a database. The CLI
// will produce a SARIF for diagnostics from `diagnosticDir` without it. Therefore,
// if `diagnosticDir` is set, we check whether `configPath` exists and only provide
// it to the CLI if it does. Although not needed, the CLI will produce an error if it
// is provided with an argument to `--sarif-codescanning-config` that does not exist.
let configPath: string | undefined =
getGeneratedCodeScanningConfigPath(config);
if (diagnosticDir !== undefined && !fs.existsSync(configPath)) {
configPath = undefined;
}
const args = [
"diagnostics",
"export",
"--format=sarif-latest",
`--output=${sarifFile}`,
`--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath(
config,
)}`,
...(configPath !== undefined
? [`--sarif-codescanning-config=${configPath}`]
: []),
...(diagnosticDir !== undefined
? [`--diagnostic-dir=${diagnosticDir}`]
: []),