mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Write diagnostics to temporary location when database isn't ready
This commit is contained in:
65
lib/entry-points.js
generated
65
lib/entry-points.js
generated
@@ -172981,8 +172981,7 @@ var semver4 = __toESM(require_semver2());
|
||||
// src/diagnostics.ts
|
||||
var import_fs = require("fs");
|
||||
var import_path2 = __toESM(require("path"));
|
||||
var unwrittenDiagnostics = [];
|
||||
var unwrittenDefaultLanguageDiagnostics = [];
|
||||
var temporaryDiagnostics = [];
|
||||
var diagnosticCounter = 0;
|
||||
function makeDiagnostic(id, name, data = void 0) {
|
||||
return {
|
||||
@@ -172991,6 +172990,16 @@ function makeDiagnostic(id, name, data = void 0) {
|
||||
source: { ...data?.source, id, name }
|
||||
};
|
||||
}
|
||||
function getTempDiagnosticPath(tmpDir, language) {
|
||||
const root = import_path2.default.join(tmpDir, "codeql-action-temp-diagnostics");
|
||||
return getDiagnosticsPath(root, language);
|
||||
}
|
||||
function getDiagnosticsPath(basePath, language) {
|
||||
if (language !== void 0) {
|
||||
return import_path2.default.resolve(basePath, language, "diagnostic", "codeql-action");
|
||||
}
|
||||
return basePath;
|
||||
}
|
||||
function addDiagnostic(config, language, diagnostic) {
|
||||
const logger2 = getActionsLogger();
|
||||
const databasePath = language ? getCodeQLDatabasePath(config, language) : config.dbLocation;
|
||||
@@ -173000,7 +173009,9 @@ function addDiagnostic(config, language, diagnostic) {
|
||||
logger2.debug(
|
||||
`Writing a diagnostic for ${language}, but the database at ${databasePath} does not exist yet.`
|
||||
);
|
||||
unwrittenDiagnostics.push({ diagnostic, language });
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(config.tempDir, language);
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
temporaryDiagnostics.push({ path: diagnosticPath, language });
|
||||
}
|
||||
}
|
||||
function addNoLanguageDiagnostic(config, diagnostic) {
|
||||
@@ -173013,7 +173024,9 @@ function addNoLanguageDiagnostic(config, diagnostic) {
|
||||
diagnostic
|
||||
);
|
||||
} else {
|
||||
unwrittenDefaultLanguageDiagnostics.push(diagnostic);
|
||||
const tempDiagnosticsPath = getTempDiagnosticPath(getTemporaryDirectory());
|
||||
const diagnosticPath = writeDiagnosticFile(tempDiagnosticsPath, diagnostic);
|
||||
temporaryDiagnostics.push({ path: diagnosticPath });
|
||||
}
|
||||
}
|
||||
function writeDiagnosticFile(diagnosticsPath, diagnostic) {
|
||||
@@ -173028,15 +173041,14 @@ function writeDiagnosticFile(diagnosticsPath, diagnostic) {
|
||||
`codeql-action-${sanitizedTimestamp}-${uniqueSuffix}.json`
|
||||
);
|
||||
(0, import_fs.writeFileSync)(jsonPath, JSON.stringify(diagnostic));
|
||||
return jsonPath;
|
||||
}
|
||||
function getDatabaseDiagnosticsPath(config, language) {
|
||||
return getDiagnosticsPath(config.dbLocation, language);
|
||||
}
|
||||
function writeDiagnostic(config, language, diagnostic) {
|
||||
const logger2 = getActionsLogger();
|
||||
const databasePath = language ? getCodeQLDatabasePath(config, language) : config.dbLocation;
|
||||
const diagnosticsPath = import_path2.default.resolve(
|
||||
databasePath,
|
||||
"diagnostic",
|
||||
"codeql-action"
|
||||
);
|
||||
const diagnosticsPath = getDatabaseDiagnosticsPath(config, language);
|
||||
try {
|
||||
writeDiagnosticFile(diagnosticsPath, diagnostic);
|
||||
} catch (err) {
|
||||
@@ -173044,30 +173056,34 @@ function writeDiagnostic(config, language, diagnostic) {
|
||||
logger2.debug(JSON.stringify(diagnostic));
|
||||
}
|
||||
}
|
||||
function logUnwrittenDiagnostics() {
|
||||
function logTemporaryDiagnostics() {
|
||||
const logger2 = getActionsLogger();
|
||||
const num = unwrittenDiagnostics.length;
|
||||
const num = temporaryDiagnostics.length;
|
||||
if (num > 0) {
|
||||
logger2.warning(
|
||||
`${num} diagnostic(s) could not be written to the database and will not appear on the Tool Status Page.`
|
||||
);
|
||||
for (const unwritten of unwrittenDiagnostics) {
|
||||
logger2.debug(JSON.stringify(unwritten.diagnostic));
|
||||
for (const temporary of temporaryDiagnostics) {
|
||||
logger2.debug((0, import_fs.readFileSync)(temporary.path, "utf-8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
function flushDiagnostics(config) {
|
||||
const logger2 = getActionsLogger();
|
||||
const diagnosticsCount = unwrittenDiagnostics.length + unwrittenDefaultLanguageDiagnostics.length;
|
||||
logger2.debug(`Writing ${diagnosticsCount} diagnostic(s) to database.`);
|
||||
for (const unwritten of unwrittenDiagnostics) {
|
||||
writeDiagnostic(config, unwritten.language, unwritten.diagnostic);
|
||||
const diagnosticsCount = temporaryDiagnostics.length;
|
||||
logger2.debug(
|
||||
`Moving ${diagnosticsCount} diagnostic(s) to their respective databases.`
|
||||
);
|
||||
for (const temporary of temporaryDiagnostics) {
|
||||
const directory = getDatabaseDiagnosticsPath(
|
||||
config,
|
||||
temporary.language ?? config.languages[0]
|
||||
);
|
||||
const filename = import_path2.default.basename(temporary.path);
|
||||
const destination = import_path2.default.join(directory, filename);
|
||||
(0, import_fs.renameSync)(temporary.path, destination);
|
||||
}
|
||||
for (const unwritten of unwrittenDefaultLanguageDiagnostics) {
|
||||
addNoLanguageDiagnostic(config, unwritten);
|
||||
}
|
||||
unwrittenDiagnostics = [];
|
||||
unwrittenDefaultLanguageDiagnostics = [];
|
||||
temporaryDiagnostics = [];
|
||||
}
|
||||
function makeTelemetryDiagnostic(id, name, attributes, tags) {
|
||||
return makeDiagnostic(id, name, {
|
||||
@@ -186577,6 +186593,7 @@ async function run3(actionState) {
|
||||
if (statusReportBase !== void 0) {
|
||||
await sendStatusReport(statusReportBase);
|
||||
}
|
||||
logTemporaryDiagnostics();
|
||||
return;
|
||||
}
|
||||
let overlayBaseDatabaseStats;
|
||||
@@ -186786,7 +186803,7 @@ exec ${goBinaryPath} "$@"`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
logUnwrittenDiagnostics();
|
||||
logTemporaryDiagnostics();
|
||||
}
|
||||
await sendCompletedStatusReport2(
|
||||
startedAt,
|
||||
|
||||
Reference in New Issue
Block a user