Avoid top-level promise in analyze-action

This commit is contained in:
Michael B. Gale
2026-05-14 15:14:03 +01:00
parent 2f137c9dc6
commit bb30f3132d
4 changed files with 76 additions and 80 deletions
+72 -73
View File
@@ -157521,12 +157521,12 @@ async function postProcessAndUploadSarif(logger, features, uploadKind, checkoutP
}
// src/analyze-action.ts
async function sendStatusReport2(startedAt2, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) {
async function sendStatusReport2(startedAt, config, stats, error3, trapCacheUploadTime, dbCreationTimings, didUploadTrapCaches, trapCacheCleanup, dependencyCacheResults, databaseUploadResults, logger) {
const status = getActionsStatus(error3, stats?.analyze_failure_language);
const statusReportBase = await createStatusReportBase(
"finish" /* Analyze */,
status,
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -157616,7 +157616,7 @@ async function runAutobuildIfLegacyGoWorkflow(config, logger) {
);
await runAutobuild(config, "go" /* go */, logger);
}
async function run(startedAt2) {
async function run(startedAt) {
let uploadResults = void 0;
let runStats = void 0;
let config = void 0;
@@ -157633,7 +157633,7 @@ async function run(startedAt2) {
const statusReportBase = await createStatusReportBase(
"finish" /* Analyze */,
"starting",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -157795,7 +157795,7 @@ async function run(startedAt2) {
core16.setFailed(error3.message);
}
await sendStatusReport2(
startedAt2,
startedAt,
config,
error3 instanceof CodeQLAnalysisError ? error3.queriesStatusReport : void 0,
error3 instanceof CodeQLAnalysisError ? error3.error : error3,
@@ -157811,7 +157811,7 @@ async function run(startedAt2) {
}
if (runStats !== void 0 && uploadResults?.["code-scanning" /* CodeScanning */] !== void 0) {
await sendStatusReport2(
startedAt2,
startedAt,
config,
{
...runStats,
@@ -157828,7 +157828,7 @@ async function run(startedAt2) {
);
} else if (runStats !== void 0) {
await sendStatusReport2(
startedAt2,
startedAt,
config,
{ ...runStats },
void 0,
@@ -157842,7 +157842,7 @@ async function run(startedAt2) {
);
} else {
await sendStatusReport2(
startedAt2,
startedAt,
config,
void 0,
void 0,
@@ -157856,12 +157856,11 @@ async function run(startedAt2) {
);
}
}
var startedAt = /* @__PURE__ */ new Date();
var runPromise = run(startedAt);
async function runWrapper() {
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await runPromise;
await run(startedAt);
} catch (error3) {
core16.setFailed(`analyze action failed: ${getErrorMessage(error3)}`);
await sendUnhandledErrorStatusReport(
@@ -157876,13 +157875,13 @@ async function runWrapper() {
// src/autobuild-action.ts
var core17 = __toESM(require_core());
async function sendCompletedStatusReport(config, logger, startedAt2, allLanguages, failingLanguage, cause) {
async function sendCompletedStatusReport(config, logger, startedAt, allLanguages, failingLanguage, cause) {
initializeEnvironment(getActionVersion());
const status = getActionsStatus(cause, failingLanguage);
const statusReportBase = await createStatusReportBase(
"autobuild" /* Autobuild */,
status,
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -157898,7 +157897,7 @@ async function sendCompletedStatusReport(config, logger, startedAt2, allLanguage
await sendStatusReport(statusReport);
}
}
async function run2(startedAt2) {
async function run2(startedAt) {
const logger = getActionsLogger();
let config;
let currentLanguage;
@@ -157907,7 +157906,7 @@ async function run2(startedAt2) {
const statusReportBase = await createStatusReportBase(
"autobuild" /* Autobuild */,
"starting",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -157948,7 +157947,7 @@ async function run2(startedAt2) {
await sendCompletedStatusReport(
config,
logger,
startedAt2,
startedAt,
languages ?? [],
currentLanguage,
error3
@@ -157956,18 +157955,18 @@ async function run2(startedAt2) {
return;
}
core17.exportVariable("CODEQL_ACTION_AUTOBUILD_DID_COMPLETE_SUCCESSFULLY" /* AUTOBUILD_DID_COMPLETE_SUCCESSFULLY */, "true");
await sendCompletedStatusReport(config, logger, startedAt2, languages ?? []);
await sendCompletedStatusReport(config, logger, startedAt, languages ?? []);
}
async function runWrapper2() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run2(startedAt2);
await run2(startedAt);
} catch (error3) {
core17.setFailed(`autobuild action failed. ${getErrorMessage(error3)}`);
await sendUnhandledErrorStatusReport(
"autobuild" /* Autobuild */,
startedAt2,
startedAt,
error3,
logger
);
@@ -158259,11 +158258,11 @@ var internal2 = {
// src/init-action.ts
var CODEQL_VERSION_JAR_MINIMIZATION = "2.23.0";
async function sendStartingStatusReport(startedAt2, config, logger) {
async function sendStartingStatusReport(startedAt, config, logger) {
const statusReportBase = await createStatusReportBase(
"init" /* Init */,
"starting",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -158272,11 +158271,11 @@ async function sendStartingStatusReport(startedAt2, config, logger) {
await sendStatusReport(statusReportBase);
}
}
async function sendCompletedStatusReport2(startedAt2, config, configFile, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, overlayBaseDatabaseStats, dependencyCachingResults, logger, error3) {
async function sendCompletedStatusReport2(startedAt, config, configFile, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, overlayBaseDatabaseStats, dependencyCachingResults, logger, error3) {
const statusReportBase = await createStatusReportBase(
"init" /* Init */,
getActionsStatus(error3),
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -158320,7 +158319,7 @@ async function sendCompletedStatusReport2(startedAt2, config, configFile, toolsD
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
}
}
async function run3(startedAt2) {
async function run3(startedAt) {
const logger = getActionsLogger();
let apiDetails;
let config;
@@ -158373,7 +158372,7 @@ async function run3(startedAt2) {
`Failed to parse analysis kinds for 'starting' status report: ${getErrorMessage(err)}`
);
}
await sendStartingStatusReport(startedAt2, { analysisKinds }, logger);
await sendStartingStatusReport(startedAt, { analysisKinds }, logger);
if (process.env["CODEQL_ACTION_SETUP_CODEQL_HAS_RUN" /* SETUP_CODEQL_ACTION_HAS_RUN */] === "true") {
throw new ConfigurationError(
`The 'init' action should not be run in the same workflow as 'setup-codeql'.`
@@ -158497,7 +158496,7 @@ async function run3(startedAt2) {
const statusReportBase = await createStatusReportBase(
"init" /* Init */,
error3 instanceof ConfigurationError ? "user-error" : "aborted",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -158713,7 +158712,7 @@ exec ${goBinaryPath} "$@"`
const error3 = wrapError(unwrappedError);
core19.setFailed(error3.message);
await sendCompletedStatusReport2(
startedAt2,
startedAt,
config,
void 0,
// We only report config info on success.
@@ -158731,7 +158730,7 @@ exec ${goBinaryPath} "$@"`
logUnwrittenDiagnostics();
}
await sendCompletedStatusReport2(
startedAt2,
startedAt,
config,
configFile,
toolsDownloadStatusReport,
@@ -158801,15 +158800,15 @@ async function recordZstdAvailability(config, zstdAvailability) {
);
}
async function runWrapper3() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run3(startedAt2);
await run3(startedAt);
} catch (error3) {
core19.setFailed(`init action failed: ${getErrorMessage(error3)}`);
await sendUnhandledErrorStatusReport(
"init" /* Init */,
startedAt2,
startedAt,
error3,
logger
);
@@ -158834,14 +158833,14 @@ async function runResolveBuildEnvironment(cmd, logger, workingDir, language) {
// src/resolve-environment-action.ts
var ENVIRONMENT_OUTPUT_NAME = "environment";
async function run4(startedAt2) {
async function run4(startedAt) {
const logger = getActionsLogger();
let config;
try {
const statusReportBase2 = await createStatusReportBase(
"resolve-environment" /* ResolveEnvironment */,
"starting",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -158880,7 +158879,7 @@ async function run4(startedAt2) {
const statusReportBase2 = await createStatusReportBase(
"resolve-environment" /* ResolveEnvironment */,
getActionsStatus(error3),
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -158896,7 +158895,7 @@ async function run4(startedAt2) {
const statusReportBase = await createStatusReportBase(
"resolve-environment" /* ResolveEnvironment */,
"success",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -158906,10 +158905,10 @@ async function run4(startedAt2) {
}
}
async function runWrapper4() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run4(startedAt2);
await run4(startedAt);
} catch (error3) {
core20.setFailed(
`${"resolve-environment" /* ResolveEnvironment */} action failed: ${getErrorMessage(
@@ -158918,7 +158917,7 @@ async function runWrapper4() {
);
await sendUnhandledErrorStatusReport(
"resolve-environment" /* ResolveEnvironment */,
startedAt2,
startedAt,
error3,
logger
);
@@ -158928,11 +158927,11 @@ async function runWrapper4() {
// src/setup-codeql-action.ts
var core21 = __toESM(require_core());
async function sendCompletedStatusReport3(startedAt2, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, logger, error3) {
async function sendCompletedStatusReport3(startedAt, toolsDownloadStatusReport, toolsFeatureFlagsValid, toolsSource, toolsVersion, logger, error3) {
const statusReportBase = await createStatusReportBase(
"setup-codeql" /* SetupCodeQL */,
getActionsStatus(error3),
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger,
@@ -158958,7 +158957,7 @@ async function sendCompletedStatusReport3(startedAt2, toolsDownloadStatusReport,
}
await sendStatusReport({ ...initStatusReport, ...initToolsDownloadFields });
}
async function run5(startedAt2) {
async function run5(startedAt) {
const logger = getActionsLogger();
let codeql;
let toolsDownloadStatusReport;
@@ -158989,7 +158988,7 @@ async function run5(startedAt2) {
const statusReportBase = await createStatusReportBase(
"setup-codeql" /* SetupCodeQL */,
"starting",
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger
@@ -159027,7 +159026,7 @@ async function run5(startedAt2) {
const statusReportBase = await createStatusReportBase(
"setup-codeql" /* SetupCodeQL */,
error3 instanceof ConfigurationError ? "user-error" : "failure",
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger,
@@ -159040,7 +159039,7 @@ async function run5(startedAt2) {
return;
}
await sendCompletedStatusReport3(
startedAt2,
startedAt,
toolsDownloadStatusReport,
toolsFeatureFlagsValid,
toolsSource,
@@ -159049,15 +159048,15 @@ async function run5(startedAt2) {
);
}
async function runWrapper5() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run5(startedAt2);
await run5(startedAt);
} catch (error3) {
core21.setFailed(`setup-codeql action failed: ${getErrorMessage(error3)}`);
await sendUnhandledErrorStatusReport(
"setup-codeql" /* SetupCodeQL */,
startedAt2,
startedAt,
error3,
logger
);
@@ -159525,11 +159524,11 @@ var StartProxyError = class extends Error {
this.errorType = errorType;
}
};
async function sendSuccessStatusReport(startedAt2, config, registry_types, logger) {
async function sendSuccessStatusReport(startedAt, config, registry_types, logger) {
const statusReportBase = await createStatusReportBase(
"start-proxy" /* StartProxy */,
"success",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -159548,14 +159547,14 @@ function getSafeErrorMessage(error3) {
}
return `Error from start-proxy Action omitted (${error3.constructor.name}).`;
}
async function sendFailedStatusReport(logger, startedAt2, language, unwrappedError) {
async function sendFailedStatusReport(logger, startedAt, language, unwrappedError) {
const error3 = wrapError(unwrappedError);
core23.setFailed(`start-proxy action failed: ${error3.message}`);
const statusReportMessage = getSafeErrorMessage(error3);
const errorStatusReportBase = await createStatusReportBase(
"start-proxy" /* StartProxy */,
getActionsStatus(error3),
startedAt2,
startedAt,
{
languages: language === void 0 ? void 0 : [language]
},
@@ -160121,7 +160120,7 @@ async function checkConnections(logger, proxy, backend) {
}
// src/start-proxy-action.ts
async function run6(startedAt2) {
async function run6(startedAt) {
const logger = getActionsLogger();
let features;
let language;
@@ -160181,7 +160180,7 @@ async function run6(startedAt2) {
);
await checkConnections(logger, proxyInfo);
await sendSuccessStatusReport(
startedAt2,
startedAt,
{
languages: language === void 0 ? void 0 : [language]
},
@@ -160189,19 +160188,19 @@ async function run6(startedAt2) {
logger
);
} catch (unwrappedError) {
await sendFailedStatusReport(logger, startedAt2, language, unwrappedError);
await sendFailedStatusReport(logger, startedAt, language, unwrappedError);
}
}
async function runWrapper6() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run6(startedAt2);
await run6(startedAt);
} catch (error3) {
core24.setFailed(`start-proxy action failed: ${getErrorMessage(error3)}`);
await sendUnhandledErrorStatusReport(
"start-proxy" /* StartProxy */,
startedAt2,
startedAt,
getSafeErrorMessage(wrapError(error3)),
logger
);
@@ -160257,11 +160256,11 @@ async function startProxy(binPath, config, logFilePath, logger) {
// src/upload-sarif-action.ts
var core25 = __toESM(require_core());
async function sendSuccessStatusReport2(startedAt2, uploadStats, logger) {
async function sendSuccessStatusReport2(startedAt, uploadStats, logger) {
const statusReportBase = await createStatusReportBase(
"upload-sarif" /* UploadSarif */,
"success",
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger
@@ -160274,7 +160273,7 @@ async function sendSuccessStatusReport2(startedAt2, uploadStats, logger) {
await sendStatusReport(statusReport);
}
}
async function run7(startedAt2) {
async function run7(startedAt) {
const logger = getActionsLogger();
try {
initializeEnvironment(getActionVersion());
@@ -160291,7 +160290,7 @@ async function run7(startedAt2) {
const startingStatusReportBase = await createStatusReportBase(
"upload-sarif" /* UploadSarif */,
"starting",
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger
@@ -160334,7 +160333,7 @@ async function run7(startedAt2) {
}
}
await sendSuccessStatusReport2(
startedAt2,
startedAt,
codeScanningResult?.statusReport || {},
logger
);
@@ -160345,7 +160344,7 @@ async function run7(startedAt2) {
const errorStatusReportBase = await createStatusReportBase(
"upload-sarif" /* UploadSarif */,
getActionsStatus(error3),
startedAt2,
startedAt,
void 0,
await checkDiskUsage(logger),
logger,
@@ -160359,17 +160358,17 @@ async function run7(startedAt2) {
}
}
async function runWrapper7() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run7(startedAt2);
await run7(startedAt);
} catch (error3) {
core25.setFailed(
`codeql/upload-sarif action failed: ${getErrorMessage(error3)}`
);
await sendUnhandledErrorStatusReport(
"upload-sarif" /* UploadSarif */,
startedAt2,
startedAt,
error3,
logger
);
@@ -161003,7 +161002,7 @@ async function removeUploadedSarif(uploadFailedSarifResult, logger) {
}
// src/init-action-post.ts
async function run8(startedAt2) {
async function run8(startedAt) {
const logger = getActionsLogger();
let config;
let uploadFailedSarifResult;
@@ -161045,7 +161044,7 @@ async function run8(startedAt2) {
const statusReportBase2 = await createStatusReportBase(
"init-post" /* InitPost */,
getActionsStatus(error3),
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger,
@@ -161062,7 +161061,7 @@ async function run8(startedAt2) {
const statusReportBase = await createStatusReportBase(
"init-post" /* InitPost */,
"success",
startedAt2,
startedAt,
config,
await checkDiskUsage(logger),
logger
@@ -161107,15 +161106,15 @@ function getJobStatusFromEnvironment() {
return void 0;
}
async function runWrapper9() {
const startedAt2 = /* @__PURE__ */ new Date();
const startedAt = /* @__PURE__ */ new Date();
const logger = getActionsLogger();
try {
await run8(startedAt2);
await run8(startedAt);
} catch (error3) {
core28.setFailed(`init post action failed: ${wrapError(error3).message}`);
await sendUnhandledErrorStatusReport(
"init-post" /* InitPost */,
startedAt2,
startedAt,
error3,
logger
);
+1 -1
View File
@@ -69,7 +69,7 @@ test("analyze action with RAM & threads from environment variables", async (t) =
// level but does not wait for it to finish. To ensure that calls to
// runFinalize and runQueries are correctly captured by spies, we explicitly
// wait for the action promise to complete before starting verification.
await analyzeAction.runPromise;
await analyzeAction.runWrapper();
t.assert(
runFinalizeStub.calledOnceWith(
+1 -1
View File
@@ -67,7 +67,7 @@ test("analyze action with RAM & threads from action inputs", async (t) => {
// level but does not wait for it to finish. To ensure that calls to
// runFinalize and runQueries are correctly captured by spies, we explicitly
// wait for the action promise to complete before starting verification.
await analyzeAction.runPromise;
await analyzeAction.runWrapper();
t.assert(
runFinalizeStub.calledOnceWith(
+2 -5
View File
@@ -523,14 +523,11 @@ async function run(startedAt: Date) {
}
}
// Module-level startedAt so it can be accessed by runWrapper for error reporting
const startedAt = new Date();
export const runPromise = run(startedAt);
export async function runWrapper() {
const startedAt = new Date();
const logger = getActionsLogger();
try {
await runPromise;
await run(startedAt);
} catch (error) {
core.setFailed(`analyze action failed: ${util.getErrorMessage(error)}`);
await sendUnhandledErrorStatusReport(