Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): delay global config preset resolution #9415

Merged
merged 1 commit into from Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/config/index.ts
Expand Up @@ -7,7 +7,6 @@ import * as defaultsParser from './defaults';
import * as definitions from './definitions';
import * as envParser from './env';
import * as fileParser from './file';
import { resolveConfigPresets } from './presets';
import type {
GlobalConfig,
RenovateConfig,
Expand Down Expand Up @@ -52,10 +51,10 @@ export async function parseConfigs(
logger.debug('Parsing configs');

// Get configs
const defaultConfig = await resolveConfigPresets(defaultsParser.getConfig());
const fileConfig = await resolveConfigPresets(fileParser.getConfig(env));
const cliConfig = await resolveConfigPresets(cliParser.getConfig(argv));
const envConfig = await resolveConfigPresets(envParser.getConfig(env));
const defaultConfig = defaultsParser.getConfig();
const fileConfig = fileParser.getConfig(env);
const cliConfig = cliParser.getConfig(argv);
const envConfig = envParser.getConfig(env);

let config: GlobalConfig = mergeChildConfig(fileConfig, envConfig);
config = mergeChildConfig(config, cliConfig);
Expand Down
1 change: 1 addition & 0 deletions lib/constants/error-messages.ts
Expand Up @@ -12,6 +12,7 @@ export const PLATFORM_RATE_LIMIT_EXCEEDED = 'rate-limit-exceeded';

// Config Error
export const CONFIG_VALIDATION = 'config-validation';
export const CONFIG_PRESETS_INVALID = 'config-presets-invalid';
export const CONFIG_SECRETS_EXPOSED = 'config-secrets-exposed';
export const CONFIG_SECRETS_INVALID = 'config-secrets-invalid';

Expand Down
12 changes: 12 additions & 0 deletions lib/workers/global/index.ts
Expand Up @@ -6,7 +6,9 @@ import upath from 'upath';
import * as pkg from '../../../package.json';
import * as configParser from '../../config';
import { GlobalConfig } from '../../config';
import { resolveConfigPresets } from '../../config/presets';
import { validateConfigSecrets } from '../../config/secrets';
import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages';
import { getProblems, logger, setMeta } from '../../logger';
import { setUtilConfig } from '../../util';
import * as hostRules from '../../util/host-rules';
Expand Down Expand Up @@ -69,6 +71,14 @@ function checkEnv(): void {
}
}

export async function validatePresets(config: GlobalConfig): Promise<void> {
try {
await resolveConfigPresets(config);
} catch (err) /* istanbul ignore next */ {
throw new Error(CONFIG_PRESETS_INVALID);
viceice marked this conversation as resolved.
Show resolved Hide resolved
}
}

export async function start(): Promise<number> {
let config: GlobalConfig;
try {
Expand All @@ -77,6 +87,8 @@ export async function start(): Promise<number> {
// initialize all submodules
config = await globalInitialize(config);

await validatePresets(config);

checkEnv();

// validate secrets. Will throw and abort if invalid
Expand Down