Skip to content

Commit

Permalink
feat(package-rules): set skipStage (#30264)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Jul 21, 2024
1 parent e2a7586 commit b6b85eb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 9 deletions.
2 changes: 2 additions & 0 deletions lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { LogLevelRemap } from '../logger/types';
import type { CustomManager } from '../modules/manager/custom/types';
import type { RepoSortMethod, SortMethod } from '../modules/platform/types';
import type { HostRule, SkipReason } from '../types';
import type { StageName } from '../types/skip-reason';
import type { GitNoVerifyOption } from '../util/git/types';
import type { MergeConfidence } from '../util/merge-confidence/types';

Expand Down Expand Up @@ -555,6 +556,7 @@ export interface PackageRuleInputConfig extends Record<string, unknown> {
currentVersionTimestamp?: string;
enabled?: boolean;
skipReason?: SkipReason;
skipStage?: StageName;
}

export interface ConfigMigration {
Expand Down
10 changes: 10 additions & 0 deletions lib/types/skip-reason.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,13 @@ export type SkipReason =
| 'recursive-placeholder'
| 'github-token-required'
| 'inherited-dependency';

export type StageName =
| 'current-timestamp'
| 'datasource-merge'
| 'lock-file-maintenance-merge'
| 'lock-file-maintenance-merge-2'
| 'pre-lookup'
| 'source-url'
| 'update-type'
| 'update-type-merge';
21 changes: 20 additions & 1 deletion lib/util/package-rules/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,28 @@ describe('util/package-rules/index', () => {
},
],
};
const res = applyPackageRules(dep);
const res = applyPackageRules(dep, 'datasource-merge');
expect(res.enabled).toBeFalse();
expect(res.skipReason).toBe('package-rules');
expect(res.skipStage).toBe('datasource-merge');
});

it('unsets skipReason=package-rules if enabled=true', () => {
const dep: any = {
depName: 'foo',
packageRules: [
{
enabled: false,
},
{
enabled: true,
},
],
};
const res = applyPackageRules(dep, 'datasource-merge');
expect(res.enabled).toBeTrue();
expect(res.skipReason).toBeUndefined();
expect(res.skipStage).toBeUndefined();
});

it('skips skipReason=package-rules if enabled=true', () => {
Expand Down
9 changes: 9 additions & 0 deletions lib/util/package-rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import slugify from 'slugify';
import { mergeChildConfig } from '../../config';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { logger } from '../../logger';
import type { StageName } from '../../types/skip-reason';
import matchers from './matchers';
import { matcherOR } from './utils';

Expand Down Expand Up @@ -62,6 +63,7 @@ function matchesRule(

export function applyPackageRules<T extends PackageRuleInputConfig>(
inputConfig: T,
stageName?: StageName,
): T {
let config = { ...inputConfig };
const packageRules = config.packageRules ?? [];
Expand All @@ -82,6 +84,13 @@ export function applyPackageRules<T extends PackageRuleInputConfig>(
}
if (toApply.enabled === false && config.enabled !== false) {
config.skipReason = 'package-rules';
if (stageName) {
config.skipStage = stageName;
}
}
if (toApply.enabled === true && config.enabled === false) {
delete config.skipReason;
delete config.skipStage;
}
config = mergeChildConfig(config, toApply);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ async function fetchDepUpdates(
const datasourceDefaultConfig = await getDefaultConfig(depConfig.datasource!);
depConfig = mergeChildConfig(depConfig, datasourceDefaultConfig);
depConfig.versioning ??= getDefaultVersioning(depConfig.datasource);
depConfig = applyPackageRules(depConfig);
depConfig = applyPackageRules(depConfig, 'pre-lookup');
depConfig.packageName ??= depConfig.depName;
if (depConfig.ignoreDeps!.includes(depName!)) {
// TODO: fix types (#22198)
Expand Down
2 changes: 1 addition & 1 deletion lib/workers/repository/process/lookup/filter-checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function filterInternalChecks(
releaseConfig[releaseConfig.updateType]!,
);
// Apply packageRules in case any apply to updateType
releaseConfig = applyPackageRules(releaseConfig);
releaseConfig = applyPackageRules(releaseConfig, 'update-type');
// Now check for a minimumReleaseAge config
const {
minimumConfidence,
Expand Down
10 changes: 8 additions & 2 deletions lib/workers/repository/process/lookup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ export async function lookupUpdates(
}
}
// Reapply package rules in case we missed something from sourceUrl
config = applyPackageRules({ ...config, sourceUrl: res.sourceUrl });
config = applyPackageRules(
{ ...config, sourceUrl: res.sourceUrl },
'source-url',
);
if (config.followTag) {
const taggedVersion = dependency.tags?.[config.followTag];
if (!taggedVersion) {
Expand Down Expand Up @@ -313,7 +316,10 @@ export async function lookupUpdates(
)
) {
// Reapply package rules to check matches for matchCurrentAge
config = applyPackageRules({ ...config, currentVersionTimestamp });
config = applyPackageRules(
{ ...config, currentVersionTimestamp },
'current-timestamp',
);
}
}

Expand Down
14 changes: 10 additions & 4 deletions lib/workers/repository/updates/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export async function flattenUpdates(
depConfig.datasource,
);
updateConfig = mergeChildConfig(updateConfig, datasourceConfig);
updateConfig = applyPackageRules(updateConfig);
updateConfig = applyPackageRules(updateConfig, 'datasource-merge');
// apply major/minor/patch/pin/digest
updateConfig = mergeChildConfig(
updateConfig,
Expand All @@ -123,7 +123,7 @@ export async function flattenUpdates(
delete updateConfig[updateType];
}
// Apply again in case any were added by the updateType config
updateConfig = applyPackageRules(updateConfig);
updateConfig = applyPackageRules(updateConfig, 'update-type-merge');
updateConfig = applyUpdateConfig(updateConfig);
updateConfig.baseDeps = packageFile.deps;
update.branchName = updateConfig.branchName;
Expand All @@ -143,13 +143,19 @@ export async function flattenUpdates(
);
lockFileConfig.updateType = 'lockFileMaintenance';
lockFileConfig.isLockFileMaintenance = true;
lockFileConfig = applyPackageRules(lockFileConfig);
lockFileConfig = applyPackageRules(
lockFileConfig,
'lock-file-maintenance-merge',
);
// Apply lockFileMaintenance and packageRules again
lockFileConfig = mergeChildConfig(
lockFileConfig,
lockFileConfig.lockFileMaintenance,
);
lockFileConfig = applyPackageRules(lockFileConfig);
lockFileConfig = applyPackageRules(
lockFileConfig,
'lock-file-maintenance-merge-2',
);
// Remove unnecessary objects
for (const updateType of updateTypes) {
delete lockFileConfig[updateType];
Expand Down

0 comments on commit b6b85eb

Please sign in to comment.