Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
142 changes: 72 additions & 70 deletions lib/entry-points.js

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

24 changes: 10 additions & 14 deletions src/config/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from "../testing-utils";

import { getConfigFileInput, getRemoteConfig } from "./file";
import { InputSource } from "./inputs";

setupTests(test);

Expand Down Expand Up @@ -41,36 +42,31 @@ test("getConfigFileInput returns input value", async (t) => {
.returns(testInput);
})
.withArgs(repositoryProperties)
.logs(t, "Using configuration file input from workflow")
.passes(t.is, testInput);
.logs(t, "Using config-file input from workflow")
.passes(t.deepEqual, { value: testInput, source: InputSource.Workflow });
});

test("getConfigFileInput returns repository property value", async (t) => {
// Since there is no direct input, we should use the repository property.
await callee(getConfigFileInput)
.withFeatures([Feature.ConfigFileRepositoryProperty])
.withArgs(repositoryProperties)
.logs(t, "Using configuration file input from repository property")
.passes(t.is, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
});

test("getConfigFileInput ignores empty repository property value", async (t) => {
// Since the repository property value is an empty/whitespace string, we should ignore it.
await callee(getConfigFileInput)
.withFeatures([Feature.ConfigFileRepositoryProperty])
.withArgs({ [RepositoryPropertyName.CONFIG_FILE]: " " })
.passes(t.is, undefined);
.logs(t, "Using config-file input from repository property")
.passes(t.deepEqual, {
value: repositoryProperties[RepositoryPropertyName.CONFIG_FILE],
source: InputSource.RepositoryProperty,
});
});

test("getConfigFileInput ignores repository property value when FF is off", async (t) => {
// Since the FF is off, we should ignore the repository property value.
await callee(getConfigFileInput)
.withFeatures([])
.withArgs(repositoryProperties)
.notLogs(t, "Using configuration file input from repository property")
.notLogs(t, "Using config-file input from repository property")
.logs(
t,
"Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.",
"Ignoring config-file input from repository property, because the corresponding feature flag is disabled.",
)
.passes(t.is, undefined);
});
Expand Down
46 changes: 12 additions & 34 deletions src/config/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { ConfigurationError } from "../util";

import { parseUserConfig, UserConfig } from "./db-config";
import { getComputedInput, InputName, type ComputedInput } from "./inputs";
import { parseRemoteFileAddress } from "./remote-file";

/**
Expand All @@ -28,42 +29,19 @@ export const REMOTE_PATH_PREFIX = "remote=";
* Gets the value that is configured for the configuration file, if any.
*/
export async function getConfigFileInput(
{
logger,
actions,
features,
}: ActionState<["Logger", "Actions", "FeatureFlags"]>,
action: ActionState<["Logger", "Actions", "FeatureFlags"]>,
repositoryProperties: Partial<RepositoryProperties>,
): Promise<string | undefined> {
const input = actions.getOptionalInput("config-file");

if (input !== undefined) {
logger.info(`Using configuration file input from workflow: ${input}`);
return input;
}

const propertyValue =
repositoryProperties[RepositoryPropertyName.CONFIG_FILE];

if (propertyValue !== undefined && propertyValue.trim().length > 0) {
// Only use the repository property value if the FF is enabled.
const useRepositoryProperty = await features.getValue(
Feature.ConfigFileRepositoryProperty,
);

if (useRepositoryProperty) {
logger.info(
`Using configuration file input from repository property: ${propertyValue}`,
);
return propertyValue;
} else {
logger.info(
"Ignoring configuration file input from repository property, because the corresponding feature flag is disabled.",
);
}
}
): Promise<ComputedInput | undefined> {
// Only use the repository property value if the FF is enabled.
const useRepositoryProperty = await action.features.getValue(
Feature.ConfigFileRepositoryProperty,
);

return undefined;
return getComputedInput(action, repositoryProperties, InputName.ConfigFile, {
repositoryPropertyFeatureEnabled: useRepositoryProperty,
allowForcedRepositoryPropertyValue: false,
repositoryPropertyName: RepositoryPropertyName.CONFIG_FILE,
});
}

/**
Expand Down
Loading
Loading