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-validator): throw an error when the config cannot be found #23815

Merged
merged 10 commits into from
Nov 15, 2023
31 changes: 26 additions & 5 deletions lib/config-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ type PackageJson = {
'renovate-config'?: Record<string, RenovateConfig>;
};

let isFoundConfigFile = false;
async function validateAndSetFlag(
liby marked this conversation as resolved.
Show resolved Hide resolved
file: string,
config: RenovateConfig,
strict: boolean,
isPreset = false
): Promise<void> {
isFoundConfigFile = true;
await validate(file, config, strict, isPreset);
}

liby marked this conversation as resolved.
Show resolved Hide resolved
(async () => {
const strictArgIndex = process.argv.indexOf('--strict');
const strict = strictArgIndex >= 0;
Expand All @@ -75,7 +86,7 @@ type PackageJson = {
const parsedContent = await getParsedContent(file);
try {
logger.info(`Validating ${file}`);
await validate(file, parsedContent, strict);
await validateAndSetFlag(file, parsedContent, strict);
} catch (err) {
logger.warn({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand All @@ -96,7 +107,7 @@ type PackageJson = {
const parsedContent = await getParsedContent(file);
try {
logger.info(`Validating ${file}`);
await validate(file, parsedContent, strict);
await validateAndSetFlag(file, parsedContent, strict);
} catch (err) {
logger.warn({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand All @@ -112,12 +123,16 @@ type PackageJson = {
) as PackageJson;
if (pkgJson.renovate) {
logger.info(`Validating package.json > renovate`);
await validate('package.json > renovate', pkgJson.renovate, strict);
await validateAndSetFlag(
'package.json > renovate',
pkgJson.renovate,
strict
);
}
if (pkgJson['renovate-config']) {
logger.info(`Validating package.json > renovate-config`);
for (const presetConfig of Object.values(pkgJson['renovate-config'])) {
await validate(
await validateAndSetFlag(
'package.json > renovate-config',
presetConfig,
strict,
Expand All @@ -134,7 +149,7 @@ type PackageJson = {
const file = process.env.RENOVATE_CONFIG_FILE ?? 'config.js';
logger.info(`Validating ${file}`);
try {
await validate(file, fileConfig, strict);
await validateAndSetFlag(file, fileConfig, strict);
liby marked this conversation as resolved.
Show resolved Hide resolved
} catch (err) {
logger.error({ file, err }, 'File is not valid Renovate config');
returnVal = 1;
Expand All @@ -144,6 +159,12 @@ type PackageJson = {
// ignore
}
}

if (!isFoundConfigFile) {
logger.error('No configuration files found.');
process.exit(1);
}

if (returnVal !== 0) {
process.exit(returnVal);
}
Expand Down