Skip to content

Commit b2cc23e

Browse files
committed
Log input choice
1 parent 8203691 commit b2cc23e

4 files changed

Lines changed: 57 additions & 12 deletions

File tree

lib/entry-points.js

Lines changed: 15 additions & 3 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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ import test from "ava";
22
import sinon from "sinon";
33

44
import { RepositoryPropertyName } from "../feature-flags/properties";
5-
import { getTestActionsEnv, setupTests } from "../testing-utils";
5+
import {
6+
getTestActionsEnv,
7+
RecordingLogger,
8+
setupTests,
9+
} from "../testing-utils";
610

711
import { getConfigFileInput } from "./file";
812

913
setupTests(test);
1014

1115
test("getConfigFileInput returns undefined by default", async (t) => {
16+
const logger = new RecordingLogger();
1217
const actionsEnv = getTestActionsEnv();
13-
const result = getConfigFileInput(actionsEnv, {});
18+
const result = getConfigFileInput(logger, actionsEnv, {});
1419
t.is(result, undefined);
1520
});
1621

@@ -19,6 +24,7 @@ const repositoryProperties = {
1924
};
2025

2126
test("getConfigFileInput returns input value", async (t) => {
27+
const logger = new RecordingLogger();
2228
const actionsEnv = getTestActionsEnv();
2329
const testInput = "/some/path";
2430
sinon
@@ -28,14 +34,25 @@ test("getConfigFileInput returns input value", async (t) => {
2834

2935
// Even though both an input and repository property are configured,
3036
// we prefer the direct input to the Action.
31-
const result = getConfigFileInput(actionsEnv, repositoryProperties);
37+
const result = getConfigFileInput(logger, actionsEnv, repositoryProperties);
3238
t.is(result, testInput);
39+
40+
// Check for the expected log message.
41+
t.true(logger.hasMessage("Using configuration file input from workflow"));
3342
});
3443

3544
test("getConfigFileInput returns repository property value", async (t) => {
45+
const logger = new RecordingLogger();
3646
const actionsEnv = getTestActionsEnv();
3747

3848
// Since there is no direct input, we should use the repository property.
39-
const result = getConfigFileInput(actionsEnv, repositoryProperties);
49+
const result = getConfigFileInput(logger, actionsEnv, repositoryProperties);
4050
t.is(result, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
51+
52+
// Check for the expected log message.
53+
t.true(
54+
logger.hasMessage(
55+
"Using configuration file input from repository property",
56+
),
57+
);
4158
});

src/config/file.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,32 @@ import {
33
RepositoryProperties,
44
RepositoryPropertyName,
55
} from "../feature-flags/properties";
6+
import { Logger } from "../logging";
67

78
/**
89
* Gets the value that is configured for the configuration file, if any.
910
*/
1011
export function getConfigFileInput(
12+
logger: Logger,
1113
actions: ActionsEnv,
1214
repositoryProperties: Partial<RepositoryProperties>,
1315
): string | undefined {
14-
return (
15-
actions.getOptionalInput("config-file") ||
16-
repositoryProperties[RepositoryPropertyName.CONFIG_FILE]
17-
);
16+
const input = actions.getOptionalInput("config-file");
17+
18+
if (input !== undefined) {
19+
logger.info(`Using configuration file input from workflow: ${input}`);
20+
return input;
21+
}
22+
23+
const propertyValue =
24+
repositoryProperties[RepositoryPropertyName.CONFIG_FILE];
25+
26+
if (propertyValue !== undefined) {
27+
logger.info(
28+
`Using configuration file input from repository property: ${propertyValue}`,
29+
);
30+
return propertyValue;
31+
}
32+
33+
return undefined;
1834
}

src/init-action.ts

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

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

266-
configFile = getConfigFileInput(actionsEnv, repositoryProperties);
266+
configFile = getConfigFileInput(logger, actionsEnv, repositoryProperties);
267267

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

0 commit comments

Comments
 (0)