From cb7c10bb9d479ed020a6dfb73b120a4971126f42 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Sat, 16 Nov 2024 07:32:33 -0300 Subject: [PATCH] fix: Handle `extractVersion` with release post-processing (#32540) --- lib/modules/datasource/common.spec.ts | 7 ++++-- lib/modules/datasource/common.ts | 1 + lib/modules/datasource/maven/index.ts | 7 +++--- .../datasource/postprocess-release.spec.ts | 25 ------------------- lib/modules/datasource/postprocess-release.ts | 22 ++++++---------- lib/modules/datasource/types.ts | 2 ++ 6 files changed, 19 insertions(+), 45 deletions(-) diff --git a/lib/modules/datasource/common.spec.ts b/lib/modules/datasource/common.spec.ts index a86c6a2d3f43de..02eddebeb117df 100644 --- a/lib/modules/datasource/common.spec.ts +++ b/lib/modules/datasource/common.spec.ts @@ -103,7 +103,10 @@ describe('modules/datasource/common', () => { }; const res = applyExtractVersion(releaseResult, '^v(?.+)$'); expect(res).toEqual({ - releases: [{ version: '1.0.0' }, { version: '2.0.0' }], + releases: [ + { version: '1.0.0', versionOrig: 'v1.0.0' }, + { version: '2.0.0', versionOrig: 'v2.0.0' }, + ], }); }); @@ -113,7 +116,7 @@ describe('modules/datasource/common', () => { }; const result = applyExtractVersion(releaseResult, '^v(?.+)$'); expect(result).toEqual({ - releases: [{ version: '1.0.0' }], + releases: [{ version: '1.0.0', versionOrig: 'v1.0.0' }], }); }); }); diff --git a/lib/modules/datasource/common.ts b/lib/modules/datasource/common.ts index b50f109ef2d9db..7ce15263d9615a 100644 --- a/lib/modules/datasource/common.ts +++ b/lib/modules/datasource/common.ts @@ -110,6 +110,7 @@ export function applyExtractVersion( return null; } + release.versionOrig = release.version; release.version = version; return release; }); diff --git a/lib/modules/datasource/maven/index.ts b/lib/modules/datasource/maven/index.ts index 32bed54f21ac5b..8fd08b788131ab 100644 --- a/lib/modules/datasource/maven/index.ts +++ b/lib/modules/datasource/maven/index.ts @@ -252,8 +252,9 @@ export class MavenDatasource extends Datasource { namespace: `datasource-maven`, key: ( { registryUrl, packageName }: PostprocessReleaseConfig, - { version }: Release, - ) => `postprocessRelease:${registryUrl}:${packageName}:${version}`, + { version, versionOrig }: Release, + ) => + `postprocessRelease:${registryUrl}:${packageName}:${versionOrig ?? version}`, ttlMinutes: 24 * 60, }) override async postprocessRelease( @@ -268,7 +269,7 @@ export class MavenDatasource extends Datasource { const pomUrl = await createUrlForDependencyPom( this.http, - release.version, + release.versionOrig ?? release.version, dependency, registryUrl, ); diff --git a/lib/modules/datasource/postprocess-release.spec.ts b/lib/modules/datasource/postprocess-release.spec.ts index a8cacb3d92378e..3ec6de9abd8e99 100644 --- a/lib/modules/datasource/postprocess-release.spec.ts +++ b/lib/modules/datasource/postprocess-release.spec.ts @@ -124,31 +124,6 @@ describe('modules/datasource/postprocess-release', () => { expect(release).toBeNull(); }); - it('preserves rejected release when `extractVersion` was set', async () => { - const releaseOrig: Release = { version: '1.2.3' }; - - class SomeDatasource extends DummyDatasource { - override postprocessRelease( - _config: PostprocessReleaseConfig, - _release: Release, - ): Promise { - return Promise.resolve('reject'); - } - } - getDatasourceFor.mockReturnValueOnce(new SomeDatasource()); - - const release = await postprocessRelease( - { - datasource: 'some-datasource', - packageName: 'some-package', - extractVersion: '^(?\\d+)$', - }, - releaseOrig, - ); - - expect(release).toBe(releaseOrig); - }); - it('falls back when error was thrown', async () => { const releaseOrig: Release = { version: '1.2.3' }; diff --git a/lib/modules/datasource/postprocess-release.ts b/lib/modules/datasource/postprocess-release.ts index b2ba55624557d8..a71837fee471db 100644 --- a/lib/modules/datasource/postprocess-release.ts +++ b/lib/modules/datasource/postprocess-release.ts @@ -49,22 +49,14 @@ export async function postprocessRelease( ); if (result === 'reject') { - if (config.extractVersion) { - logger.debug( - { - datasource, - packageName, - registryUrl, - version: release.version, - extractVersion: config.extractVersion, - }, - 'Rejected release combined with `extractVersion`: preserving the release', - ); - return release; - } - logger.debug( - { datasource, packageName, registryUrl, version: release.version }, + { + datasource, + packageName, + registryUrl, + version: release.version, + versionOrig: release.versionOrig, + }, 'Rejected release', ); return null; diff --git a/lib/modules/datasource/types.ts b/lib/modules/datasource/types.ts index d4e8ed0b3287e2..94336ff106cc3d 100644 --- a/lib/modules/datasource/types.ts +++ b/lib/modules/datasource/types.ts @@ -61,6 +61,8 @@ export interface Release { isStable?: boolean; releaseTimestamp?: string | null; version: string; + /** The original value to which `extractVersion` was applied */ + versionOrig?: string; newDigest?: string | undefined; constraints?: Record; dependencies?: Record;