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

fix: Handle extractVersion with release post-processing #32540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/modules/datasource/common.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ describe('modules/datasource/common', () => {
};
const res = applyExtractVersion(releaseResult, '^v(?<version>.+)$');
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' },
],
});
});

Expand All @@ -113,7 +116,7 @@ describe('modules/datasource/common', () => {
};
const result = applyExtractVersion(releaseResult, '^v(?<version>.+)$');
expect(result).toEqual({
releases: [{ version: '1.0.0' }],
releases: [{ version: '1.0.0', versionOrig: 'v1.0.0' }],
});
});
});
Expand Down
1 change: 1 addition & 0 deletions lib/modules/datasource/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function applyExtractVersion(
return null;
}

release.versionOrig = release.version;
release.version = version;
return release;
});
Expand Down
7 changes: 4 additions & 3 deletions lib/modules/datasource/maven/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -268,7 +269,7 @@ export class MavenDatasource extends Datasource {

const pomUrl = await createUrlForDependencyPom(
this.http,
release.version,
release.versionOrig ?? release.version,
dependency,
registryUrl,
);
Expand Down
25 changes: 0 additions & 25 deletions lib/modules/datasource/postprocess-release.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PostprocessReleaseResult> {
return Promise.resolve('reject');
}
}
getDatasourceFor.mockReturnValueOnce(new SomeDatasource());

const release = await postprocessRelease(
{
datasource: 'some-datasource',
packageName: 'some-package',
extractVersion: '^(?<version>\\d+)$',
},
releaseOrig,
);

expect(release).toBe(releaseOrig);
});

it('falls back when error was thrown', async () => {
const releaseOrig: Release = { version: '1.2.3' };

Expand Down
22 changes: 7 additions & 15 deletions lib/modules/datasource/postprocess-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions lib/modules/datasource/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string[]>;
dependencies?: Record<string, string>;
Expand Down