Skip to content

Commit e0fedcf

Browse files
committed
Use temporary diagnostic dir in generateFailedSarif
1 parent bbeb45d commit e0fedcf

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎lib/entry-points.js‎

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

‎src/codeql.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export interface CodeQL {
199199
sarifFile: string,
200200
automationDetailsId: string | undefined,
201201
config: ActionConfig<"tempDir">,
202+
diagnosticDir: string | undefined,
202203
): Promise<void>;
203204
/** Get the location of an extractor for the specified language. */
204205
resolveExtractor(language: Language): Promise<string>;
@@ -915,6 +916,7 @@ async function getCodeQLForCmd(
915916
sarifFile: string,
916917
automationDetailsId: string | undefined,
917918
config: ActionConfig<"tempDir">,
919+
diagnosticDir: string | undefined,
918920
): Promise<void> {
919921
const args = [
920922
"diagnostics",
@@ -924,6 +926,9 @@ async function getCodeQLForCmd(
924926
`--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath(
925927
config,
926928
)}`,
929+
...(diagnosticDir !== undefined
930+
? [`--diagnostic-dir=${diagnosticDir}`]
931+
: []),
927932
...getExtraOptionsFromEnv(["diagnostics", "export"]),
928933
];
929934
if (automationDetailsId !== undefined) {

‎src/init-action-post-helper.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
type UploadDebugArtifactsConfig,
2525
} from "./debug-artifacts";
2626
import * as dependencyCaching from "./dependency-caching";
27+
import { getTempDiagnosticPath } from "./diagnostics";
2728
import { EnvVar, ReadOnlyEnv } from "./environment";
2829
import { Feature, FeatureEnablement } from "./feature-flags";
2930
import { Logger } from "./logging";
@@ -189,7 +190,19 @@ async function generateFailedSarif(
189190
databasePath === undefined ||
190191
!(await features.getValue(Feature.ExportDiagnosticsEnabled, codeql))
191192
) {
192-
await codeql.diagnosticsExport(sarifFile, category, config);
193+
// If we don't have a database path, then we may have diagnostics that were written to a
194+
// temporary location. Get the path that they would have been written to and check whether
195+
// it exists. If so, pass it on to the CLI. The CLI will not complain if we give it a
196+
// path that doesn't exist, so we are just being extra defensive here.
197+
let diagnosticDir: string | undefined = getTempDiagnosticPath(
198+
config.tempDir,
199+
);
200+
201+
if (!fs.existsSync(diagnosticDir)) {
202+
diagnosticDir = undefined;
203+
}
204+
205+
await codeql.diagnosticsExport(sarifFile, category, config, diagnosticDir);
193206
} else {
194207
// We call 'database export-diagnostics' to find any per-database diagnostics.
195208
await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);

0 commit comments

Comments
 (0)