Skip to content

Commit 1f34ec1

Browse files
authored
Merge pull request #3983 from github/mbg/repo-props/ff-for-config-file-prop
Add FF for configuration file repository property
2 parents 628fc3f + d5f0145 commit 1f34ec1

5 files changed

Lines changed: 99 additions & 17 deletions

File tree

lib/entry-points.js

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

src/config/file.test.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ setupTests(test);
1515
test("getConfigFileInput returns undefined by default", async (t) => {
1616
const logger = new RecordingLogger();
1717
const actionsEnv = getTestActionsEnv();
18-
const result = getConfigFileInput(logger, actionsEnv, {});
18+
const result = getConfigFileInput(logger, actionsEnv, {}, true);
1919
t.is(result, undefined);
2020
});
2121

@@ -34,7 +34,12 @@ test("getConfigFileInput returns input value", async (t) => {
3434

3535
// Even though both an input and repository property are configured,
3636
// we prefer the direct input to the Action.
37-
const result = getConfigFileInput(logger, actionsEnv, repositoryProperties);
37+
const result = getConfigFileInput(
38+
logger,
39+
actionsEnv,
40+
repositoryProperties,
41+
true,
42+
);
3843
t.is(result, testInput);
3944

4045
// Check for the expected log message.
@@ -46,7 +51,12 @@ test("getConfigFileInput returns repository property value", async (t) => {
4651
const actionsEnv = getTestActionsEnv();
4752

4853
// Since there is no direct input, we should use the repository property.
49-
const result = getConfigFileInput(logger, actionsEnv, repositoryProperties);
54+
const result = getConfigFileInput(
55+
logger,
56+
actionsEnv,
57+
repositoryProperties,
58+
true,
59+
);
5060
t.is(result, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
5161

5262
// Check for the expected log message.
@@ -62,8 +72,38 @@ test("getConfigFileInput ignores empty repository property value", async (t) =>
6272
const actionsEnv = getTestActionsEnv();
6373

6474
// Since the repository property value is an empty/whitespace string, we should ignore it.
65-
const result = getConfigFileInput(logger, actionsEnv, {
66-
[RepositoryPropertyName.CONFIG_FILE]: " ",
67-
});
75+
const result = getConfigFileInput(
76+
logger,
77+
actionsEnv,
78+
{
79+
[RepositoryPropertyName.CONFIG_FILE]: " ",
80+
},
81+
true,
82+
);
83+
t.is(result, undefined);
84+
});
85+
86+
test("getConfigFileInput ignores repository property value when FF is off", async (t) => {
87+
const logger = new RecordingLogger();
88+
const actionsEnv = getTestActionsEnv();
89+
90+
// Since the FF is off, we should ignore the repository property value.
91+
const result = getConfigFileInput(
92+
logger,
93+
actionsEnv,
94+
repositoryProperties,
95+
false,
96+
);
6897
t.is(result, undefined);
98+
99+
t.false(
100+
logger.hasMessage(
101+
"Using configuration file input from repository property",
102+
),
103+
);
104+
t.true(
105+
logger.hasMessage(
106+
"Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.",
107+
),
108+
);
69109
});

src/config/file.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function getConfigFileInput(
1212
logger: Logger,
1313
actions: ActionsEnv,
1414
repositoryProperties: Partial<RepositoryProperties>,
15+
useRepositoryProperty: boolean,
1516
): string | undefined {
1617
const input = actions.getOptionalInput("config-file");
1718

@@ -24,10 +25,17 @@ export function getConfigFileInput(
2425
repositoryProperties[RepositoryPropertyName.CONFIG_FILE];
2526

2627
if (propertyValue !== undefined && propertyValue.trim().length > 0) {
27-
logger.info(
28-
`Using configuration file input from repository property: ${propertyValue}`,
29-
);
30-
return propertyValue;
28+
// Only use the repository property value if the FF is enabled.
29+
if (useRepositoryProperty) {
30+
logger.info(
31+
`Using configuration file input from repository property: ${propertyValue}`,
32+
);
33+
return propertyValue;
34+
} else {
35+
logger.info(
36+
"Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.",
37+
);
38+
}
3139
}
3240

3341
return undefined;

src/feature-flags.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export enum Feature {
7474
AllowMultipleAnalysisKinds = "allow_multiple_analysis_kinds",
7575
AllowToolcacheInput = "allow_toolcache_input",
7676
CleanupTrapCaches = "cleanup_trap_caches",
77+
/** Whether to allow the `config-file` input to be specified via a repository property. */
78+
ConfigFileRepositoryProperty = "config_file_repository_property",
7779
CppDependencyInstallation = "cpp_dependency_installation_enabled",
7880
CsharpCacheBuildModeNone = "csharp_cache_bmn",
7981
CsharpNewCacheKey = "csharp_new_cache_key",
@@ -184,6 +186,11 @@ export const featureConfig = {
184186
envVar: "CODEQL_ACTION_CLEANUP_TRAP_CACHES",
185187
minimumVersion: undefined,
186188
},
189+
[Feature.ConfigFileRepositoryProperty]: {
190+
defaultValue: false,
191+
envVar: "CODEQL_ACTION_CONFIG_FILE_REPOSITORY_PROPERTY",
192+
minimumVersion: undefined,
193+
},
187194
[Feature.CppDependencyInstallation]: {
188195
defaultValue: false,
189196
envVar: "CODEQL_EXTRACTOR_CPP_AUTOINSTALL_DEPENDENCIES",

src/init-action.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,15 @@ async function run(startedAt: Date) {
263263

264264
core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
265265

266-
configFile = getConfigFileInput(logger, actionsEnv, repositoryProperties);
266+
const useConfigFileProperty = await features.getValue(
267+
Feature.ConfigFileRepositoryProperty,
268+
);
269+
configFile = getConfigFileInput(
270+
logger,
271+
actionsEnv,
272+
repositoryProperties,
273+
useConfigFileProperty,
274+
);
267275

268276
// path.resolve() respects the intended semantics of source-root. If
269277
// source-root is relative, it is relative to the GITHUB_WORKSPACE. If

0 commit comments

Comments
 (0)