Skip to content

Commit c649c59

Browse files
committed
Upload overlay base DB to API behind FF
1 parent 31042e9 commit c649c59

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

lib/analyze-action.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/analyze-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ async function run() {
429429
codeql,
430430
config,
431431
apiDetails,
432+
features,
432433
logger,
433434
);
434435

src/codeql.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { ToolsDownloadStatusReport } from "./tools-download";
3535
import { ToolsFeature, isSupportedToolsFeature } from "./tools-features";
3636
import { shouldEnableIndirectTracing } from "./tracer-config";
3737
import * as util from "./util";
38-
import { BuildMode, getErrorMessage } from "./util";
38+
import { BuildMode, CleanupLevel, getErrorMessage } from "./util";
3939

4040
type Options = Array<string | number | boolean>;
4141

@@ -141,7 +141,10 @@ export interface CodeQL {
141141
/**
142142
* Clean up all the databases within a database cluster.
143143
*/
144-
databaseCleanupCluster(config: Config, cleanupLevel: string): Promise<void>;
144+
databaseCleanupCluster(
145+
config: Config,
146+
cleanupLevel: CleanupLevel,
147+
): Promise<void>;
145148
/**
146149
* Run 'codeql database bundle'.
147150
*/
@@ -878,7 +881,7 @@ export async function getCodeQLForCmd(
878881
},
879882
async databaseCleanupCluster(
880883
config: Config,
881-
cleanupLevel: string,
884+
cleanupLevel: CleanupLevel,
882885
): Promise<void> {
883886
const cacheCleanupFlag = (await util.codeQlVersionAtLeast(
884887
this,

src/database-upload.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import * as gitUtils from "./git-utils";
1515
import { KnownLanguage } from "./languages";
1616
import { RepositoryNwo } from "./repository";
1717
import {
18+
createFeatures,
1819
createTestConfig,
1920
getRecordingLogger,
2021
LoggedMessage,
@@ -96,6 +97,7 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
9697
getCodeQL(),
9798
getTestConfig(tmpDir),
9899
testApiDetails,
100+
createFeatures([]),
99101
getRecordingLogger(loggedMessages),
100102
);
101103
t.assert(
@@ -129,6 +131,7 @@ test("Abort database upload if 'analysis-kinds: code-scanning' is not enabled",
129131
analysisKinds: [AnalysisKind.CodeQuality],
130132
},
131133
testApiDetails,
134+
createFeatures([]),
132135
getRecordingLogger(loggedMessages),
133136
);
134137
t.assert(
@@ -160,6 +163,7 @@ test("Abort database upload if running against GHES", async (t) => {
160163
getCodeQL(),
161164
config,
162165
testApiDetails,
166+
createFeatures([]),
163167
getRecordingLogger(loggedMessages),
164168
);
165169
t.assert(
@@ -188,6 +192,7 @@ test("Abort database upload if not analyzing default branch", async (t) => {
188192
getCodeQL(),
189193
getTestConfig(tmpDir),
190194
testApiDetails,
195+
createFeatures([]),
191196
getRecordingLogger(loggedMessages),
192197
);
193198
t.assert(
@@ -217,6 +222,7 @@ test("Don't crash if uploading a database fails", async (t) => {
217222
getCodeQL(),
218223
getTestConfig(tmpDir),
219224
testApiDetails,
225+
createFeatures([]),
220226
getRecordingLogger(loggedMessages),
221227
);
222228

@@ -248,6 +254,7 @@ test("Successfully uploading a database to github.com", async (t) => {
248254
getCodeQL(),
249255
getTestConfig(tmpDir),
250256
testApiDetails,
257+
createFeatures([]),
251258
getRecordingLogger(loggedMessages),
252259
);
253260
t.assert(
@@ -281,6 +288,7 @@ test("Successfully uploading a database to GHEC-DR", async (t) => {
281288
url: "https://tenant.ghe.com",
282289
apiURL: undefined,
283290
},
291+
createFeatures([]),
284292
getRecordingLogger(loggedMessages),
285293
);
286294
t.assert(

src/database-upload.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ import { AnalysisKind } from "./analyses";
55
import { getApiClient, GitHubApiDetails } from "./api-client";
66
import { type CodeQL } from "./codeql";
77
import { Config } from "./config-utils";
8+
import { Feature, FeatureEnablement } from "./feature-flags";
89
import * as gitUtils from "./git-utils";
910
import { Logger, withGroupAsync } from "./logging";
11+
import { OverlayDatabaseMode } from "./overlay-database-utils";
1012
import { RepositoryNwo } from "./repository";
1113
import * as util from "./util";
12-
import { bundleDb, parseGitHubUrl } from "./util";
14+
import { bundleDb, CleanupLevel, parseGitHubUrl } from "./util";
1315

1416
export async function cleanupAndUploadDatabases(
1517
repositoryNwo: RepositoryNwo,
1618
codeql: CodeQL,
1719
config: Config,
1820
apiDetails: GitHubApiDetails,
21+
features: FeatureEnablement,
1922
logger: Logger,
2023
): Promise<void> {
2124
if (actionsUtil.getRequiredInput("upload-database") !== "true") {
@@ -50,10 +53,16 @@ export async function cleanupAndUploadDatabases(
5053
return;
5154
}
5255

56+
const cleanupLevel =
57+
config.overlayDatabaseMode === OverlayDatabaseMode.OverlayBase &&
58+
(await features.getValue(Feature.UploadOverlayDbToApi))
59+
? CleanupLevel.Overlay
60+
: CleanupLevel.Clear;
61+
5362
// Clean up the database, since intermediate results may still be written to the
5463
// database if there is high RAM pressure.
5564
await withGroupAsync("Cleaning up databases", async () => {
56-
await codeql.databaseCleanupCluster(config, "clear");
65+
await codeql.databaseCleanupCluster(config, cleanupLevel);
5766
});
5867

5968
const client = getApiClient();

src/overlay-database-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { type Config } from "./config-utils";
1616
import { getCommitOid, getFileOidsUnderPath } from "./git-utils";
1717
import { Logger, withGroupAsync } from "./logging";
1818
import {
19+
CleanupLevel,
1920
getErrorMessage,
2021
isInTestMode,
2122
tryGetFolderBytes,
@@ -242,7 +243,7 @@ export async function cleanupAndUploadOverlayBaseDatabaseToCache(
242243

243244
// Clean up the database using the overlay cleanup level.
244245
await withGroupAsync("Cleaning up databases", async () => {
245-
await codeql.databaseCleanupCluster(config, "overlay");
246+
await codeql.databaseCleanupCluster(config, CleanupLevel.Overlay);
246247
});
247248

248249
const dbLocation = config.dbLocation;

src/util.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,3 +1314,8 @@ export function unsafeEntriesInvariant<T extends Record<string, any>>(
13141314
([_, val]) => val !== undefined,
13151315
) as Array<[keyof T, Exclude<T[keyof T], undefined>]>;
13161316
}
1317+
1318+
export enum CleanupLevel {
1319+
Clear = "clear",
1320+
Overlay = "overlay",
1321+
}

0 commit comments

Comments
 (0)