diff --git a/lib/workers/repository/process/lookup/index.spec.ts b/lib/workers/repository/process/lookup/index.spec.ts index 2039816e067f5ff5a331706aa9b052dab5364038..10c963df82a8f1e0622f637f76f5ee99d3ebf28c 100644 --- a/lib/workers/repository/process/lookup/index.spec.ts +++ b/lib/workers/repository/process/lookup/index.spec.ts @@ -1871,17 +1871,17 @@ describe('workers/repository/process/lookup/index', () => { }); expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ - { - updateType: 'replacement', - newName: 'eclipse-temurin', - newValue: '17.0.0', - }, { updateType: 'major', newMajor: 18, newValue: '18.0.0', newVersion: '18.0.0', }, + { + updateType: 'replacement', + newName: 'eclipse-temurin', + newValue: '17.0.0', + }, ]); }); @@ -1908,17 +1908,17 @@ describe('workers/repository/process/lookup/index', () => { getDockerDigest.mockResolvedValueOnce('sha256:pin0987654321'); expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ - { - updateType: 'replacement', - newName: 'eclipse-temurin', - newValue: '17.0.0', - newDigest: 'sha256:abcdef1234567890', - }, { updateType: 'major', newMajor: 18, newValue: '18.0.0', newVersion: '18.0.0', + newDigest: 'sha256:abcdef1234567890', + }, + { + updateType: 'replacement', + newName: 'eclipse-temurin', + newValue: '17.0.0', newDigest: 'sha256:0123456789abcdef', }, { @@ -1989,17 +1989,17 @@ describe('workers/repository/process/lookup/index', () => { }); expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ - { - updateType: 'replacement', - newName: 'new.registry.io/library/openjdk', - newValue: '17.0.0', - }, { updateType: 'major', newMajor: 18, newValue: '18.0.0', newVersion: '18.0.0', }, + { + updateType: 'replacement', + newName: 'new.registry.io/library/openjdk', + newValue: '17.0.0', + }, ]); }); @@ -2021,17 +2021,17 @@ describe('workers/repository/process/lookup/index', () => { }); expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ - { - updateType: 'replacement', - newName: 'new.registry.io/library/openjdk', - newValue: '18.0.0', - }, { updateType: 'major', newMajor: 18, newValue: '18.0.0', newVersion: '18.0.0', }, + { + updateType: 'replacement', + newName: 'new.registry.io/library/openjdk', + newValue: '18.0.0', + }, ]); }); @@ -2053,16 +2053,39 @@ describe('workers/repository/process/lookup/index', () => { }); expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ + { + updateType: 'major', + newMajor: 18, + newValue: '18.0.0', + newVersion: '18.0.0', + }, { updateType: 'replacement', newName: 'eclipse-temurin', newValue: '17.0.0', }, + ]); + }); + + it('handles replacements - can perform replacement even for invalid versioning', async () => { + config.packageName = 'adoptopenjdk/openjdk11'; + config.currentValue = 'alpine-jre'; + config.replacementName = 'eclipse-temurin'; + config.replacementVersion = '17.0.0-jre-alpine'; + config.datasource = DockerDatasource.id; + getDockerReleases.mockResolvedValueOnce({ + releases: [ + { + version: 'alpine-jre', + }, + ], + }); + + expect((await lookup.lookupUpdates(config)).updates).toMatchObject([ { - updateType: 'major', - newMajor: 18, - newValue: '18.0.0', - newVersion: '18.0.0', + updateType: 'replacement', + newName: 'eclipse-temurin', + newValue: '17.0.0-jre-alpine', }, ]); }); diff --git a/lib/workers/repository/process/lookup/index.ts b/lib/workers/repository/process/lookup/index.ts index 5b1b0ba7b4d8c5e8ad8e90bbbc10e43a8630ed1b..1434370d15f64da3b473da0255291b0ce47273a0 100644 --- a/lib/workers/repository/process/lookup/index.ts +++ b/lib/workers/repository/process/lookup/index.ts @@ -28,7 +28,6 @@ import { getRollbackUpdate } from './rollback'; import type { LookupUpdateConfig, UpdateResult } from './types'; import { addReplacementUpdateIfValid, - isReplacementNameRulesConfigured, isReplacementRulesConfigured, } from './utils'; @@ -71,6 +70,7 @@ export async function lookupUpdates( return res; } const isValid = is.string(currentValue) && versioning.isValid(currentValue); + if (unconstrainedValue || isValid) { if ( !updatePinnedDependencies && @@ -162,10 +162,6 @@ export async function lookupUpdates( } let rangeStrategy = getRangeStrategy(config); - if (isReplacementRulesConfigured(config)) { - addReplacementUpdateIfValid(res.updates, config); - } - // istanbul ignore next if ( isVulnerabilityAlert && @@ -327,21 +323,20 @@ export async function lookupUpdates( logger.debug( `Dependency ${packageName} has unsupported/unversioned value ${currentValue} (versioning=${config.versioning})` ); + if (!pinDigests && !currentDigest) { res.skipReason = 'invalid-value'; } else { delete res.skipReason; } - } else if (!currentValue && isReplacementNameRulesConfigured(config)) { - logger.debug( - `Handle name-only replacement for ${packageName} without current version` - ); - - addReplacementUpdateIfValid(res.updates, config); } else { res.skipReason = 'invalid-value'; } + if (isReplacementRulesConfigured(config)) { + addReplacementUpdateIfValid(res.updates, config); + } + // Record if the dep is fixed to a version if (lockedVersion) { res.currentVersion = lockedVersion; diff --git a/lib/workers/repository/process/lookup/utils.ts b/lib/workers/repository/process/lookup/utils.ts index 4abf2903681ccfadb5b3d8fecc6753cdfebadeb0..537c62a0085ad2649e42c2f85f84daac9c7828fd 100644 --- a/lib/workers/repository/process/lookup/utils.ts +++ b/lib/workers/repository/process/lookup/utils.ts @@ -25,20 +25,12 @@ export function addReplacementUpdateIfValid( } } -export function isReplacementNameRulesConfigured( - config: LookupUpdateConfig -): boolean { - return ( - is.nonEmptyString(config.replacementName) || - is.nonEmptyString(config.replacementNameTemplate) - ); -} - export function isReplacementRulesConfigured( config: LookupUpdateConfig ): boolean { return ( - isReplacementNameRulesConfigured(config) || + is.nonEmptyString(config.replacementName) || + is.nonEmptyString(config.replacementNameTemplate) || is.nonEmptyString(config.replacementVersion) ); }