mirror of
https://github.com/github/codeql-action.git
synced 2025-12-06 07:48:17 +08:00
Upload overlay base DB to API behind FF
This commit is contained in:
@@ -429,6 +429,7 @@ async function run() {
|
||||
codeql,
|
||||
config,
|
||||
apiDetails,
|
||||
features,
|
||||
logger,
|
||||
);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ import { ToolsDownloadStatusReport } from "./tools-download";
|
||||
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
|
||||
import { shouldEnableIndirectTracing } from "./tracer-config";
|
||||
import * as util from "./util";
|
||||
import { BuildMode, getErrorMessage } from "./util";
|
||||
import { BuildMode, CleanupLevel, getErrorMessage } from "./util";
|
||||
|
||||
type Options = Array<string | number | boolean>;
|
||||
|
||||
@@ -141,7 +141,10 @@ export interface CodeQL {
|
||||
/**
|
||||
* Clean up all the databases within a database cluster.
|
||||
*/
|
||||
databaseCleanupCluster(config: Config, cleanupLevel: string): Promise<void>;
|
||||
databaseCleanupCluster(
|
||||
config: Config,
|
||||
cleanupLevel: CleanupLevel,
|
||||
): Promise<void>;
|
||||
/**
|
||||
* Run 'codeql database bundle'.
|
||||
*/
|
||||
@@ -878,7 +881,7 @@ export async function getCodeQLForCmd(
|
||||
},
|
||||
async databaseCleanupCluster(
|
||||
config: Config,
|
||||
cleanupLevel: string,
|
||||
cleanupLevel: CleanupLevel,
|
||||
): Promise<void> {
|
||||
const cacheCleanupFlag = (await util.codeQlVersionAtLeast(
|
||||
this,
|
||||
|
||||
@@ -15,6 +15,7 @@ import * as gitUtils from "./git-utils";
|
||||
import { KnownLanguage } from "./languages";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import {
|
||||
createFeatures,
|
||||
createTestConfig,
|
||||
getRecordingLogger,
|
||||
LoggedMessage,
|
||||
@@ -96,6 +97,7 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
|
||||
getCodeQL(),
|
||||
getTestConfig(tmpDir),
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
@@ -129,6 +131,7 @@ test("Abort database upload if 'analysis-kinds: code-scanning' is not enabled",
|
||||
analysisKinds: [AnalysisKind.CodeQuality],
|
||||
},
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
@@ -160,6 +163,7 @@ test("Abort database upload if running against GHES", async (t) => {
|
||||
getCodeQL(),
|
||||
config,
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
@@ -188,6 +192,7 @@ test("Abort database upload if not analyzing default branch", async (t) => {
|
||||
getCodeQL(),
|
||||
getTestConfig(tmpDir),
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
@@ -217,6 +222,7 @@ test("Don't crash if uploading a database fails", async (t) => {
|
||||
getCodeQL(),
|
||||
getTestConfig(tmpDir),
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
|
||||
@@ -248,6 +254,7 @@ test("Successfully uploading a database to github.com", async (t) => {
|
||||
getCodeQL(),
|
||||
getTestConfig(tmpDir),
|
||||
testApiDetails,
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
@@ -281,6 +288,7 @@ test("Successfully uploading a database to GHEC-DR", async (t) => {
|
||||
url: "https://tenant.ghe.com",
|
||||
apiURL: undefined,
|
||||
},
|
||||
createFeatures([]),
|
||||
getRecordingLogger(loggedMessages),
|
||||
);
|
||||
t.assert(
|
||||
|
||||
@@ -5,17 +5,20 @@ import { AnalysisKind } from "./analyses";
|
||||
import { getApiClient, GitHubApiDetails } from "./api-client";
|
||||
import { type CodeQL } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import { Feature, FeatureEnablement } from "./feature-flags";
|
||||
import * as gitUtils from "./git-utils";
|
||||
import { Logger, withGroupAsync } from "./logging";
|
||||
import { OverlayDatabaseMode } from "./overlay-database-utils";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import * as util from "./util";
|
||||
import { bundleDb, parseGitHubUrl } from "./util";
|
||||
import { bundleDb, CleanupLevel, parseGitHubUrl } from "./util";
|
||||
|
||||
export async function cleanupAndUploadDatabases(
|
||||
repositoryNwo: RepositoryNwo,
|
||||
codeql: CodeQL,
|
||||
config: Config,
|
||||
apiDetails: GitHubApiDetails,
|
||||
features: FeatureEnablement,
|
||||
logger: Logger,
|
||||
): Promise<void> {
|
||||
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
|
||||
@@ -50,10 +53,16 @@ export async function cleanupAndUploadDatabases(
|
||||
return;
|
||||
}
|
||||
|
||||
const cleanupLevel =
|
||||
config.overlayDatabaseMode === OverlayDatabaseMode.OverlayBase &&
|
||||
(await features.getValue(Feature.UploadOverlayDbToApi))
|
||||
? CleanupLevel.Overlay
|
||||
: CleanupLevel.Clear;
|
||||
|
||||
// Clean up the database, since intermediate results may still be written to the
|
||||
// database if there is high RAM pressure.
|
||||
await withGroupAsync("Cleaning up databases", async () => {
|
||||
await codeql.databaseCleanupCluster(config, "clear");
|
||||
await codeql.databaseCleanupCluster(config, cleanupLevel);
|
||||
});
|
||||
|
||||
const client = getApiClient();
|
||||
|
||||
@@ -16,6 +16,7 @@ import { type Config } from "./config-utils";
|
||||
import { getCommitOid, getFileOidsUnderPath } from "./git-utils";
|
||||
import { Logger, withGroupAsync } from "./logging";
|
||||
import {
|
||||
CleanupLevel,
|
||||
getErrorMessage,
|
||||
isInTestMode,
|
||||
tryGetFolderBytes,
|
||||
@@ -242,7 +243,7 @@ export async function cleanupAndUploadOverlayBaseDatabaseToCache(
|
||||
|
||||
// Clean up the database using the overlay cleanup level.
|
||||
await withGroupAsync("Cleaning up databases", async () => {
|
||||
await codeql.databaseCleanupCluster(config, "overlay");
|
||||
await codeql.databaseCleanupCluster(config, CleanupLevel.Overlay);
|
||||
});
|
||||
|
||||
const dbLocation = config.dbLocation;
|
||||
|
||||
@@ -1314,3 +1314,8 @@ export function unsafeEntriesInvariant<T extends Record<string, any>>(
|
||||
([_, val]) => val !== undefined,
|
||||
) as Array<[keyof T, Exclude<T[keyof T], undefined>]>;
|
||||
}
|
||||
|
||||
export enum CleanupLevel {
|
||||
Clear = "clear",
|
||||
Overlay = "overlay",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user