mirror of
https://github.com/github/codeql-action.git
synced 2026-05-26 16:34:25 +00:00
Call amendInputConfigFile() early
This commit extracts into amendInputConfigFile() the code that processes configInput, and moves the call from initConfig() into init-action.ts.
This commit is contained in:
@@ -589,16 +589,15 @@ test("Using config input and file together, config input should be used.", async
|
||||
// Only JS, python packs will be ignored
|
||||
const languagesInput = "javascript";
|
||||
|
||||
const config = await configUtils.initConfig(
|
||||
createTestInitConfigInputs({
|
||||
languagesInput,
|
||||
configFile: configFilePath,
|
||||
configInput,
|
||||
tempDir,
|
||||
workspacePath: tempDir,
|
||||
}),
|
||||
codeql,
|
||||
);
|
||||
const inputs = createTestInitConfigInputs({
|
||||
languagesInput,
|
||||
configFile: configFilePath,
|
||||
configInput,
|
||||
tempDir,
|
||||
workspacePath: tempDir,
|
||||
});
|
||||
configUtils.amendInputConfigFile(inputs, inputs.logger);
|
||||
const config = await configUtils.initConfig(inputs, codeql);
|
||||
|
||||
t.deepEqual(config.originalUserInput, yaml.load(configInput));
|
||||
});
|
||||
|
||||
+24
-12
@@ -569,6 +569,30 @@ async function downloadCacheWithTime(
|
||||
return { trapCaches, trapCacheDownloadTime };
|
||||
}
|
||||
|
||||
/**
|
||||
* Amends the input config file if configInput is provided.
|
||||
* If configInput is set, it takes precedence over configFile.
|
||||
*
|
||||
* This function should be called only once on any specific `InitConfigInputs`
|
||||
* object. Otherwise it could emit a false warning.
|
||||
*/
|
||||
export function amendInputConfigFile(
|
||||
inputs: InitConfigInputs,
|
||||
logger: Logger,
|
||||
): void {
|
||||
// if configInput is set, it takes precedence over configFile
|
||||
if (inputs.configInput) {
|
||||
if (inputs.configFile) {
|
||||
logger.warning(
|
||||
`Both a config file and config input were provided. Ignoring config file.`,
|
||||
);
|
||||
}
|
||||
inputs.configFile = userConfigFromActionPath(inputs.tempDir);
|
||||
fs.writeFileSync(inputs.configFile, inputs.configInput);
|
||||
logger.debug(`Using config from action input: ${inputs.configFile}`);
|
||||
}
|
||||
}
|
||||
|
||||
async function loadUserConfig(
|
||||
configFile: string,
|
||||
workspacePath: string,
|
||||
@@ -839,18 +863,6 @@ export async function initConfig(
|
||||
): Promise<Config> {
|
||||
const { logger, tempDir } = inputs;
|
||||
|
||||
// if configInput is set, it takes precedence over configFile
|
||||
if (inputs.configInput) {
|
||||
if (inputs.configFile) {
|
||||
logger.warning(
|
||||
`Both a config file and config input were provided. Ignoring config file.`,
|
||||
);
|
||||
}
|
||||
inputs.configFile = userConfigFromActionPath(tempDir);
|
||||
fs.writeFileSync(inputs.configFile, inputs.configInput);
|
||||
logger.debug(`Using config from action input: ${inputs.configFile}`);
|
||||
}
|
||||
|
||||
let userConfig: UserConfig = {};
|
||||
if (!inputs.configFile) {
|
||||
logger.debug("No configuration file was provided");
|
||||
|
||||
@@ -265,6 +265,7 @@ async function run() {
|
||||
repositoryProperties,
|
||||
logger,
|
||||
};
|
||||
configUtils.amendInputConfigFile(inputs, logger);
|
||||
|
||||
const codeQLDefaultVersionInfo = await features.getDefaultCliVersion(
|
||||
gitHubVersion.type,
|
||||
|
||||
Reference in New Issue
Block a user