mirror of
https://github.com/github/codeql-action.git
synced 2026-10-21 02:01:27 +00:00
Parse the config input in init without the parseConfigInput wrapper
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2347,40 +2347,6 @@ test("applyIncrementalAnalysisSettings: adds exclusions for diff-informed-only r
|
||||
]);
|
||||
});
|
||||
|
||||
test("parseConfigInput - returns undefined when the input isn't set", async (t) => {
|
||||
await callee(configUtils.parseConfigInput)
|
||||
.withArgs(undefined)
|
||||
.passes(t.is, undefined);
|
||||
});
|
||||
|
||||
test("parseConfigInput - parses the input as YAML", async (t) => {
|
||||
await callee(configUtils.parseConfigInput)
|
||||
.withArgs(simpleConfigFileContents)
|
||||
.passes(t.deepEqual, {
|
||||
name: "my config",
|
||||
queries: [{ uses: "./foo_file" }],
|
||||
});
|
||||
});
|
||||
|
||||
test("parseConfigInput - throws a ConfigurationError naming the input if it isn't valid YAML", async (t) => {
|
||||
await callee(configUtils.parseConfigInput)
|
||||
.withArgs("queries: [")
|
||||
.throws(t, {
|
||||
instanceOf: ConfigurationError,
|
||||
message: /^Cannot parse "`config` input"/,
|
||||
});
|
||||
});
|
||||
|
||||
test("parseConfigInput - throws a ConfigurationError naming the input if validation fails", async (t) => {
|
||||
await callee(configUtils.parseConfigInput)
|
||||
.withFeatures([Feature.ValidateDbConfig])
|
||||
.withArgs("queries: 1")
|
||||
.throws(t, {
|
||||
instanceOf: ConfigurationError,
|
||||
message: /^The configuration file "`config` input" is invalid/,
|
||||
});
|
||||
});
|
||||
|
||||
test("determineUserConfig - empty config when neither input is specified", async (t) => {
|
||||
await withTmpDir(async (tmpDir) => {
|
||||
const target = callee(configUtils.determineUserConfig)
|
||||
|
||||
@@ -1044,29 +1044,6 @@ export async function applyIncrementalAnalysisSettings(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the `config` input, which contains a configuration in YAML.
|
||||
*
|
||||
* @returns The configuration, or `undefined` if the input isn't set. Unless configuration validation
|
||||
* is enabled, the configuration might not be a mapping.
|
||||
* @throws A `ConfigurationError` if the input isn't valid YAML or, when configuration validation is
|
||||
* enabled, isn't a valid configuration.
|
||||
*/
|
||||
export async function parseConfigInput(
|
||||
{ logger, features }: ActionState<["Logger", "FeatureFlags"]>,
|
||||
configInput: string | undefined,
|
||||
): Promise<UserConfig | undefined> {
|
||||
if (configInput === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return parseUserConfig(
|
||||
logger,
|
||||
"`config` input",
|
||||
configInput,
|
||||
await features.getValue(Feature.ValidateDbConfig),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines where to load the `UserConfig` for the CLI from and loads it.
|
||||
*
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
shouldRestoreCache,
|
||||
} from "./caching-utils";
|
||||
import { CodeQL } from "./codeql";
|
||||
import { parseUserConfig } from "./config/db-config";
|
||||
import { getConfigFileInput } from "./config/file";
|
||||
import { ComputedInput, getToolsInput } from "./config/inputs";
|
||||
import * as configUtils from "./config-utils";
|
||||
@@ -306,10 +307,16 @@ async function run(
|
||||
const rawLanguages = configUtils.getRawLanguagesNoAutodetect(
|
||||
getOptionalInput("languages"),
|
||||
);
|
||||
const configInput = await configUtils.parseConfigInput(
|
||||
actionStateWithFeatures,
|
||||
getOptionalInput("config"),
|
||||
);
|
||||
const rawConfigInput = getOptionalInput("config");
|
||||
const configInput =
|
||||
rawConfigInput === undefined
|
||||
? undefined
|
||||
: parseUserConfig(
|
||||
logger,
|
||||
"`config` input",
|
||||
rawConfigInput,
|
||||
await features.getValue(Feature.ValidateDbConfig),
|
||||
);
|
||||
const queriesInput = getOptionalInput("queries");
|
||||
const otherLanguagePacksReason = getOtherLanguagePacksReason({
|
||||
configFile,
|
||||
|
||||
Reference in New Issue
Block a user