Move getOrInitCodeQL to upload-sarif

This commit is contained in:
Michael B. Gale
2026-02-24 19:59:56 +00:00
parent b30d90c496
commit 37f3bfc967
3 changed files with 1914 additions and 1911 deletions
+1878 -1876
View File
File diff suppressed because it is too large Load Diff
+3 -34
View File
@@ -3,9 +3,8 @@ import * as core from "@actions/core";
import * as actionsUtil from "./actions-util";
import * as analyses from "./analyses";
import { getGitHubVersion } from "./api-client";
import { CodeQL, getCodeQL } from "./codeql";
import { Config, getConfig } from "./config-utils";
import { FeatureEnablement, initFeatures } from "./feature-flags";
import { getConfig } from "./config-utils";
import { initFeatures } from "./feature-flags";
import { Logger, getActionsLogger } from "./logging";
import { getRepositoryNwo } from "./repository";
import {
@@ -18,10 +17,9 @@ import {
isThirdPartyAnalysis,
} from "./status-report";
import * as upload_lib from "./upload-lib";
import { postProcessAndUploadSarif } from "./upload-sarif";
import { getOrInitCodeQL, postProcessAndUploadSarif } from "./upload-sarif";
import {
ConfigurationError,
GitHubVersion,
checkActionVersion,
checkDiskUsage,
getErrorMessage,
@@ -56,35 +54,6 @@ async function sendSuccessStatusReport(
}
}
/** The cached `CodeQL` instance, if any. */
let codeql: CodeQL | undefined;
/** Get or initialise a `CodeQL` instance for use by the `upload-sarif` action. */
async function getOrInitCodeQL(
logger: Logger,
gitHubVersion: GitHubVersion,
features: FeatureEnablement,
config: Config | undefined,
): Promise<CodeQL> {
// Return the cached instance, if we have one.
if (codeql !== undefined) return codeql;
// 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) {
codeql = await getCodeQL(config.codeQLCmd);
} else {
codeql = await upload_lib.minimalInitCodeQL(
logger,
gitHubVersion,
features,
);
}
return codeql;
}
async function run(startedAt: Date) {
// To capture errors appropriately, keep as much code within the try-catch as
// possible, and only use safe functions outside.
+33 -1
View File
@@ -1,15 +1,47 @@
import { UploadKind } from "./actions-util";
import * as analyses from "./analyses";
import type { CodeQL } from "./codeql";
import * as codeql from "./codeql";
import { Config } from "./config-utils";
import { FeatureEnablement } from "./feature-flags";
import { Logger } from "./logging";
import * as upload_lib from "./upload-lib";
import { unsafeEntriesInvariant } from "./util";
import { GitHubVersion, unsafeEntriesInvariant } from "./util";
// Maps analysis kinds to SARIF IDs.
export type UploadSarifResults = Partial<
Record<analyses.AnalysisKind, upload_lib.UploadResult>
>;
/** 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(
logger: Logger,
gitHubVersion: GitHubVersion,
features: FeatureEnablement,
config: Config | undefined,
): Promise<CodeQL> {
// Return the cached instance, if we have one.
if (cachedCodeQL !== undefined) return 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);
} else {
cachedCodeQL = await upload_lib.minimalInitCodeQL(
logger,
gitHubVersion,
features,
);
}
return cachedCodeQL;
}
/**
* Finds SARIF files in `sarifPath`, post-processes them, and uploads them to the appropriate services.
*