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): read filenames from CLI arguments #16475

Merged
merged 7 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/usage/getting-started/installing-onboarding.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ If you want to make config edits directly, follow these steps:
1. Validate your config by running `renovate-config-validator`
1. If the improved config passes the validation, merge the branch into your mainline branch

The validator program checks files based on multiple inputs:

- Filenames as CLI arguments
- `RENOVATE_CONFIG_FILE` environment variable
- All [default locations](../configuration-options.md) if the files exist

At the moment, all locations are validated without any precedence or deduplication.

You can configure a [pre-commit](https://pre-commit.com) hook to validate your configuration automatically.
Please check out the [`renovatebot/pre-commit-hooks` repository](https://github.com/renovatebot/pre-commit-hooks) for more information.

Expand Down
20 changes: 20 additions & 0 deletions lib/config-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@ type PackageJson = {
};

(async () => {
for (const file of process.argv.slice(2)) {
viceice marked this conversation as resolved.
Show resolved Hide resolved
try {
if (!(await pathExists(file))) {
returnVal = 1;
logger.error(`${file} does not exist`);
break;
}
const parsedContent = await getParsedContent(file);
try {
logger.info(`Validating ${file}`);
await validate(file, parsedContent);
} catch (err) {
logger.warn({ err }, `${file} is not valid Renovate config`);
returnVal = 1;
}
} catch (err) {
logger.warn({ err }, `${file} could not be parsed`);
returnVal = 1;
}
}
for (const file of configFileNames.filter(
viceice marked this conversation as resolved.
Show resolved Hide resolved
(name) => name !== 'package.json'
)) {
Expand Down