Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Abstract over FeatureEnablement implementations with initFeatures
  • Loading branch information
mbg committed Feb 15, 2026
commit 2c9bc45d4654f21e39a4b0ea16bdd4f667749c93
7 changes: 5 additions & 2 deletions lib/analyze-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/autobuild-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/init-action-post.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/init-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/setup-codeql-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/start-proxy-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion lib/upload-sarif-action.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/analyze-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from "./dependency-caching";
import { getDiffInformedAnalysisBranches } from "./diff-informed-analysis-utils";
import { EnvVar } from "./environment";
import { Features } from "./feature-flags";
import { initFeatures } from "./feature-flags";
import { KnownLanguage } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import { cleanupAndUploadOverlayBaseDatabaseToCache } from "./overlay-database-utils";
Expand Down Expand Up @@ -293,7 +293,7 @@ async function run(startedAt: Date) {

util.checkActionVersion(actionsUtil.getActionVersion(), gitHubVersion);

const features = new Features(
const features = initFeatures(
gitHubVersion,
repositoryNwo,
actionsUtil.getTemporaryDirectory(),
Expand Down
4 changes: 2 additions & 2 deletions src/autobuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CodeQL, getCodeQL } from "./codeql";
import * as configUtils from "./config-utils";
import { DocUrl } from "./doc-url";
import { EnvVar } from "./environment";
import { Feature, featureConfig, Features } from "./feature-flags";
import { Feature, featureConfig, initFeatures } from "./feature-flags";
import { KnownLanguage, Language } from "./languages";
import { Logger } from "./logging";
import { getRepositoryNwo } from "./repository";
Expand Down Expand Up @@ -117,7 +117,7 @@ export async function setupCppAutobuild(codeql: CodeQL, logger: Logger) {
const featureName = "C++ automatic installation of dependencies";
const gitHubVersion = await getGitHubVersion();
const repositoryNwo = getRepositoryNwo();
const features = new Features(
const features = initFeatures(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
Expand Down
4 changes: 2 additions & 2 deletions src/diff-informed-analysis-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
shouldPerformDiffInformedAnalysis,
exportedForTesting,
} from "./diff-informed-analysis-utils";
import { Feature, Features } from "./feature-flags";
import { Feature, initFeatures } from "./feature-flags";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
import {
Expand Down Expand Up @@ -63,7 +63,7 @@ const testShouldPerformDiffInformedAnalysis = test.macro({
delete process.env.CODEQL_ACTION_DIFF_INFORMED_QUERIES;
}

const features = new Features(
const features = initFeatures(
testCase.gitHubVersion,
parseRepositoryNwo("github/example"),
tmpDir,
Expand Down
4 changes: 2 additions & 2 deletions src/feature-flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import {
Feature,
featureConfig,
FeatureEnablement,
Features,
FEATURE_FLAGS_FILE_NAME,
FeatureConfig,
FeatureWithoutCLI,
initFeatures,
} from "./feature-flags";
import { getRunnerLogger } from "./logging";
import { parseRepositoryNwo } from "./repository";
Expand Down Expand Up @@ -565,7 +565,7 @@ function setUpFeatureFlagTests(
): FeatureEnablement {
setupActionsVars(tmpDir, tmpDir);

return new Features(gitHubVersion, testRepositoryNwo, tmpDir, logger);
return initFeatures(gitHubVersion, testRepositoryNwo, tmpDir, logger);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ export const FEATURE_FLAGS_FILE_NAME = "cached-feature-flags.json";
* Determines the enablement status of a number of features locally without
* consulting the GitHub API.
*/
export class OfflineFeatures implements FeatureEnablement {
class OfflineFeatures implements FeatureEnablement {
constructor(protected readonly logger: Logger) {}

async getDefaultCliVersion(
Expand Down Expand Up @@ -494,7 +494,7 @@ export class OfflineFeatures implements FeatureEnablement {
* If feature enablement is not able to be determined locally, a request to the
* GitHub API is made to determine the enablement status.
*/
export class Features extends OfflineFeatures {
class Features extends OfflineFeatures {
private gitHubFeatureFlags: GitHubFeatureFlags;

constructor(
Expand Down Expand Up @@ -798,3 +798,16 @@ function supportsFeatureFlags(githubVariant: util.GitHubVariant): boolean {
githubVariant === util.GitHubVariant.GHEC_DR
);
}

/**
* Initialises an instance of a `FeatureEnablement` implementation. The implementation used
* is determined by the environment we are running in.
*/
export function initFeatures(
Comment thread
mbg marked this conversation as resolved.
Resolved
gitHubVersion: util.GitHubVersion,
repositoryNwo: RepositoryNwo,
tempDir: string,
logger: Logger,
): FeatureEnablement {
return new Features(gitHubVersion, repositoryNwo, tempDir, logger);
}
4 changes: 2 additions & 2 deletions src/init-action-post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
getDependencyCacheUsage,
} from "./dependency-caching";
import { EnvVar } from "./environment";
import { Features } from "./feature-flags";
import { initFeatures } from "./feature-flags";
import * as gitUtils from "./git-utils";
import * as initActionPostHelper from "./init-action-post-helper";
import { getActionsLogger } from "./logging";
Expand Down Expand Up @@ -62,7 +62,7 @@ async function run(startedAt: Date) {
checkGitHubVersionInRange(gitHubVersion, logger);

const repositoryNwo = getRepositoryNwo();
const features = new Features(
const features = initFeatures(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
Expand Down
6 changes: 3 additions & 3 deletions src/init-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
makeTelemetryDiagnostic,
} from "./diagnostics";
import { EnvVar } from "./environment";
import { Feature, FeatureEnablement, Features } from "./feature-flags";
import { Feature, FeatureEnablement, initFeatures } from "./feature-flags";
import {
loadPropertiesFromApi,
RepositoryProperties,
Expand Down Expand Up @@ -210,7 +210,7 @@ async function run(startedAt: Date) {
let config: configUtils.Config | undefined;
let configFile: string | undefined;
let codeql: CodeQL;
let features: Features;
let features: FeatureEnablement;
let sourceRoot: string;
let toolsDownloadStatusReport: ToolsDownloadStatusReport | undefined;
let toolsFeatureFlagsValid: boolean | undefined;
Expand All @@ -237,7 +237,7 @@ async function run(startedAt: Date) {

const repositoryNwo = getRepositoryNwo();

features = new Features(
features = initFeatures(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
Expand Down
4 changes: 2 additions & 2 deletions src/setup-codeql-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { getGitHubVersion } from "./api-client";
import { CodeQL } from "./codeql";
import { EnvVar } from "./environment";
import { Features } from "./feature-flags";
import { initFeatures } from "./feature-flags";
import { initCodeQL } from "./init";
import { getActionsLogger, Logger } from "./logging";
import { getRepositoryNwo } from "./repository";
Expand Down Expand Up @@ -114,7 +114,7 @@ async function run(startedAt: Date): Promise<void> {

const repositoryNwo = getRepositoryNwo();

const features = new Features(
const features = initFeatures(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
Expand Down
6 changes: 3 additions & 3 deletions src/start-proxy-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { pki } from "node-forge";

import * as actionsUtil from "./actions-util";
import { getGitHubVersion } from "./api-client";
import { Feature, Features } from "./feature-flags";
import { Feature, FeatureEnablement, initFeatures } from "./feature-flags";
import { KnownLanguage } from "./languages";
import { getActionsLogger, Logger } from "./logging";
import { getRepositoryNwo } from "./repository";
Expand Down Expand Up @@ -99,7 +99,7 @@ async function run(startedAt: Date) {
// possible, and only use safe functions outside.

const logger = getActionsLogger();
let features: Features | undefined;
let features: FeatureEnablement | undefined;
let language: KnownLanguage | undefined;

try {
Expand All @@ -114,7 +114,7 @@ async function run(startedAt: Date) {
// Initialise FFs.
const repositoryNwo = getRepositoryNwo();
const gitHubVersion = await getGitHubVersion();
features = new Features(
features = initFeatures(
gitHubVersion,
repositoryNwo,
actionsUtil.getTemporaryDirectory(),
Expand Down
4 changes: 2 additions & 2 deletions src/upload-sarif-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as actionsUtil from "./actions-util";
import { getActionVersion, getTemporaryDirectory } from "./actions-util";
import * as analyses from "./analyses";
import { getGitHubVersion } from "./api-client";
import { Features } from "./feature-flags";
import { initFeatures } from "./feature-flags";
import { Logger, getActionsLogger } from "./logging";
import { getRepositoryNwo } from "./repository";
import {
Expand Down Expand Up @@ -70,7 +70,7 @@ async function run(startedAt: Date) {
actionsUtil.persistInputs();

const repositoryNwo = getRepositoryNwo();
const features = new Features(
const features = initFeatures(
gitHubVersion,
repositoryNwo,
getTemporaryDirectory(),
Expand Down