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): migrate inline with the same sort #12091

Merged
merged 39 commits into from Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c719277
refactor: migrate inline with the same sort
pret-a-porter Oct 9, 2021
cd03397
refactor: migrations runner => migrations service
pret-a-porter Oct 10, 2021
ba14eee
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 10, 2021
3d41d5f
refactor: move Migration to types
pret-a-porter Oct 10, 2021
e35f7ec
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 11, 2021
d583c60
refactor: improve migrations
pret-a-porter Oct 11, 2021
00f4472
refactor: migrations unit tests
pret-a-porter Oct 11, 2021
4ad77bd
refactor: improve migrations
pret-a-porter Oct 11, 2021
383ce90
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 12, 2021
63701dc
refactor: migrations
pret-a-porter Oct 13, 2021
659292a
refactor: migrations
pret-a-porter Oct 13, 2021
1af7fa4
refactor: add test to check order of properties
pret-a-porter Oct 13, 2021
8f919a0
refactor: migration of go mod tidy
pret-a-porter Oct 13, 2021
a3d43f5
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 14, 2021
6f9a0ca
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 17, 2021
f481137
refactor: unnecessary Partial modificator
pret-a-porter Oct 17, 2021
6248e79
refactor: fix by comments
pret-a-porter Oct 17, 2021
324acdc
refactor: move Migration to types
pret-a-porter Oct 17, 2021
863d8b7
refactor: fix test
pret-a-porter Oct 17, 2021
9bbc04d
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Oct 31, 2021
b7c5451
refactor: fix unit tests
pret-a-porter Oct 31, 2021
1594d51
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 2, 2021
3b808da
refactor: fix unit tests
pret-a-porter Nov 2, 2021
2fdd36c
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 3, 2021
7d11245
Merge branch 'main' into refactor/migrate_same_sort
viceice Nov 4, 2021
957b76d
Merge branch 'main' into refactor/migrate_same_sort
rarkins Nov 5, 2021
04f22f8
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 6, 2021
0b7d304
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 7, 2021
98c652d
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 7, 2021
adb3261
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 8, 2021
817a6ad
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 8, 2021
fdc1dee
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 9, 2021
6b372d7
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 10, 2021
136273b
Merge branch 'main' into refactor/migrate_same_sort
rarkins Nov 12, 2021
793ea4a
Merge branch 'main' into refactor/migrate_same_sort
rarkins Nov 12, 2021
2f09d02
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 13, 2021
a868150
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 14, 2021
ba9ffeb
Merge branch 'main' into refactor/migrate_same_sort
pret-a-porter Nov 14, 2021
b9cca49
Merge branch 'main' into refactor/migrate_same_sort
rarkins Nov 17, 2021
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
61 changes: 4 additions & 57 deletions lib/config/migration.ts
Expand Up @@ -5,7 +5,7 @@ import { logger } from '../logger';
import { clone } from '../util/clone';
rarkins marked this conversation as resolved.
Show resolved Hide resolved
import { regEx } from '../util/regex';
import { getGlobalConfig } from './global';
import { applyMigrations } from './migrations';
import { MigrationsService } from './migrations';
import { getOptions } from './options';
import { removedPresets } from './presets/common';
import type {
Expand All @@ -20,23 +20,6 @@ const options = getOptions();

let optionTypes: Record<string, RenovateOptions['type']>;

const removedOptions = [
'maintainYarnLock',
'yarnCacheFolder',
'yarnMaintenanceBranchName',
'yarnMaintenanceCommitMessage',
'yarnMaintenancePrTitle',
'yarnMaintenancePrBody',
'groupBranchName',
'groupBranchName',
'groupCommitMessage',
'groupPrTitle',
'groupPrBody',
'statusCheckVerify',
'lazyGrouping',
'supportPolicy',
];

// Returns a migrated config
export function migrateConfig(
config: RenovateConfig,
Expand All @@ -50,7 +33,8 @@ export function migrateConfig(
optionTypes[option.name] = option.type;
});
}
const migratedConfig = clone(config) as MigratedRenovateConfig;
const newConfig = MigrationsService.run(config);
const migratedConfig = clone(newConfig) as MigratedRenovateConfig;
viceice marked this conversation as resolved.
Show resolved Hide resolved
const depTypes = [
'dependencies',
'devDependencies',
Expand All @@ -59,11 +43,8 @@ export function migrateConfig(
'peerDependencies',
];
const { migratePresets } = getGlobalConfig();
applyMigrations(config, migratedConfig);
for (const [key, val] of Object.entries(config)) {
if (removedOptions.includes(key)) {
delete migratedConfig[key];
} else if (key === 'pathRules') {
if (key === 'pathRules') {
if (is.array(val)) {
migratedConfig.packageRules = is.array(migratedConfig.packageRules)
? migratedConfig.packageRules
Expand All @@ -85,13 +66,6 @@ export function migrateConfig(
migratedConfig[newKey] = true;
}
delete migratedConfig[key];
} else if (key === 'gomodTidy') {
if (val) {
migratedConfig.postUpdateOptions =
migratedConfig.postUpdateOptions || [];
migratedConfig.postUpdateOptions.push('gomodTidy');
}
delete migratedConfig.gomodTidy;
} else if (key === 'semanticCommits') {
if (val === true) {
migratedConfig.semanticCommits = 'enabled';
Expand Down Expand Up @@ -211,16 +185,6 @@ export function migrateConfig(
if (val === false) {
migratedConfig.rebaseWhen = 'never';
}
} else if (key === 'exposeEnv') {
migratedConfig.exposeAllEnv = val;
delete migratedConfig.exposeEnv;
} else if (key === 'trustLevel') {
delete migratedConfig.trustLevel;
if (val === 'high') {
migratedConfig.allowCustomCrateRegistries ??= true;
migratedConfig.allowScripts ??= true;
migratedConfig.exposeAllEnv ??= true;
}
} else if (key === 'ignoreNpmrcFile') {
delete migratedConfig.ignoreNpmrcFile;
if (!is.string(migratedConfig.npmrc)) {
Expand Down Expand Up @@ -305,9 +269,6 @@ export function migrateConfig(
}
}
delete migratedConfig.unpublishSafe;
} else if (key === 'versionScheme') {
migratedConfig.versioning = val;
delete migratedConfig.versionScheme;
} else if (
key === 'automergeType' &&
is.string(val) &&
Expand All @@ -322,25 +283,16 @@ export function migrateConfig(
migratedConfig.major = migratedConfig.major || {};
migratedConfig.major.automerge = !!val;
delete migratedConfig[key];
} else if (key === 'multipleMajorPrs') {
delete migratedConfig.multipleMajorPrs;
migratedConfig.separateMultipleMajor = val;
} else if (key === 'renovateFork' && is.boolean(val)) {
delete migratedConfig.renovateFork;
migratedConfig.includeForks = val;
} else if (key === 'separateMajorReleases') {
delete migratedConfig.separateMultipleMajor;
migratedConfig.separateMajorMinor = val;
} else if (key === 'separatePatchReleases') {
delete migratedConfig.separatePatchReleases;
migratedConfig.separateMinorPatch = val;
} else if (key === 'automergePatch') {
migratedConfig.patch = migratedConfig.patch || {};
migratedConfig.patch.automerge = !!val;
delete migratedConfig[key];
} else if (key === 'ignoreNodeModules') {
delete migratedConfig.ignoreNodeModules;
migratedConfig.ignorePaths = val ? ['node_modules/'] : [];
} else if (
key === 'automerge' &&
is.string(val) &&
Expand Down Expand Up @@ -374,9 +326,6 @@ export function migrateConfig(
migratedConfig.packages
);
delete migratedConfig.packages;
} else if (key === 'excludedPackageNames') {
migratedConfig.excludePackageNames = val;
delete migratedConfig.excludedPackageNames;
} else if (key === 'packageName') {
migratedConfig.packageNames = [val];
delete migratedConfig.packageName;
Expand Down Expand Up @@ -541,8 +490,6 @@ export function migrateConfig(
migratedConfig.suppressNotifications || [];
migratedConfig.suppressNotifications.push('deprecationWarningIssues');
}
} else if (key === 'binarySource' && val === 'auto') {
migratedConfig.binarySource = 'global';
} else if (key === 'composerIgnorePlatformReqs') {
if (val === true) {
migratedConfig.composerIgnorePlatformReqs = [];
Expand Down
26 changes: 26 additions & 0 deletions lib/config/migrations/base/abstract-migration.ts
@@ -0,0 +1,26 @@
import type { RenovateConfig } from '../../types';
import type { Migration } from '../types';

export abstract class AbstractMigration implements Migration {
readonly propertyName: string;

protected readonly originalConfig: RenovateConfig;

protected readonly migratedConfig: RenovateConfig;

constructor(
propertyName: string,
originalConfig: RenovateConfig,
migratedConfig: RenovateConfig
) {
this.propertyName = propertyName;
this.originalConfig = originalConfig;
this.migratedConfig = migratedConfig;
}

abstract run(): void;

protected delete(property: string): void {
viceice marked this conversation as resolved.
Show resolved Hide resolved
delete this.migratedConfig[property];
}
}
7 changes: 7 additions & 0 deletions lib/config/migrations/base/remove-property-migration.ts
@@ -0,0 +1,7 @@
import { AbstractMigration } from './abstract-migration';

export class RemovePropertyMigration extends AbstractMigration {
override run(): void {
this.delete(this.propertyName);
}
}
23 changes: 23 additions & 0 deletions lib/config/migrations/base/rename-property-migration.ts
@@ -0,0 +1,23 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from './abstract-migration';

export class RenamePropertyMigration extends AbstractMigration {
protected readonly newPropertyName: string;

constructor(
deprecatedPropertyName: string,
newPropertyName: string,
originalConfig: RenovateConfig,
migratedConfig: RenovateConfig
) {
super(deprecatedPropertyName, originalConfig, migratedConfig);
this.newPropertyName = newPropertyName;
}

override run(): void {
this.delete(this.propertyName);

this.migratedConfig[this.newPropertyName] =
this.originalConfig[this.propertyName];
}
}
11 changes: 11 additions & 0 deletions lib/config/migrations/custom/binary-source-migration.spec.ts
@@ -0,0 +1,11 @@
import { MigrationsService } from '../migrations-service';

describe('config/migrations/custom/binary-source-migration', () => {
it('should migrate "auto" to "global"', () => {
const migratedConfig = MigrationsService.run({
binarySource: 'auto',
});

expect(migratedConfig.binarySource).toBe('global');
});
});
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/binary-source-migration.ts
@@ -0,0 +1,14 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export class BinarySourceMigration extends AbstractMigration {
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) {
super('binarySource', originalConfig, migratedConfig);
}

override run(): void {
if (this.originalConfig.binarySource === 'auto') {
this.migratedConfig.binarySource = 'global';
}
}
}
31 changes: 31 additions & 0 deletions lib/config/migrations/custom/go-mod-tidy-migration.spec.ts
@@ -0,0 +1,31 @@
import { MigrationsService } from '../migrations-service';

describe('config/migrations/custom/go-mod-tidy-migration', () => {
it('should add postUpdateOptions option when true', () => {
const migratedConfig = MigrationsService.run({
gomodTidy: true,
postUpdateOptions: ['test'],
});

expect(migratedConfig).not.toHaveProperty('gomodTidy');
expect(migratedConfig.postUpdateOptions).toEqual(['test', 'gomodTidy']);
});

it('should handle case when postUpdateOptions is not defined ', () => {
const migratedConfig = MigrationsService.run({
gomodTidy: true,
});

expect(migratedConfig).not.toHaveProperty('gomodTidy');
expect(migratedConfig.postUpdateOptions).toEqual(['gomodTidy']);
});

it('should only remove when false', () => {
const migratedConfig = MigrationsService.run({
gomodTidy: false,
});

expect(migratedConfig).not.toHaveProperty('gomodTidy');
expect(migratedConfig).not.toHaveProperty('postUpdateOptions');
});
});
19 changes: 19 additions & 0 deletions lib/config/migrations/custom/go-mod-tidy-migration.ts
@@ -0,0 +1,19 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export class GoModTidyMigration extends AbstractMigration {
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) {
super('gomodTidy', originalConfig, migratedConfig);
}

override run(): void {
const { gomodTidy, postUpdateOptions } = this.originalConfig;

this.delete(this.propertyName);

if (gomodTidy) {
this.migratedConfig.postUpdateOptions ??= postUpdateOptions ?? [];
this.migratedConfig.postUpdateOptions.push('gomodTidy');
}
}
}
11 changes: 11 additions & 0 deletions lib/config/migrations/custom/ignore-node-modules-migration.spec.ts
@@ -0,0 +1,11 @@
import { MigrationsService } from '../migrations-service';

describe('config/migrations/custom/ignore-node-modules-migration', () => {
it('should migrate to ignorePaths', () => {
const migratedConfig = MigrationsService.run({
ignoreNodeModules: true,
});

expect(migratedConfig.ignorePaths).toEqual(['node_modules/']);
});
});
16 changes: 16 additions & 0 deletions lib/config/migrations/custom/ignore-node-modules-migration.ts
@@ -0,0 +1,16 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export class IgnoreNodeModulesMigration extends AbstractMigration {
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) {
super('ignoreNodeModules', originalConfig, migratedConfig);
}

override run(): void {
this.delete(this.propertyName);

this.migratedConfig.ignorePaths = this.originalConfig.ignoreNodeModules
? ['node_modules/']
: [];
}
}
@@ -0,0 +1,12 @@
import { MigrationsService } from '../migrations-service';

describe('config/migrations/custom/required-status-checks-migration', () => {
it('should migrate requiredStatusChecks=null to ignoreTests=true', () => {
const migratedConfig = MigrationsService.run({
requiredStatusChecks: null,
});

expect(migratedConfig).not.toHaveProperty('requiredStatusChecks');
expect(migratedConfig.ignoreTests).toBeTrue();
});
});
16 changes: 16 additions & 0 deletions lib/config/migrations/custom/required-status-checks-migration.ts
@@ -0,0 +1,16 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export class RequiredStatusChecksMigration extends AbstractMigration {
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) {
super('requiredStatusChecks', originalConfig, migratedConfig);
}

override run(): void {
this.delete(this.propertyName);

if (this.originalConfig.requiredStatusChecks === null) {
this.migratedConfig.ignoreTests = true;
}
}
}
26 changes: 26 additions & 0 deletions lib/config/migrations/custom/trust-level-migration.spec.ts
@@ -0,0 +1,26 @@
import { MigrationsService } from '../migrations-service';

describe('config/migrations/custom/trust-level-migration', () => {
it('should handle hight level', () => {
const migratedConfig = MigrationsService.run({
trustLevel: 'high',
});

expect(migratedConfig.allowCustomCrateRegistries).toBeTrue();
expect(migratedConfig.allowScripts).toBeTrue();
expect(migratedConfig.exposeAllEnv).toBeTrue();
});

it('should not rewrite provided properties', () => {
const migratedConfig = MigrationsService.run({
allowCustomCrateRegistries: false,
allowScripts: false,
exposeAllEnv: false,
trustLevel: 'high',
});

expect(migratedConfig.allowCustomCrateRegistries).toBeFalse();
expect(migratedConfig.allowScripts).toBeFalse();
expect(migratedConfig.exposeAllEnv).toBeFalse();
});
});
21 changes: 21 additions & 0 deletions lib/config/migrations/custom/trust-level-migration.ts
@@ -0,0 +1,21 @@
import type { RenovateConfig } from '../../types';
import { AbstractMigration } from '../base/abstract-migration';

export class TrustLevelMigration extends AbstractMigration {
constructor(originalConfig: RenovateConfig, migratedConfig: RenovateConfig) {
super('trustLevel', originalConfig, migratedConfig);
}

override run(): void {
this.delete(this.propertyName);

if (this.originalConfig.trustLevel === 'high') {
this.migratedConfig.allowCustomCrateRegistries =
this.originalConfig.allowCustomCrateRegistries ?? true;
viceice marked this conversation as resolved.
Show resolved Hide resolved
this.migratedConfig.allowScripts =
this.originalConfig.allowScripts ?? true;
this.migratedConfig.exposeAllEnv =
this.originalConfig.exposeAllEnv ?? true;
}
}
}