diff --git a/lib/entry-points.js b/lib/entry-points.js index 7561480c4..8b4514637 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -177370,7 +177370,7 @@ async function getCodeQLForCmd(logger2, cmd, checkVersion) { } await new toolrunner3.ToolRunner(cmd, args).exec(); }, - async diagnosticsExport(sarifFile, automationDetailsId, config) { + async diagnosticsExport(sarifFile, automationDetailsId, config, diagnosticDir) { const args = [ "diagnostics", "export", @@ -177379,6 +177379,7 @@ async function getCodeQLForCmd(logger2, cmd, checkVersion) { `--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath( config )}`, + ...diagnosticDir !== void 0 ? [`--diagnostic-dir=${diagnosticDir}`] : [], ...getExtraOptionsFromEnv(["diagnostics", "export"]) ]; if (automationDetailsId !== void 0) { @@ -186909,7 +186910,13 @@ async function generateFailedSarif(logger2, features, config, category, checkout sarifFile = "../codeql-failed-run.sarif"; } if (databasePath === void 0 || !await features.getValue("export_diagnostics_enabled" /* ExportDiagnosticsEnabled */, codeql)) { - await codeql.diagnosticsExport(sarifFile, category, config); + let diagnosticDir = getTempDiagnosticPath( + config.tempDir + ); + if (!fs31.existsSync(diagnosticDir)) { + diagnosticDir = void 0; + } + await codeql.diagnosticsExport(sarifFile, category, config, diagnosticDir); } else { await codeql.databaseExportDiagnostics(databasePath, sarifFile, category); } diff --git a/src/codeql.ts b/src/codeql.ts index 68273d27b..6a0440321 100644 --- a/src/codeql.ts +++ b/src/codeql.ts @@ -199,6 +199,7 @@ export interface CodeQL { sarifFile: string, automationDetailsId: string | undefined, config: ActionConfig<"tempDir">, + diagnosticDir: string | undefined, ): Promise; /** Get the location of an extractor for the specified language. */ resolveExtractor(language: Language): Promise; @@ -915,6 +916,7 @@ async function getCodeQLForCmd( sarifFile: string, automationDetailsId: string | undefined, config: ActionConfig<"tempDir">, + diagnosticDir: string | undefined, ): Promise { const args = [ "diagnostics", @@ -924,6 +926,9 @@ async function getCodeQLForCmd( `--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath( config, )}`, + ...(diagnosticDir !== undefined + ? [`--diagnostic-dir=${diagnosticDir}`] + : []), ...getExtraOptionsFromEnv(["diagnostics", "export"]), ]; if (automationDetailsId !== undefined) { diff --git a/src/init-action-post-helper.ts b/src/init-action-post-helper.ts index b6aeb5bd3..3d736f9d5 100644 --- a/src/init-action-post-helper.ts +++ b/src/init-action-post-helper.ts @@ -24,6 +24,7 @@ import { type UploadDebugArtifactsConfig, } from "./debug-artifacts"; import * as dependencyCaching from "./dependency-caching"; +import { getTempDiagnosticPath } from "./diagnostics"; import { EnvVar, ReadOnlyEnv } from "./environment"; import { Feature, FeatureEnablement } from "./feature-flags"; import { Logger } from "./logging"; @@ -189,7 +190,19 @@ async function generateFailedSarif( databasePath === undefined || !(await features.getValue(Feature.ExportDiagnosticsEnabled, codeql)) ) { - await codeql.diagnosticsExport(sarifFile, category, config); + // If we don't have a database path, then we may have diagnostics that were written to a + // temporary location. Get the path that they would have been written to and check whether + // it exists. If so, pass it on to the CLI. The CLI will not complain if we give it a + // path that doesn't exist, so we are just being extra defensive here. + let diagnosticDir: string | undefined = getTempDiagnosticPath( + config.tempDir, + ); + + if (!fs.existsSync(diagnosticDir)) { + diagnosticDir = undefined; + } + + await codeql.diagnosticsExport(sarifFile, category, config, diagnosticDir); } else { // We call 'database export-diagnostics' to find any per-database diagnostics. await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);