Skip to content

Commit c079287

Browse files
committed
Call amendInputConfigFile() early
This commit extracts into amendInputConfigFile() the code that processes configInput, and moves the call from initConfig() into init-action.ts.
1 parent fcd4657 commit c079287

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

src/config-utils.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -589,16 +589,15 @@ test("Using config input and file together, config input should be used.", async
589589
// Only JS, python packs will be ignored
590590
const languagesInput = "javascript";
591591

592-
const config = await configUtils.initConfig(
593-
createTestInitConfigInputs({
594-
languagesInput,
595-
configFile: configFilePath,
596-
configInput,
597-
tempDir,
598-
workspacePath: tempDir,
599-
}),
600-
codeql,
601-
);
592+
const inputs = createTestInitConfigInputs({
593+
languagesInput,
594+
configFile: configFilePath,
595+
configInput,
596+
tempDir,
597+
workspacePath: tempDir,
598+
});
599+
configUtils.amendInputConfigFile(inputs, inputs.logger);
600+
const config = await configUtils.initConfig(inputs, codeql);
602601

603602
t.deepEqual(config.originalUserInput, yaml.load(configInput));
604603
});

src/config-utils.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,30 @@ async function downloadCacheWithTime(
569569
return { trapCaches, trapCacheDownloadTime };
570570
}
571571

572+
/**
573+
* Amends the input config file if configInput is provided.
574+
* If configInput is set, it takes precedence over configFile.
575+
*
576+
* This function should be called only once on any specific `InitConfigInputs`
577+
* object. Otherwise it could emit a false warning.
578+
*/
579+
export function amendInputConfigFile(
580+
inputs: InitConfigInputs,
581+
logger: Logger,
582+
): void {
583+
// if configInput is set, it takes precedence over configFile
584+
if (inputs.configInput) {
585+
if (inputs.configFile) {
586+
logger.warning(
587+
`Both a config file and config input were provided. Ignoring config file.`,
588+
);
589+
}
590+
inputs.configFile = userConfigFromActionPath(inputs.tempDir);
591+
fs.writeFileSync(inputs.configFile, inputs.configInput);
592+
logger.debug(`Using config from action input: ${inputs.configFile}`);
593+
}
594+
}
595+
572596
async function loadUserConfig(
573597
configFile: string,
574598
workspacePath: string,
@@ -839,18 +863,6 @@ export async function initConfig(
839863
): Promise<Config> {
840864
const { logger, tempDir } = inputs;
841865

842-
// if configInput is set, it takes precedence over configFile
843-
if (inputs.configInput) {
844-
if (inputs.configFile) {
845-
logger.warning(
846-
`Both a config file and config input were provided. Ignoring config file.`,
847-
);
848-
}
849-
inputs.configFile = userConfigFromActionPath(tempDir);
850-
fs.writeFileSync(inputs.configFile, inputs.configInput);
851-
logger.debug(`Using config from action input: ${inputs.configFile}`);
852-
}
853-
854866
let userConfig: UserConfig = {};
855867
if (!inputs.configFile) {
856868
logger.debug("No configuration file was provided");

src/init-action.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ async function run() {
265265
repositoryProperties,
266266
logger,
267267
};
268+
configUtils.amendInputConfigFile(inputs, logger);
268269

269270
const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
270271
gitHubVersion.type,

0 commit comments

Comments
 (0)