Skip to content

Commit f86aa52

Browse files
committed
Use ActionState for getRemoteConfig
1 parent e446d55 commit f86aa52

3 files changed

Lines changed: 32 additions & 31 deletions

File tree

lib/entry-points.js

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

src/config-utils.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { performance } from "perf_hooks";
55
import * as core from "@actions/core";
66
import * as yaml from "js-yaml";
77

8+
import { ActionState } from "./action-common";
89
import {
910
getActionVersion,
1011
getOptionalInput,
@@ -78,6 +79,7 @@ import {
7879
Success,
7980
Failure,
8081
isHostedRunner,
82+
getEnv,
8183
} from "./util";
8284

8385
/**
@@ -600,12 +602,11 @@ async function downloadCacheWithTime(
600602
}
601603

602604
async function loadUserConfig(
603-
logger: Logger,
605+
actionState: ActionState,
604606
configFile: string,
605607
workspacePath: string,
606608
apiDetails: api.GitHubApiCombinedDetails,
607609
tempDir: string,
608-
validateConfig: boolean,
609610
): Promise<UserConfig> {
610611
if (isLocal(configFile)) {
611612
if (configFile !== userConfigFromActionPath(tempDir)) {
@@ -618,14 +619,12 @@ async function loadUserConfig(
618619
);
619620
}
620621
}
621-
return getLocalConfig(logger, configFile, validateConfig);
622-
} else {
623-
return await getRemoteConfig(
624-
logger,
625-
configFile,
626-
apiDetails,
627-
validateConfig,
622+
const validateConfig = await actionState.features.getValue(
623+
Feature.ValidateDbConfig,
628624
);
625+
return getLocalConfig(actionState.logger, configFile, validateConfig);
626+
} else {
627+
return await getRemoteConfig(actionState, configFile, apiDetails);
629628
}
630629
}
631630

@@ -1161,14 +1160,13 @@ export async function initConfig(
11611160
logger.debug("No configuration file was provided");
11621161
} else {
11631162
logger.debug(`Using configuration file: ${inputs.configFile}`);
1164-
const validateConfig = await features.getValue(Feature.ValidateDbConfig);
1163+
const actionState: ActionState = { logger, features, env: getEnv() };
11651164
userConfig = await loadUserConfig(
1166-
logger,
1165+
actionState,
11671166
inputs.configFile,
11681167
inputs.workspacePath,
11691168
inputs.apiDetails,
11701169
tempDir,
1171-
validateConfig,
11721170
);
11731171
}
11741172

src/config/file.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import { ActionState } from "../action-common";
12
import { ActionsEnv } from "../actions-util";
23
import * as api from "../api-client";
34
import * as errorMessages from "../error-messages";
5+
import { Feature } from "../feature-flags";
46
import {
57
RepositoryProperties,
68
RepositoryPropertyName,
@@ -42,18 +44,16 @@ export function getConfigFileInput(
4244
/**
4345
* Attempts to fetch a `UserConfig` from a remote `address`.
4446
*
45-
* @param logger The logger to use.
47+
* @param actionState The current Action state.
4648
* @param configFile The remote address of the configuration file.
4749
* @param apiDetails Information about how to connect to the API.
48-
* @param validateConfig Whether to validate the configuration.
4950
*
5051
* @returns The `UserConfig`, if it could be fetched and parsed successfully.
5152
*/
5253
export async function getRemoteConfig(
53-
logger: Logger,
54+
actionState: ActionState,
5455
configFile: string,
5556
apiDetails: api.GitHubApiCombinedDetails,
56-
validateConfig: boolean,
5757
): Promise<UserConfig> {
5858
const address = parseRemoteFileAddress(getEnv(), configFile);
5959

@@ -79,8 +79,11 @@ export async function getRemoteConfig(
7979
);
8080
}
8181

82+
const validateConfig = await actionState.features.getValue(
83+
Feature.ValidateDbConfig,
84+
);
8285
return parseUserConfig(
83-
logger,
86+
actionState.logger,
8487
configFile,
8588
Buffer.from(fileContents, "base64").toString("binary"),
8689
validateConfig,

0 commit comments

Comments
 (0)