mirror of
https://github.com/github/codeql-action.git
synced 2026-10-29 17:17:15 +00:00
Write diagnostics to temporary location when database isn't ready
This commit is contained in:
60
lib/entry-points.js
generated
60
lib/entry-points.js
generated
@@ -172971,8 +172971,7 @@ var semver5 = __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 {
|
||||
@@ -172981,6 +172980,13 @@ 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");
|
||||
if (language !== void 0) {
|
||||
return import_path2.default.join(root, language);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
function addDiagnostic(config, language, diagnostic) {
|
||||
const logger2 = getActionsLogger();
|
||||
const databasePath = language ? getCodeQLDatabasePath(config, language) : config.dbLocation;
|
||||
@@ -172990,7 +172996,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) {
|
||||
@@ -173003,7 +173011,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) {
|
||||
@@ -173018,15 +173028,15 @@ function writeDiagnosticFile(diagnosticsPath, diagnostic) {
|
||||
`codeql-action-${sanitizedTimestamp}-${uniqueSuffix}.json`
|
||||
);
|
||||
(0, import_fs.writeFileSync)(jsonPath, JSON.stringify(diagnostic));
|
||||
return jsonPath;
|
||||
}
|
||||
function getDatabaseDiagnosticsPath(config, language) {
|
||||
const databasePath = language ? getCodeQLDatabasePath(config, language) : config.dbLocation;
|
||||
return import_path2.default.resolve(databasePath, "diagnostic", "codeql-action");
|
||||
}
|
||||
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) {
|
||||
@@ -173034,30 +173044,31 @@ 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);
|
||||
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, {
|
||||
@@ -186549,6 +186560,7 @@ async function run3(actionState) {
|
||||
if (statusReportBase !== void 0) {
|
||||
await sendStatusReport(statusReportBase);
|
||||
}
|
||||
logTemporaryDiagnostics();
|
||||
return;
|
||||
}
|
||||
let overlayBaseDatabaseStats;
|
||||
@@ -186762,7 +186774,7 @@ exec ${goBinaryPath} "$@"`
|
||||
);
|
||||
return;
|
||||
} finally {
|
||||
logUnwrittenDiagnostics();
|
||||
logTemporaryDiagnostics();
|
||||
}
|
||||
await sendCompletedStatusReport2(
|
||||
startedAt,
|
||||
|
||||
Reference in New Issue
Block a user