diff --git a/lib/analyze-action.js b/lib/analyze-action.js index 7e4e89eeab..b9c6cc2abe 100644 --- a/lib/analyze-action.js +++ b/lib/analyze-action.js @@ -108012,7 +108012,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/autobuild-action.js b/lib/autobuild-action.js index e495cffbee..f542bd4361 100644 --- a/lib/autobuild-action.js +++ b/lib/autobuild-action.js @@ -103130,6 +103130,10 @@ function getWorkflowRunAttempt() { function isSelfHostedRunner() { return process.env.RUNNER_ENVIRONMENT === "self-hosted"; } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; +function isCCR() { + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; +} function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); } @@ -104345,7 +104349,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/init-action-post.js b/lib/init-action-post.js index 1f1869f412..ea87c71e31 100644 --- a/lib/init-action-post.js +++ b/lib/init-action-post.js @@ -165338,7 +165338,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/init-action.js b/lib/init-action.js index 34c83bc4ae..e4841c5d33 100644 --- a/lib/init-action.js +++ b/lib/init-action.js @@ -105545,7 +105545,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/setup-codeql-action.js b/lib/setup-codeql-action.js index 445f3b5768..2a999e3fe5 100644 --- a/lib/setup-codeql-action.js +++ b/lib/setup-codeql-action.js @@ -103247,6 +103247,10 @@ function isSelfHostedRunner() { function isDynamicWorkflow() { return getWorkflowEventName() === "dynamic"; } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; +function isCCR() { + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; +} function prettyPrintInvocation(cmd, args) { return [cmd, ...args].map((x) => x.includes(" ") ? `'${x}'` : x).join(" "); } @@ -104246,7 +104250,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/start-proxy-action.js b/lib/start-proxy-action.js index 1aa9d0f634..7d43b435de 100644 --- a/lib/start-proxy-action.js +++ b/lib/start-proxy-action.js @@ -120267,6 +120267,10 @@ function getWorkflowRunAttempt() { function isSelfHostedRunner() { return process.env.RUNNER_ENVIRONMENT === "self-hosted"; } +var CCR_KEY_PREFIX = "dynamic/copilot-pull-request-reviewer"; +function isCCR() { + return process.env["CODEQL_ACTION_ANALYSIS_KEY" /* ANALYSIS_KEY */]?.startsWith(CCR_KEY_PREFIX) || false; +} var persistedInputsKey = "persisted_inputs"; var persistInputs = function() { const inputEnvironmentVariables = Object.entries(process.env).filter( @@ -121039,7 +121043,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index e326893e67..f05e5330f7 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -107200,7 +107200,14 @@ var GitHubFeatureFlags = class { async loadApiResponse() { if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features." + "Not running against github.com. Using default values for all features." + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features." ); this.hasAccessedRemoteFeatureFlags = false; return {}; diff --git a/src/feature-flags.test.ts b/src/feature-flags.test.ts index cdab85e279..6632cf2523 100644 --- a/src/feature-flags.test.ts +++ b/src/feature-flags.test.ts @@ -4,6 +4,7 @@ import * as path from "path"; import test, { ExecutionContext } from "ava"; import * as defaults from "./defaults.json"; +import { EnvVar } from "./environment"; import { Feature, featureConfig, @@ -37,29 +38,39 @@ test.beforeEach(() => { const testRepositoryNwo = parseRepositoryNwo("github/example"); -test(`All features are disabled if running against GHES`, async (t) => { +test(`All features use default values if running against GHES`, async (t) => { await withTmpDir(async (tmpDir) => { - const loggedMessages = []; + const loggedMessages: LoggedMessage[] = []; const features = setUpFeatureFlagTests( tmpDir, getRecordingLogger(loggedMessages), { type: GitHubVariant.GHES, version: "3.0.0" }, ); - for (const feature of Object.values(Feature)) { - t.deepEqual( - await getFeatureIncludingCodeQlIfRequired(features, feature), - featureConfig[feature].defaultValue, - ); - } + await assertAllFeaturesHaveDefaultValues(t, features); + assertLoggedMessage( + t, + loggedMessages, + "Not running against github.com. Using default values for all features.", + ); + }); +}); - t.assert( - loggedMessages.find( - (v: LoggedMessage) => - v.type === "debug" && - v.message === - "Not running against github.com. Disabling all toggleable features.", - ) !== undefined, +test(`All features use default values if running in CCR`, async (t) => { + await withTmpDir(async (tmpDir) => { + const loggedMessages: LoggedMessage[] = []; + const features = setUpFeatureFlagTests( + tmpDir, + getRecordingLogger(loggedMessages), + ); + + process.env[EnvVar.ANALYSIS_KEY] = "dynamic/copilot-pull-request-reviewer"; + + await assertAllFeaturesHaveDefaultValues(t, features); + assertLoggedMessage( + t, + loggedMessages, + "Feature flags are not supported in Copilot Code Review. Using default values for all features.", ); }); }); @@ -542,6 +553,30 @@ test("non-legacy feature flags should not start with codeql_action_", async (t) } }); +async function assertAllFeaturesHaveDefaultValues( + t: ExecutionContext, + features: FeatureEnablement, +) { + for (const feature of Object.values(Feature)) { + t.deepEqual( + await getFeatureIncludingCodeQlIfRequired(features, feature), + featureConfig[feature].defaultValue, + ); + } +} + +function assertLoggedMessage( + t: ExecutionContext, + loggedMessages: LoggedMessage[], + expectedMessage: string, +) { + t.assert( + loggedMessages.find( + (v: LoggedMessage) => v.type === "debug" && v.message === expectedMessage, + ) !== undefined, + ); +} + function assertAllFeaturesUndefinedInApi( t: ExecutionContext, loggedMessages: LoggedMessage[], diff --git a/src/feature-flags.ts b/src/feature-flags.ts index ea8cc1767b..04508089d9 100644 --- a/src/feature-flags.ts +++ b/src/feature-flags.ts @@ -3,6 +3,7 @@ import * as path from "path"; import * as semver from "semver"; +import { isCCR } from "./actions-util"; import { getApiClient } from "./api-client"; import type { CodeQL } from "./codeql"; import * as defaults from "./defaults.json"; @@ -664,7 +665,14 @@ class GitHubFeatureFlags { // Do nothing when not running against github.com if (!supportsFeatureFlags(this.gitHubVersion.type)) { this.logger.debug( - "Not running against github.com. Disabling all toggleable features.", + "Not running against github.com. Using default values for all features.", + ); + this.hasAccessedRemoteFeatureFlags = false; + return {}; + } + if (isCCR()) { + this.logger.debug( + "Feature flags are not supported in Copilot Code Review. Using default values for all features.", ); this.hasAccessedRemoteFeatureFlags = false; return {};