Skip to content

Commit 8203691

Browse files
committed
Accept repository property as fallback
1 parent ae7c3ea commit 8203691

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

lib/entry-points.js

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

4+
import { RepositoryPropertyName } from "../feature-flags/properties";
45
import { getTestActionsEnv, setupTests } from "../testing-utils";
56

67
import { getConfigFileInput } from "./file";
@@ -9,10 +10,14 @@ setupTests(test);
910

1011
test("getConfigFileInput returns undefined by default", async (t) => {
1112
const actionsEnv = getTestActionsEnv();
12-
const result = getConfigFileInput(actionsEnv);
13+
const result = getConfigFileInput(actionsEnv, {});
1314
t.is(result, undefined);
1415
});
1516

17+
const repositoryProperties = {
18+
[RepositoryPropertyName.CONFIG_FILE]: "/path/from/property",
19+
};
20+
1621
test("getConfigFileInput returns input value", async (t) => {
1722
const actionsEnv = getTestActionsEnv();
1823
const testInput = "/some/path";
@@ -21,6 +26,16 @@ test("getConfigFileInput returns input value", async (t) => {
2126
.withArgs("config-file")
2227
.returns(testInput);
2328

24-
const result = getConfigFileInput(actionsEnv);
29+
// Even though both an input and repository property are configured,
30+
// we prefer the direct input to the Action.
31+
const result = getConfigFileInput(actionsEnv, repositoryProperties);
2532
t.is(result, testInput);
2633
});
34+
35+
test("getConfigFileInput returns repository property value", async (t) => {
36+
const actionsEnv = getTestActionsEnv();
37+
38+
// Since there is no direct input, we should use the repository property.
39+
const result = getConfigFileInput(actionsEnv, repositoryProperties);
40+
t.is(result, repositoryProperties[RepositoryPropertyName.CONFIG_FILE]);
41+
});

src/config/file.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { ActionsEnv } from "../actions-util";
2+
import {
3+
RepositoryProperties,
4+
RepositoryPropertyName,
5+
} from "../feature-flags/properties";
26

37
/**
48
* Gets the value that is configured for the configuration file, if any.
59
*/
6-
export function getConfigFileInput(actions: ActionsEnv): string | undefined {
7-
return actions.getOptionalInput("config-file");
10+
export function getConfigFileInput(
11+
actions: ActionsEnv,
12+
repositoryProperties: Partial<RepositoryProperties>,
13+
): string | undefined {
14+
return (
15+
actions.getOptionalInput("config-file") ||
16+
repositoryProperties[RepositoryPropertyName.CONFIG_FILE]
17+
);
818
}

src/init-action.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ async function run(startedAt: Date) {
254254
repositoryNwo,
255255
logger,
256256
);
257+
const repositoryProperties = repositoryPropertiesResult.orElse({});
257258

258259
// Create a unique identifier for this run.
259260
const jobRunUuid = uuidV4();
@@ -262,7 +263,7 @@ async function run(startedAt: Date) {
262263

263264
core.exportVariable(EnvVar.INIT_ACTION_HAS_RUN, "true");
264265

265-
configFile = getConfigFileInput(actionsEnv);
266+
configFile = getConfigFileInput(actionsEnv, repositoryProperties);
266267

267268
// path.resolve() respects the intended semantics of source-root. If
268269
// source-root is relative, it is relative to the GITHUB_WORKSPACE. If
@@ -353,7 +354,6 @@ async function run(startedAt: Date) {
353354

354355
analysisKinds = await getAnalysisKinds(logger, features);
355356
const debugMode = getOptionalInput("debug") === "true" || core.isDebug();
356-
const repositoryProperties = repositoryPropertiesResult.orElse({});
357357
const fileCoverageResult = await getFileCoverageInformationEnabled(
358358
debugMode,
359359
codeql,

0 commit comments

Comments
 (0)