mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor(enabled-managers): implement custom.<customMgrName>
syntax (#24079)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
This commit is contained in:
parent
f1fa4c1e3a
commit
79556f4ecb
12 changed files with 88 additions and 31 deletions
|
@ -1170,6 +1170,16 @@ Example:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To enable custom managers you will need to add `custom.` prefix before their names
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"enabledManagers": ["custom.regex"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
For the full list of available managers, see the [Supported Managers](https://docs.renovatebot.com/modules/manager/#supported-managers) documentation.
|
For the full list of available managers, see the [Supported Managers](https://docs.renovatebot.com/modules/manager/#supported-managers) documentation.
|
||||||
|
|
||||||
## encrypted
|
## encrypted
|
||||||
|
|
|
@ -1,13 +1,29 @@
|
||||||
import { EnabledManagersMigration } from './enabled-managers-migration';
|
import { EnabledManagersMigration } from './enabled-managers-migration';
|
||||||
|
|
||||||
describe('config/migrations/custom/enabled-managers-migration', () => {
|
describe('config/migrations/custom/enabled-managers-migration', () => {
|
||||||
it('should replace yarn with npm', () => {
|
it('migrates', () => {
|
||||||
expect(EnabledManagersMigration).toMigrate(
|
expect(EnabledManagersMigration).toMigrate(
|
||||||
{
|
{
|
||||||
enabledManagers: ['test1', 'yarn', 'test2'],
|
enabledManagers: ['test1', 'yarn', 'test2', 'regex', 'custom.regex'],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabledManagers: ['test1', 'npm', 'test2'],
|
enabledManagers: [
|
||||||
|
'test1',
|
||||||
|
'npm',
|
||||||
|
'test2',
|
||||||
|
'custom.regex',
|
||||||
|
'custom.regex',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// coverage
|
||||||
|
expect(EnabledManagersMigration).not.toMigrate(
|
||||||
|
{
|
||||||
|
enabledManagers: undefined,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
enabledManagers: undefined,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,11 +5,20 @@ export class EnabledManagersMigration extends AbstractMigration {
|
||||||
override readonly propertyName = 'enabledManagers';
|
override readonly propertyName = 'enabledManagers';
|
||||||
|
|
||||||
override run(value: unknown): void {
|
override run(value: unknown): void {
|
||||||
if (is.array(value)) {
|
if (!is.array<string>(value, is.string)) {
|
||||||
const newValue = value.map((manager) =>
|
return;
|
||||||
manager === 'yarn' ? 'npm' : manager,
|
|
||||||
);
|
|
||||||
this.rewrite(newValue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newValue = value.map((manager) => {
|
||||||
|
switch (manager) {
|
||||||
|
case 'yarn':
|
||||||
|
return 'npm';
|
||||||
|
case 'regex':
|
||||||
|
return 'custom.regex';
|
||||||
|
default:
|
||||||
|
return manager;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.rewrite(newValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,7 +236,7 @@ describe('config/validation', () => {
|
||||||
[
|
[
|
||||||
'multiple enabled managers',
|
'multiple enabled managers',
|
||||||
{
|
{
|
||||||
enabledManagers: ['npm', 'gradle', 'maven', 'regex'],
|
enabledManagers: ['npm', 'gradle', 'maven', 'custom.regex'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
])('validates enabled managers for %s', async (_case, config) => {
|
])('validates enabled managers for %s', async (_case, config) => {
|
||||||
|
|
|
@ -71,7 +71,7 @@ function validatePlainObject(val: Record<string, unknown>): true | string {
|
||||||
|
|
||||||
function getUnsupportedEnabledManagers(enabledManagers: string[]): string[] {
|
function getUnsupportedEnabledManagers(enabledManagers: string[]): string[] {
|
||||||
return enabledManagers.filter(
|
return enabledManagers.filter(
|
||||||
(manager) => !allManagersList.includes(manager),
|
(manager) => !allManagersList.includes(manager.replace('custom.', '')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ describe('modules/manager/custom/index', () => {
|
||||||
it('works', () => {
|
it('works', () => {
|
||||||
expect(customManager.isCustomManager('npm')).toBe(false);
|
expect(customManager.isCustomManager('npm')).toBe(false);
|
||||||
expect(customManager.isCustomManager('regex')).toBe(true);
|
expect(customManager.isCustomManager('regex')).toBe(true);
|
||||||
|
expect(customManager.isCustomManager('custom.regex')).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -37,6 +37,16 @@ describe('modules/manager/index', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getEnabledManagersList()', () => {
|
||||||
|
it('works', () => {
|
||||||
|
expect(manager.getEnabledManagersList()).toEqual(manager.allManagersList);
|
||||||
|
expect(manager.getEnabledManagersList(['custom.regex', 'npm'])).toEqual([
|
||||||
|
'npm',
|
||||||
|
'regex',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('validates', () => {
|
it('validates', () => {
|
||||||
function validate(module: ManagerApi, moduleName: string): boolean {
|
function validate(module: ManagerApi, moduleName: string): boolean {
|
||||||
// no need to validate custom as it is a wrapper and not an actual manager
|
// no need to validate custom as it is a wrapper and not an actual manager
|
||||||
|
|
|
@ -103,3 +103,22 @@ export function getRangeStrategy(config: RangeConfig): RangeStrategy | null {
|
||||||
|
|
||||||
return config.rangeStrategy;
|
return config.rangeStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter a list of managers based on enabled managers.
|
||||||
|
*
|
||||||
|
* If enabledManagers is provided, this function returns a subset of allManagersList
|
||||||
|
* that matches the enabled manager names, including custom managers. If enabledManagers
|
||||||
|
* is not provided or is an empty array, it returns the full list of managers.
|
||||||
|
*/
|
||||||
|
export function getEnabledManagersList(enabledManagers?: string[]): string[] {
|
||||||
|
if (enabledManagers?.length) {
|
||||||
|
return allManagersList.filter(
|
||||||
|
(manager) =>
|
||||||
|
enabledManagers.includes(manager) ||
|
||||||
|
enabledManagers.includes(`custom.${manager}`),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allManagersList;
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ describe('workers/repository/extract/extract-fingerprint-config', () => {
|
||||||
notStable: 'http://some.link.2',
|
notStable: 'http://some.link.2',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
enabledManagers: ['npm', 'regex'],
|
enabledManagers: ['npm', 'custom.regex'],
|
||||||
customManagers: [
|
customManagers: [
|
||||||
{
|
{
|
||||||
customType: 'regex',
|
customType: 'regex',
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { getManagerConfig, mergeChildConfig } from '../../../config';
|
import { getManagerConfig, mergeChildConfig } from '../../../config';
|
||||||
import type { RenovateConfig } from '../../../config/types';
|
import type { RenovateConfig } from '../../../config/types';
|
||||||
import { allManagersList } from '../../../modules/manager';
|
import { getEnabledManagersList } from '../../../modules/manager';
|
||||||
import { isCustomManager } from '../../../modules/manager/custom';
|
import { isCustomManager } from '../../../modules/manager/custom';
|
||||||
import type { RegexManagerTemplates } from '../../../modules/manager/custom/regex/types';
|
import type { RegexManagerTemplates } from '../../../modules/manager/custom/regex/types';
|
||||||
import { validMatchFields } from '../../../modules/manager/custom/regex/utils';
|
import { validMatchFields } from '../../../modules/manager/custom/regex/utils';
|
||||||
|
@ -55,13 +55,7 @@ export function generateFingerprintConfig(
|
||||||
config: RenovateConfig,
|
config: RenovateConfig,
|
||||||
): FingerprintExtractConfig {
|
): FingerprintExtractConfig {
|
||||||
const managerExtractConfigs: WorkerExtractConfig[] = [];
|
const managerExtractConfigs: WorkerExtractConfig[] = [];
|
||||||
let managerList: Set<string>;
|
const managerList = new Set(getEnabledManagersList(config.enabledManagers));
|
||||||
const { enabledManagers } = config;
|
|
||||||
if (enabledManagers?.length) {
|
|
||||||
managerList = new Set(enabledManagers);
|
|
||||||
} else {
|
|
||||||
managerList = new Set(allManagersList);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const manager of managerList) {
|
for (const manager of managerList) {
|
||||||
const managerConfig = getManagerConfig(config, manager);
|
const managerConfig = getManagerConfig(config, manager);
|
||||||
|
|
|
@ -42,10 +42,13 @@ describe('workers/repository/extract/index', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('warns if no packages found for a enabled manager', async () => {
|
it('warns if no packages found for a enabled manager', async () => {
|
||||||
config.enabledManagers = ['npm'];
|
config.enabledManagers = ['npm', 'custom.regex'];
|
||||||
managerFiles.getManagerPackageFiles.mockResolvedValue([]);
|
managerFiles.getManagerPackageFiles.mockResolvedValue([]);
|
||||||
expect((await extractAllDependencies(config)).packageFiles).toEqual({});
|
expect((await extractAllDependencies(config)).packageFiles).toEqual({});
|
||||||
expect(logger.debug).toHaveBeenCalled();
|
expect(logger.debug).toHaveBeenCalledWith(
|
||||||
|
{ manager: 'custom.regex' },
|
||||||
|
`Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('warns if packageFiles is null', async () => {
|
it('warns if packageFiles is null', async () => {
|
||||||
|
|
|
@ -2,7 +2,7 @@ import is from '@sindresorhus/is';
|
||||||
import { getManagerConfig, mergeChildConfig } from '../../../config';
|
import { getManagerConfig, mergeChildConfig } from '../../../config';
|
||||||
import type { ManagerConfig, RenovateConfig } from '../../../config/types';
|
import type { ManagerConfig, RenovateConfig } from '../../../config/types';
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../../logger';
|
||||||
import { allManagersList, hashMap } from '../../../modules/manager';
|
import { getEnabledManagersList, hashMap } from '../../../modules/manager';
|
||||||
import { isCustomManager } from '../../../modules/manager/custom';
|
import { isCustomManager } from '../../../modules/manager/custom';
|
||||||
import { scm } from '../../../modules/platform/scm';
|
import { scm } from '../../../modules/platform/scm';
|
||||||
import type { ExtractResult, WorkerExtractConfig } from '../../types';
|
import type { ExtractResult, WorkerExtractConfig } from '../../types';
|
||||||
|
@ -13,14 +13,7 @@ import { processSupersedesManagers } from './supersedes';
|
||||||
export async function extractAllDependencies(
|
export async function extractAllDependencies(
|
||||||
config: RenovateConfig,
|
config: RenovateConfig,
|
||||||
): Promise<ExtractResult> {
|
): Promise<ExtractResult> {
|
||||||
let managerList = allManagersList;
|
const managerList = getEnabledManagersList(config.enabledManagers);
|
||||||
const { enabledManagers } = config;
|
|
||||||
if (is.nonEmptyArray(enabledManagers)) {
|
|
||||||
logger.debug('Applying enabledManagers filtering');
|
|
||||||
managerList = managerList.filter((manager) =>
|
|
||||||
enabledManagers.includes(manager),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const extractList: WorkerExtractConfig[] = [];
|
const extractList: WorkerExtractConfig[] = [];
|
||||||
const fileList = await scm.getFileList();
|
const fileList = await scm.getFileList();
|
||||||
|
|
||||||
|
@ -91,7 +84,9 @@ export async function extractAllDependencies(
|
||||||
// If not, log a warning to indicate possible misconfiguration.
|
// If not, log a warning to indicate possible misconfiguration.
|
||||||
if (is.nonEmptyArray(config.enabledManagers)) {
|
if (is.nonEmptyArray(config.enabledManagers)) {
|
||||||
for (const enabledManager of config.enabledManagers) {
|
for (const enabledManager of config.enabledManagers) {
|
||||||
if (!(enabledManager in extractResult.packageFiles)) {
|
if (
|
||||||
|
!(enabledManager.replace('custom.', '') in extractResult.packageFiles)
|
||||||
|
) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
{ manager: enabledManager },
|
{ manager: enabledManager },
|
||||||
`Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`,
|
`Manager explicitly enabled in "enabledManagers" config, but found no results. Possible config error?`,
|
||||||
|
|
Loading…
Reference in a new issue