diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index d36868fa2..d9e0fea11 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -111370,19 +111370,18 @@ function filterAlertsByDiffRange(logger, sarif) { } // src/upload-sarif.ts -var cachedCodeQL2; -async function getOrInitCodeQL(logger, gitHubVersion, features, config) { - if (cachedCodeQL2 !== void 0) return cachedCodeQL2; +async function getOrInitCodeQL(actionState, logger, gitHubVersion, features, config) { + if (actionState.cachedCodeQL !== void 0) return actionState.cachedCodeQL; if (config !== void 0) { - cachedCodeQL2 = await getCodeQL(config.codeQLCmd); + actionState.cachedCodeQL = await getCodeQL(config.codeQLCmd); } else { - cachedCodeQL2 = await minimalInitCodeQL( + actionState.cachedCodeQL = await minimalInitCodeQL( logger, gitHubVersion, features ); } - return cachedCodeQL2; + return actionState.cachedCodeQL; } async function postProcessAndUploadSarif(logger, tempPath, features, getCodeQL2, uploadKind, checkoutPath, sarifPath, category, postProcessedOutputPath) { const sarifGroups = await getGroupedSarifFilePaths( @@ -111442,6 +111441,7 @@ async function sendSuccessStatusReport(startedAt, uploadStats, logger) { } async function run(startedAt) { const logger = getActionsLogger(); + const state = { cachedCodeQL: void 0 }; try { initializeEnvironment(getActionVersion()); const gitHubVersion = await getGitHubVersion(); @@ -111477,7 +111477,7 @@ async function run(startedAt) { logger, tempDir, features, - () => getOrInitCodeQL(logger, gitHubVersion, features, config), + () => getOrInitCodeQL(state, logger, gitHubVersion, features, config), "always", checkoutPath, sarifPath, diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index 4cc4bfc49..86894cce1 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -17,7 +17,11 @@ import { isThirdPartyAnalysis, } from "./status-report"; import * as upload_lib from "./upload-lib"; -import { getOrInitCodeQL, postProcessAndUploadSarif } from "./upload-sarif"; +import { + getOrInitCodeQL, + postProcessAndUploadSarif, + UploadSarifState, +} from "./upload-sarif"; import { ConfigurationError, checkActionVersion, @@ -59,6 +63,7 @@ async function run(startedAt: Date) { // possible, and only use safe functions outside. const logger = getActionsLogger(); + const state: UploadSarifState = { cachedCodeQL: undefined }; try { initializeEnvironment(actionsUtil.getActionVersion()); @@ -107,7 +112,7 @@ async function run(startedAt: Date) { logger, tempDir, features, - () => getOrInitCodeQL(logger, gitHubVersion, features, config), + () => getOrInitCodeQL(state, logger, gitHubVersion, features, config), "always", checkoutPath, sarifPath, diff --git a/src/upload-sarif.ts b/src/upload-sarif.ts index f704c2c28..95e2bf807 100644 --- a/src/upload-sarif.ts +++ b/src/upload-sarif.ts @@ -8,38 +8,41 @@ import { Logger } from "./logging"; import * as upload_lib from "./upload-lib"; import { GitHubVersion, unsafeEntriesInvariant } from "./util"; +export interface UploadSarifState { + /** The cached `CodeQL` instance, if any. */ + cachedCodeQL: CodeQL | undefined; +} + // Maps analysis kinds to SARIF IDs. export type UploadSarifResults = Partial< Record >; -/** The cached `CodeQL` instance, if any. */ -let cachedCodeQL: CodeQL | undefined; - /** Get or initialise a `CodeQL` instance for use by the `upload-sarif` action. */ export async function getOrInitCodeQL( + actionState: UploadSarifState, logger: Logger, gitHubVersion: GitHubVersion, features: FeatureEnablement, config: Config | undefined, ): Promise { // Return the cached instance, if we have one. - if (cachedCodeQL !== undefined) return cachedCodeQL; + if (actionState.cachedCodeQL !== undefined) return actionState.cachedCodeQL; // If we have been able to load a `Config` from an earlier CodeQL Action step in the job, // then use the CodeQL executable that we have used previously. Otherwise, initialise the // CLI specifically for `upload-sarif`. Either way, we cache the instance. if (config !== undefined) { - cachedCodeQL = await codeql.getCodeQL(config.codeQLCmd); + actionState.cachedCodeQL = await codeql.getCodeQL(config.codeQLCmd); } else { - cachedCodeQL = await upload_lib.minimalInitCodeQL( + actionState.cachedCodeQL = await upload_lib.minimalInitCodeQL( logger, gitHubVersion, features, ); } - return cachedCodeQL; + return actionState.cachedCodeQL; } /**