mirror of
https://github.com/github/codeql-action.git
synced 2025-12-27 09:40:17 +08:00
Merge branch 'main' into henrymercer/add-ml-powered-query-enablement-to-analyze-status-report
This commit is contained in:
@@ -15,7 +15,6 @@ import {
|
||||
import { CODEQL_VERSION_NEW_TRACING, getCodeQL } from "./codeql";
|
||||
import { Config, getConfig } from "./config-utils";
|
||||
import { uploadDatabases } from "./database-upload";
|
||||
import { GitHubFeatureFlags } from "./feature-flags";
|
||||
import { getActionsLogger } from "./logging";
|
||||
import { parseRepositoryNwo } from "./repository";
|
||||
import * as upload_lib from "./upload-lib";
|
||||
@@ -112,12 +111,6 @@ async function run() {
|
||||
util.getRequiredEnvParam("GITHUB_REPOSITORY")
|
||||
);
|
||||
|
||||
const featureFlags = new GitHubFeatureFlags(
|
||||
config.gitHubVersion,
|
||||
apiDetails,
|
||||
repositoryNwo,
|
||||
logger
|
||||
);
|
||||
await runFinalize(outputDir, threads, memory, config, logger);
|
||||
if (actionsUtil.getRequiredInput("skip-queries") !== "true") {
|
||||
runStats = await runQueries(
|
||||
@@ -200,13 +193,7 @@ async function run() {
|
||||
}
|
||||
|
||||
// Possibly upload the database bundles for remote queries
|
||||
await uploadDatabases(
|
||||
repositoryNwo,
|
||||
config,
|
||||
featureFlags,
|
||||
apiDetails,
|
||||
logger
|
||||
);
|
||||
await uploadDatabases(repositoryNwo, config, apiDetails, logger);
|
||||
|
||||
if (
|
||||
uploadResult !== undefined &&
|
||||
|
||||
@@ -10,7 +10,6 @@ import * as apiClient from "./api-client";
|
||||
import { setCodeQL } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import { uploadDatabases } from "./database-upload";
|
||||
import { createFeatureFlags, FeatureFlag } from "./feature-flags";
|
||||
import { Language } from "./languages";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import {
|
||||
@@ -35,10 +34,6 @@ test.beforeEach(() => {
|
||||
initializeEnvironment(Mode.actions, "1.2.3");
|
||||
});
|
||||
|
||||
const uploadToUploadsDomainFlags = createFeatureFlags([
|
||||
FeatureFlag.DatabaseUploadsEnabled,
|
||||
]);
|
||||
|
||||
const testRepoName: RepositoryNwo = { owner: "github", repo: "example" };
|
||||
const testApiDetails: GitHubApiDetails = {
|
||||
auth: "1234",
|
||||
@@ -97,7 +92,6 @@ test("Abort database upload if 'upload-database' input set to false", async (t)
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
uploadToUploadsDomainFlags,
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -127,7 +121,6 @@ test("Abort database upload if running against GHES", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
config,
|
||||
createFeatureFlags([]),
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -157,7 +150,6 @@ test("Abort database upload if running against GHAE", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
config,
|
||||
createFeatureFlags([]),
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -184,7 +176,6 @@ test("Abort database upload if not analyzing default branch", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
uploadToUploadsDomainFlags,
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -198,40 +189,6 @@ test("Abort database upload if not analyzing default branch", async (t) => {
|
||||
});
|
||||
});
|
||||
|
||||
test("Abort database upload if feature flag is disabled", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
sinon
|
||||
.stub(actionsUtil, "getRequiredInput")
|
||||
.withArgs("upload-database")
|
||||
.returns("true");
|
||||
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
|
||||
|
||||
setCodeQL({
|
||||
async databaseBundle() {
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
const loggedMessages = [];
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
createFeatureFlags([]),
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
t.assert(
|
||||
loggedMessages.find(
|
||||
(v: LoggedMessage) =>
|
||||
v.type === "debug" &&
|
||||
v.message ===
|
||||
"Repository is not opted in to database uploads. Skipping upload."
|
||||
) !== undefined
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("Don't crash if uploading a database fails", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
setupActionsVars(tmpDir, tmpDir);
|
||||
@@ -241,10 +198,6 @@ test("Don't crash if uploading a database fails", async (t) => {
|
||||
.returns("true");
|
||||
sinon.stub(actionsUtil, "isAnalyzingDefaultBranch").resolves(true);
|
||||
|
||||
const featureFlags = createFeatureFlags([
|
||||
FeatureFlag.DatabaseUploadsEnabled,
|
||||
]);
|
||||
|
||||
await mockHttpRequests(500);
|
||||
|
||||
setCodeQL({
|
||||
@@ -257,7 +210,6 @@ test("Don't crash if uploading a database fails", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
featureFlags,
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -294,7 +246,6 @@ test("Successfully uploading a database to api.github.com", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
uploadToUploadsDomainFlags,
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
@@ -329,7 +280,6 @@ test("Successfully uploading a database to uploads.github.com", async (t) => {
|
||||
await uploadDatabases(
|
||||
testRepoName,
|
||||
getTestConfig(tmpDir),
|
||||
uploadToUploadsDomainFlags,
|
||||
testApiDetails,
|
||||
getRecordingLogger(loggedMessages)
|
||||
);
|
||||
|
||||
@@ -4,7 +4,6 @@ import * as actionsUtil from "./actions-util";
|
||||
import { getApiClient, GitHubApiDetails } from "./api-client";
|
||||
import { getCodeQL } from "./codeql";
|
||||
import { Config } from "./config-utils";
|
||||
import { FeatureFlag, FeatureFlags } from "./feature-flags";
|
||||
import { Logger } from "./logging";
|
||||
import { RepositoryNwo } from "./repository";
|
||||
import * as util from "./util";
|
||||
@@ -13,7 +12,6 @@ import { bundleDb } from "./util";
|
||||
export async function uploadDatabases(
|
||||
repositoryNwo: RepositoryNwo,
|
||||
config: Config,
|
||||
featureFlags: FeatureFlags,
|
||||
apiDetails: GitHubApiDetails,
|
||||
logger: Logger
|
||||
): Promise<void> {
|
||||
@@ -34,13 +32,6 @@ export async function uploadDatabases(
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(await featureFlags.getValue(FeatureFlag.DatabaseUploadsEnabled))) {
|
||||
logger.debug(
|
||||
"Repository is not opted in to database uploads. Skipping upload."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const client = getApiClient(apiDetails);
|
||||
const codeql = await getCodeQL(config.codeQLCmd);
|
||||
|
||||
|
||||
@@ -85,10 +85,7 @@ test("Feature flags are disabled if they're not returned in API response", async
|
||||
t.assert((await featureFlags.getValue(flag)) === false);
|
||||
}
|
||||
|
||||
for (const featureFlag of [
|
||||
"database_uploads_enabled",
|
||||
"ml_powered_queries_enabled",
|
||||
]) {
|
||||
for (const featureFlag of ["ml_powered_queries_enabled"]) {
|
||||
t.assert(
|
||||
loggedMessages.find(
|
||||
(v: LoggedMessage) =>
|
||||
@@ -115,7 +112,7 @@ test("Feature flags exception is propagated if the API request errors", async (t
|
||||
mockFeatureFlagApiEndpoint(500, {});
|
||||
|
||||
await t.throwsAsync(
|
||||
async () => featureFlags.getValue(FeatureFlag.DatabaseUploadsEnabled),
|
||||
async () => featureFlags.getValue(FeatureFlag.MlPoweredQueriesEnabled),
|
||||
{
|
||||
message:
|
||||
"Encountered an error while trying to load feature flags: Error: some error message",
|
||||
@@ -124,10 +121,7 @@ test("Feature flags exception is propagated if the API request errors", async (t
|
||||
});
|
||||
});
|
||||
|
||||
const FEATURE_FLAGS = [
|
||||
"database_uploads_enabled",
|
||||
"ml_powered_queries_enabled",
|
||||
];
|
||||
const FEATURE_FLAGS = ["ml_powered_queries_enabled"];
|
||||
|
||||
for (const featureFlag of FEATURE_FLAGS) {
|
||||
test(`Feature flag '${featureFlag}' is enabled if enabled in the API response`, async (t) => {
|
||||
@@ -149,9 +143,6 @@ for (const featureFlag of FEATURE_FLAGS) {
|
||||
mockFeatureFlagApiEndpoint(200, expectedFeatureFlags);
|
||||
|
||||
const actualFeatureFlags: { [flag: string]: boolean } = {
|
||||
database_uploads_enabled: await featureFlags.getValue(
|
||||
FeatureFlag.DatabaseUploadsEnabled
|
||||
),
|
||||
ml_powered_queries_enabled: await featureFlags.getValue(
|
||||
FeatureFlag.MlPoweredQueriesEnabled
|
||||
),
|
||||
|
||||
@@ -8,7 +8,6 @@ export interface FeatureFlags {
|
||||
}
|
||||
|
||||
export enum FeatureFlag {
|
||||
DatabaseUploadsEnabled = "database_uploads_enabled",
|
||||
MlPoweredQueriesEnabled = "ml_powered_queries_enabled",
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user