Skip to content

Commit 5048f93

Browse files
committed
Use temporary diagnostic dir in generateFailedSarif
1 parent 846426e commit 5048f93

3 files changed

Lines changed: 38 additions & 8 deletions

File tree

‎lib/entry-points.js‎

Lines changed: 19 additions & 7 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
@@ -198,6 +198,7 @@ export interface CodeQL {
198198
sarifFile: string,
199199
automationDetailsId: string | undefined,
200200
config: Config,
201+
diagnosticDir: string | undefined,
201202
): Promise<void>;
202203
/** Get the location of an extractor for the specified language. */
203204
resolveExtractor(language: Language): Promise<string>;
@@ -919,6 +920,7 @@ async function getCodeQLForCmd(
919920
sarifFile: string,
920921
automationDetailsId: string | undefined,
921922
config: Config,
923+
diagnosticDir: string | undefined,
922924
): Promise<void> {
923925
const args = [
924926
"diagnostics",
@@ -928,6 +930,9 @@ async function getCodeQLForCmd(
928930
`--sarif-codescanning-config=${getGeneratedCodeScanningConfigPath(
929931
config,
930932
)}`,
933+
...(diagnosticDir !== undefined
934+
? [`--diagnostic-dir=${diagnosticDir}`]
935+
: []),
931936
...getExtraOptionsFromEnv(["diagnostics", "export"]),
932937
];
933938
if (automationDetailsId !== undefined) {

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
sanitizeArtifactName,
1919
} from "./debug-artifacts";
2020
import * as dependencyCaching from "./dependency-caching";
21+
import { getTempDiagnosticPath } from "./diagnostics";
2122
import { EnvVar, ReadOnlyEnv } from "./environment";
2223
import { Feature, FeatureEnablement } from "./feature-flags";
2324
import { Logger } from "./logging";
@@ -178,7 +179,19 @@ async function generateFailedSarif(
178179
databasePath === undefined ||
179180
!(await features.getValue(Feature.ExportDiagnosticsEnabled, codeql))
180181
) {
181-
await codeql.diagnosticsExport(sarifFile, category, config);
182+
// If we don't have a database path, then we may have diagnostics that were written to a
183+
// temporary location. Get the path that they would have been written to and check whether
184+
// it exists. If so, pass it on to the CLI. The CLI will not complain if we give it a
185+
// path that doesn't exist, so we are just being extra defensive here.
186+
let diagnosticDir: string | undefined = getTempDiagnosticPath(
187+
config.tempDir,
188+
);
189+
190+
if (!fs.existsSync(diagnosticDir)) {
191+
diagnosticDir = undefined;
192+
}
193+
194+
await codeql.diagnosticsExport(sarifFile, category, config, diagnosticDir);
182195
} else {
183196
// We call 'database export-diagnostics' to find any per-database diagnostics.
184197
await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);

0 commit comments

Comments
 (0)