Skip to content

Commit 3ed7f23

Browse files
feat(config/options): allow all managers as parents of managerFilePatterns (renovatebot#36471)
1 parent 72a55a3 commit 3ed7f23

File tree

7 files changed

+46
-42
lines changed

7 files changed

+46
-42
lines changed

lib/config/__snapshots__/validation.spec.ts.snap

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,12 @@ exports[`config/validation > validateConfig(config) > errors if manager objects
158158
exports[`config/validation > validateConfig(config) > errors if managerFilePatterns has wrong parent 1`] = `
159159
[
160160
{
161-
"message": ""managerFilePatterns" may not be defined at the top level of a config and must instead be within a manager block",
162-
"topic": "Config error",
161+
"message": "managerFilePatterns should only be configured within one of "ansible or ansible-galaxy or argocd or asdf or azure-pipelines or batect or batect-wrapper or bazel or bazel-module or bazelisk or bicep or bitbucket-pipelines or bitrise or buildkite or buildpacks or bun or bun-version or bundler or cake or cargo or cdnurl or circleci or cloudbuild or cocoapods or composer or conan or copier or cpanfile or crossplane or deps-edn or devbox or devcontainer or docker-compose or dockerfile or droneci or fleet or flux or fvm or git-submodules or github-actions or gitlabci or gitlabci-include or glasskube or gleam or gomod or gradle or gradle-wrapper or haskell-cabal or helm-requirements or helm-values or helmfile or helmsman or helmv3 or hermit or homebrew or html or jenkins or jsonnet-bundler or kotlin-script or kubernetes or kustomize or leiningen or maven or maven-wrapper or meteor or mint or mise or mix or nix or nodenv or npm or nuget or nvm or ocb or osgi or pep621 or pep723 or pip-compile or pip_requirements or pip_setup or pipenv or pixi or poetry or pre-commit or pub or puppet or pyenv or renovate-config-presets or ruby-version or runtime-version or sbt or scalafmt or setup-cfg or sveltos or swift or tekton or terraform or terraform-version or terragrunt or terragrunt-version or tflint-plugin or travis or velaci or vendir or woodpecker or customManagers" objects. Was found in .",
162+
"topic": "managerFilePatterns",
163163
},
164-
]
165-
`;
166-
167-
exports[`config/validation > validateConfig(config) > errors if managerFilePatterns has wrong parent 2`] = `
168-
[
169164
{
170-
"message": ""managerFilePatterns" must be configured in a manager block and not here: npm.minor",
171-
"topic": "Config warning",
165+
"message": "managerFilePatterns should only be configured within one of "ansible or ansible-galaxy or argocd or asdf or azure-pipelines or batect or batect-wrapper or bazel or bazel-module or bazelisk or bicep or bitbucket-pipelines or bitrise or buildkite or buildpacks or bun or bun-version or bundler or cake or cargo or cdnurl or circleci or cloudbuild or cocoapods or composer or conan or copier or cpanfile or crossplane or deps-edn or devbox or devcontainer or docker-compose or dockerfile or droneci or fleet or flux or fvm or git-submodules or github-actions or gitlabci or gitlabci-include or glasskube or gleam or gomod or gradle or gradle-wrapper or haskell-cabal or helm-requirements or helm-values or helmfile or helmsman or helmv3 or hermit or homebrew or html or jenkins or jsonnet-bundler or kotlin-script or kubernetes or kustomize or leiningen or maven or maven-wrapper or meteor or mint or mise or mix or nix or nodenv or npm or nuget or nvm or ocb or osgi or pep621 or pep723 or pip-compile or pip_requirements or pip_setup or pipenv or pixi or poetry or pre-commit or pub or puppet or pyenv or renovate-config-presets or ruby-version or runtime-version or sbt or scalafmt or setup-cfg or sveltos or swift or tekton or terraform or terraform-version or terragrunt or terragrunt-version or tflint-plugin or travis or velaci or vendir or woodpecker or customManagers" objects. Was found in minor",
166+
"topic": "npm.minor.managerFilePatterns",
172167
},
173168
]
174169
`;

lib/config/options/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { AllManagersListLiteral } from '../../manager-list.generated';
12
import { getManagers } from '../../modules/manager';
23
import { getCustomManagers } from '../../modules/manager/custom';
34
import { getPlatformList } from '../../modules/platform';
@@ -2446,6 +2447,7 @@ const options: RenovateOptions[] = [
24462447
mergeable: true,
24472448
cli: false,
24482449
env: false,
2450+
parents: [...AllManagersListLiteral, 'customManagers'],
24492451
},
24502452
{
24512453
name: 'postUpdateOptions',

lib/config/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { PlatformId } from '../constants';
22
import type { LogLevelRemap } from '../logger/types';
3+
import type { ManagerName } from '../manager-list.generated';
34
import type { CustomManager } from '../modules/manager/custom/types';
45
import type { RepoSortMethod, SortMethod } from '../modules/platform/types';
56
import type { HostRule, SkipReason } from '../types';
@@ -410,7 +411,8 @@ export type AllowedParents =
410411
| 'logLevelRemap'
411412
| 'packageRules'
412413
| 'postUpgradeTasks'
413-
| 'vulnerabilityAlerts';
414+
| 'vulnerabilityAlerts'
415+
| ManagerName;
414416
export interface RenovateOptionBase {
415417
/**
416418
* If true, the option can only be configured by people with access to the Renovate instance.

lib/config/validation.spec.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import { getManagerList } from '../modules/manager';
12
import { configFileNames } from './app-strings';
23
import { GlobalConfig } from './global';
34
import type { RenovateConfig } from './types';
45
import * as configValidation from './validation';
56
import { partial } from '~test/util';
67

8+
const managerList = getManagerList().sort();
9+
710
describe('config/validation', () => {
811
describe('validateConfig(config)', () => {
912
it('returns deprecation warnings', async () => {
@@ -1096,9 +1099,9 @@ describe('config/validation', () => {
10961099
'repo',
10971100
config,
10981101
);
1099-
expect(errors).toHaveLength(1);
1100-
expect(warnings).toHaveLength(1);
1101-
expect(errors).toMatchSnapshot();
1102+
1103+
expect(errors).toHaveLength(0);
1104+
expect(warnings).toHaveLength(2);
11021105
expect(warnings).toMatchSnapshot();
11031106
});
11041107

@@ -1756,16 +1759,16 @@ describe('config/validation', () => {
17561759
'global',
17571760
config,
17581761
);
1762+
expect.assertions(1);
17591763
expect(warnings).toEqual([
1760-
{
1761-
message:
1762-
'"managerFilePatterns" may not be defined at the top level of a config and must instead be within a manager block',
1763-
topic: 'Config error',
1764-
},
17651764
{
17661765
topic: 'Configuration Error',
17671766
message: `The "binarySource" option is a global option reserved only for Renovate's global configuration and cannot be configured within a repository's config file.`,
17681767
},
1768+
{
1769+
topic: 'managerFilePatterns',
1770+
message: `managerFilePatterns should only be configured within one of "${managerList.join(' or ')} or customManagers" objects. Was found in .`,
1771+
},
17691772
]);
17701773
});
17711774

@@ -1786,9 +1789,8 @@ describe('config/validation', () => {
17861789
);
17871790
expect(warnings).toEqual([
17881791
{
1789-
message:
1790-
'"managerFilePatterns" may not be defined at the top level of a config and must instead be within a manager block',
1791-
topic: 'Config error',
1792+
topic: 'managerFilePatterns',
1793+
message: `managerFilePatterns should only be configured within one of "${managerList.join(' or ')} or customManagers" objects. Was found in .`,
17921794
},
17931795
]);
17941796
});

lib/config/validation.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ const ignoredNodes = [
7676
const tzRe = regEx(/^:timezone\((.+)\)$/);
7777
const rulesRe = regEx(/p.*Rules\[\d+\]$/);
7878

79-
function isManagerPath(parentPath: string): boolean {
80-
return (
81-
regEx(/^customManagers\[[0-9]+]$/).test(parentPath) ||
82-
managerList.includes(parentPath)
83-
);
84-
}
85-
8679
function isIgnored(key: string): boolean {
8780
return ignoredNodes.includes(key);
8881
}
@@ -221,19 +214,6 @@ export async function validateConfig(
221214
});
222215
}
223216
}
224-
if (key === 'managerFilePatterns') {
225-
if (parentPath === undefined) {
226-
errors.push({
227-
topic: 'Config error',
228-
message: `"managerFilePatterns" may not be defined at the top level of a config and must instead be within a manager block`,
229-
});
230-
} else if (!isManagerPath(parentPath)) {
231-
warnings.push({
232-
topic: 'Config warning',
233-
message: `"managerFilePatterns" must be configured in a manager block and not here: ${parentPath}`,
234-
});
235-
}
236-
}
237217
if (
238218
!isIgnored(key) && // We need to ignore some reserved keys
239219
!(is as any).function(val) // Ignore all functions

test/docs/documentation.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ describe('docs/documentation', () => {
4242
function getConfigHeaders(file: string): string[] {
4343
const content = fs.readFileSync(`docs/usage/${file}`, 'utf8');
4444
const matches = content.match(/\n## (.*?)\n/g) ?? [];
45-
return matches.map((match) => match.substring(4, match.length - 1));
45+
return matches
46+
.map((match) => match.substring(4, match.length - 1))
47+
.filter((header) => header !== 'managerFilePatterns');
4648
}
4749

4850
function getRequiredConfigOptions(): string[] {
@@ -80,6 +82,7 @@ describe('docs/documentation', () => {
8082
.filter((option) => !option.globalOnly)
8183
.filter((option) => option.parents)
8284
.map((option) => option.name)
85+
.filter((header) => header !== 'managerFilePatterns')
8386
.sort();
8487
}
8588

tools/generate-imports.mjs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,25 @@ async function generateData() {
141141
);
142142
}
143143

144+
async function generateManagerList() {
145+
// get managers list
146+
const managers = (
147+
await fs.readdir('lib/modules/manager', { withFileTypes: true })
148+
)
149+
.filter((file) => file.isDirectory())
150+
.map((file) => file.name)
151+
.filter((mgr) => mgr !== 'custom')
152+
.sort()
153+
.map((fname) => `"${fname}"`);
154+
155+
const content = `
156+
export const AllManagersListLiteral = [${managers.join(',')}] as const;
157+
export type ManagerName = typeof AllManagersListLiteral[number];
158+
`;
159+
160+
await updateFile(`lib/manager-list.generated.ts`, content);
161+
}
162+
144163
async function generateHash() {
145164
console.log('generating hashes');
146165
try {
@@ -191,6 +210,7 @@ await (async () => {
191210
try {
192211
// data-files
193212
await generateData();
213+
await generateManagerList();
194214
await generateHash();
195215
await Promise.all(
196216
(await glob('lib/**/*.generated.ts'))

0 commit comments

Comments
 (0)