Address review comments from @henrymercer
This commit is contained in:
parent
4139682b64
commit
b29194f0ac
12 changed files with 95 additions and 58 deletions
34
lib/analyze-action.js
generated
34
lib/analyze-action.js
generated
|
|
@ -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();
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
4
lib/config-utils.js
generated
4
lib/config-utils.js
generated
|
|
@ -517,9 +517,9 @@ async function downloadCacheWithTime(trapCachingEnabled, codeQL, languages, logg
|
|||
let trapCaches = {};
|
||||
let trapCacheDownloadTime = 0;
|
||||
if (trapCachingEnabled) {
|
||||
const start = Date.now();
|
||||
const start = performance.now();
|
||||
trapCaches = await (0, trap_caching_1.downloadTrapCaches)(codeQL, languages, logger);
|
||||
trapCacheDownloadTime = Date.now() - start;
|
||||
trapCacheDownloadTime = performance.now() - start;
|
||||
}
|
||||
return { trapCaches, trapCacheDownloadTime };
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
6
lib/init-action.js
generated
6
lib/init-action.js
generated
|
|
@ -33,7 +33,7 @@ const trap_caching_1 = require("./trap-caching");
|
|||
const util_1 = require("./util");
|
||||
// eslint-disable-next-line import/no-commonjs
|
||||
const pkg = require("../package.json");
|
||||
async function sendSuccessStatusReport(startedAt, config, toolsVersion) {
|
||||
async function sendSuccessStatusReport(startedAt, config, toolsVersion, logger) {
|
||||
var _a;
|
||||
const statusReportBase = await (0, actions_util_1.createStatusReportBase)("init", "success", startedAt);
|
||||
const languages = config.languages.join(",");
|
||||
|
|
@ -66,7 +66,7 @@ async function sendSuccessStatusReport(startedAt, config, toolsVersion) {
|
|||
tools_resolved_version: toolsVersion,
|
||||
workflow_languages: workflowLanguages || "",
|
||||
trap_cache_languages: Object.keys(config.trapCaches).join(","),
|
||||
trap_cache_download_size_bytes: await (0, trap_caching_1.getTotalCacheSize)(config.trapCaches),
|
||||
trap_cache_download_size_bytes: await (0, trap_caching_1.getTotalCacheSize)(config.trapCaches, logger),
|
||||
trap_cache_download_duration_ms: config.trapCacheDownloadTime,
|
||||
};
|
||||
await (0, actions_util_1.sendStatusReport)(statusReport);
|
||||
|
|
@ -156,7 +156,7 @@ async function run() {
|
|||
await (0, actions_util_1.sendStatusReport)(await (0, actions_util_1.createStatusReportBase)("init", (0, actions_util_1.getActionsStatus)(error), startedAt, String(error), error instanceof Error ? error.stack : undefined));
|
||||
return;
|
||||
}
|
||||
await sendSuccessStatusReport(startedAt, config, toolsVersion);
|
||||
await sendSuccessStatusReport(startedAt, config, toolsVersion, logger);
|
||||
}
|
||||
async function getTrapCachingEnabled(featureFlags) {
|
||||
const trapCaching = (0, actions_util_1.getOptionalInput)("trap-caching");
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
11
lib/trap-caching.js
generated
11
lib/trap-caching.js
generated
|
|
@ -159,14 +159,17 @@ async function getLanguagesSupportingCaching(codeql, languages, logger) {
|
|||
return result;
|
||||
}
|
||||
exports.getLanguagesSupportingCaching = getLanguagesSupportingCaching;
|
||||
async function getTotalCacheSize(trapCaches) {
|
||||
async function getTotalCacheSize(trapCaches, logger) {
|
||||
const sizes = await Promise.all(Object.values(trapCaches).map(async (cacheDir) => {
|
||||
return new Promise((resolve) => {
|
||||
(0, get_folder_size_1.default)(cacheDir, (err, size) => {
|
||||
// Ignore file system errors when getting the size. It's only used for telemetry anyway.
|
||||
if (err)
|
||||
if (err) {
|
||||
logger.warning(`Error getting size of ${cacheDir}: ${err}`);
|
||||
resolve(0);
|
||||
resolve(size);
|
||||
}
|
||||
else {
|
||||
resolve(size);
|
||||
}
|
||||
});
|
||||
});
|
||||
}));
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue