Address review comments from @henrymercer

This commit is contained in:
Edoardo Pirovano 2022-08-16 13:30:49 +01:00
parent 4139682b64
commit b29194f0ac
No known key found for this signature in database
GPG key ID: 047556B5D93FFE28
12 changed files with 95 additions and 58 deletions

34
lib/analyze-action.js generated
View file

@ -35,7 +35,7 @@ const upload_lib = __importStar(require("./upload-lib"));
const util = __importStar(require("./util"));
// eslint-disable-next-line import/no-commonjs
const pkg = require("../package.json");
async function sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches) {
async function sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches, logger) {
const status = actionsUtil.getActionsStatus(error, stats === null || stats === void 0 ? void 0 : stats.analyze_failure_language);
const statusReportBase = await actionsUtil.createStatusReportBase("finish", status, startedAt, error === null || error === void 0 ? void 0 : error.message, error === null || error === void 0 ? void 0 : error.stack);
const statusReport = {
@ -46,12 +46,18 @@ async function sendStatusReport(startedAt, config, stats, error, trapCacheUpload
}
: {}),
...(stats || {}),
trap_cache_upload_duration_ms: trapCacheUploadTime || 0,
trap_cache_upload_size_bytes: config && didUploadTrapCaches
? await (0, trap_caching_1.getTotalCacheSize)(config.trapCaches)
: 0,
};
await actionsUtil.sendStatusReport(statusReport);
if (config && didUploadTrapCaches) {
const trapCacheUploadStatusReport = {
...statusReport,
trap_cache_upload_duration_ms: trapCacheUploadTime || 0,
trap_cache_upload_size_bytes: await (0, trap_caching_1.getTotalCacheSize)(config.trapCaches, logger),
};
await actionsUtil.sendStatusReport(trapCacheUploadStatusReport);
}
else {
await actionsUtil.sendStatusReport(statusReport);
}
}
exports.sendStatusReport = sendStatusReport;
async function run() {
@ -63,11 +69,11 @@ async function run() {
let didUploadTrapCaches = false;
util.initializeEnvironment(util.Mode.actions, pkg.version);
await util.checkActionVersion(pkg.version);
const logger = (0, logging_1.getActionsLogger)();
try {
if (!(await actionsUtil.sendStatusReport(await actionsUtil.createStatusReportBase("finish", "starting", startedAt)))) {
return;
}
const logger = (0, logging_1.getActionsLogger)();
config = await (0, config_utils_1.getConfig)(actionsUtil.getTemporaryDirectory(), logger);
if (config === undefined) {
throw new Error("Config file could not be found at expected location. Has the 'init' action been called?");
@ -106,9 +112,9 @@ async function run() {
// Possibly upload the database bundles for remote queries
await (0, database_upload_1.uploadDatabases)(repositoryNwo, config, apiDetails, logger);
// Possibly upload the TRAP caches for later re-use
const trapCacheUploadStartTime = Date.now();
const trapCacheUploadStartTime = performance.now();
const codeql = await (0, codeql_1.getCodeQL)(config.codeQLCmd);
trapCacheUploadTime = Date.now() - trapCacheUploadStartTime;
trapCacheUploadTime = performance.now() - trapCacheUploadStartTime;
didUploadTrapCaches = await (0, trap_caching_1.uploadTrapCaches)(codeql, config, logger);
// We don't upload results in test mode, so don't wait for processing
if (util.isInTestMode()) {
@ -125,10 +131,10 @@ async function run() {
console.log(error);
if (error instanceof analyze_1.CodeQLAnalysisError) {
const stats = { ...error.queriesStatusReport };
await sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches);
await sendStatusReport(startedAt, config, stats, error, trapCacheUploadTime, didUploadTrapCaches, logger);
}
else {
await sendStatusReport(startedAt, config, undefined, error, trapCacheUploadTime, didUploadTrapCaches);
await sendStatusReport(startedAt, config, undefined, error, trapCacheUploadTime, didUploadTrapCaches, logger);
}
return;
}
@ -136,13 +142,13 @@ async function run() {
await sendStatusReport(startedAt, config, {
...runStats,
...uploadResult.statusReport,
}, undefined, trapCacheUploadTime, didUploadTrapCaches);
}, undefined, trapCacheUploadTime, didUploadTrapCaches, logger);
}
else if (runStats) {
await sendStatusReport(startedAt, config, { ...runStats }, undefined, trapCacheUploadTime, didUploadTrapCaches);
await sendStatusReport(startedAt, config, { ...runStats }, undefined, trapCacheUploadTime, didUploadTrapCaches, logger);
}
else {
await sendStatusReport(startedAt, config, undefined, undefined, trapCacheUploadTime, didUploadTrapCaches);
await sendStatusReport(startedAt, config, undefined, undefined, trapCacheUploadTime, didUploadTrapCaches, logger);
}
}
exports.runPromise = run();