Skip to content

Commit

Permalink
fix(versioning)!: bump short ranges to version (#20494)
Browse files Browse the repository at this point in the history
When rangeStrategy=bump, and the existing range is "short" (e.g. `^1`), and a bump is required, the new result will be a version range (e.g. `^1.0.7`).

Closes #20488
  • Loading branch information
rarkins committed Mar 10, 2023
1 parent 0f86d31 commit 73c8227
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 42 deletions.
6 changes: 3 additions & 3 deletions lib/modules/versioning/cargo/index.spec.ts
Expand Up @@ -111,11 +111,11 @@ describe('modules/versioning/cargo/index', () => {
${' = 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'= 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'= 1.1.0'}
${'1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0.7'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'^2.0.0'}
${'1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'2.0.0'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2.1.7'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5'}

This comment has been minimized.

Copy link
@Turbo87

Turbo87 Mar 10, 2023

Contributor

since 5 in cargo is equivalent to ^5 this should probably also be bumped to 5.1.7

This comment has been minimized.

Copy link
@rarkins

rarkins Mar 10, 2023

Author Collaborator

Looks like it

${'5'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.0.7'} | ${'5.0'}
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/versioning/composer/index.spec.ts
Expand Up @@ -147,7 +147,7 @@ describe('modules/versioning/composer/index', () => {
${'~1.0 || >=3.0 <=4.0'} | ${'widen'} | ${'2.9.0'} | ${'5.0.0'} | ${'~1.0 || >=3.0 <=5.0'}
${'+4.0.0'} | ${'replace'} | ${'4.0.0'} | ${'4.2.0'} | ${'4.2.0'}
${'v4.0.0'} | ${'replace'} | ${'4.0.0'} | ${'4.2.0'} | ${'v4.2.0'}
${'^v1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^v1.1'}
${'^v1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^v1.1.7'}
${'^v1.0@beta'} | ${'bump'} | ${'1.0.0-beta3'} | ${'1.0.0-beta5'} | ${'^v1.0.0-beta5@beta'}
${'^v1.0@beta'} | ${'replace'} | ${'1.0.0-beta3'} | ${'2.0.0-beta5'} | ${'^v2.0.0-beta5@beta'}
${'^4.0@alpha'} | ${'replace'} | ${'4.0.0-alpha1'} | ${'4.0.0-beta5'} | ${'^4.0.0-beta5@alpha'}
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/versioning/helm/index.spec.ts
Expand Up @@ -34,13 +34,13 @@ describe('modules/versioning/helm/index', () => {
test.each`
currentValue | rangeStrategy | currentVersion | newVersion | expected
${'=1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0.7'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7-prerelease.1'} | ${'^1.0.7-prerelease.1'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^1.1'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^1.1.7'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7-prerelease.1'} | ${'~1.0.7-prerelease.1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2.1.7'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.0.7'} | ${'5.0'}
Expand Down
10 changes: 5 additions & 5 deletions lib/modules/versioning/npm/index.spec.ts
Expand Up @@ -58,14 +58,14 @@ describe('modules/versioning/npm/index', () => {
test.each`
currentValue | rangeStrategy | currentVersion | newVersion | expected
${'=1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0.7'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7-prerelease.1'} | ${'^1.0.7-prerelease.1'}
${'~> 1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.1.7'} | ${'~> 1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^1.1'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'^1.1.7'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7-prerelease.1'} | ${'~1.0.7-prerelease.1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2.1.7'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.0.7'} | ${'5.0'}
Expand Down
24 changes: 0 additions & 24 deletions lib/modules/versioning/npm/range.ts
Expand Up @@ -136,33 +136,9 @@ export function getNewValue({
});
}
if (element.operator === '^') {
const split = currentValue.split('.');
if (suffix.length) {
return `^${newVersion}`;
}
if (split.length === 1) {
// ^4
return `^${toVersionMajor}`;
}
if (split.length === 2) {
// ^4.1
return `^${toVersionMajor}.${toVersionMinor}`;
}
return `^${newVersion}`;
}
if (element.operator === '~') {
const split = currentValue.split('.');
if (suffix.length) {
return `~${newVersion}`;
}
if (split.length === 1) {
// ~4
return `~${toVersionMajor}`;
}
if (split.length === 2) {
// ~4.1
return `~${toVersionMajor}.${toVersionMinor}`;
}
return `~${newVersion}`;
}
if (element.operator === '=') {
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/versioning/poetry/index.spec.ts
Expand Up @@ -189,15 +189,15 @@ describe('modules/versioning/poetry/index', () => {
${' = 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${' = 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'= 1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.0'} | ${'=1.1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0'}
${'^1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.0.7'} | ${'^1.0.7'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'^2.0.0'}
${'^5.0.3'} | ${'replace'} | ${'5.3.1'} | ${'5.5'} | ${'^5.0.3'}
${'1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'2.0.7'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'2.0.7'} | ${'^2.0.0'}
${'^0.5.15'} | ${'replace'} | ${'0.5.15'} | ${'0.6'} | ${'^0.5.15'}
${'^0.5.15'} | ${'replace'} | ${'0.5.15'} | ${'0.6b.4'} | ${'^0.5.15'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1'}
${'^1'} | ${'bump'} | ${'1.0.0'} | ${'2.1.7'} | ${'^2.1.7'}
${'~1'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'5.1.7'} | ${'5'}
${'5'} | ${'bump'} | ${'5.0.0'} | ${'6.1.7'} | ${'6'}
${'5.0'} | ${'bump'} | ${'5.0.0'} | ${'5.0.7'} | ${'5.0'}
Expand All @@ -211,7 +211,7 @@ describe('modules/versioning/poetry/index', () => {
${'^0.8.0-alpha.0'} | ${'bump'} | ${'0.8.0-alpha.0'} | ${'0.8.0-alpha.1'} | ${'^0.8.0-alpha.1'}
${'^0.8.0-alpha.0'} | ${'bump'} | ${'0.8.0-alpha.0'} | ${'0.8.0a1'} | ${'^0.8.0-alpha.1'}
${'^1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.3'} | ${'^1.0.0'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1'}
${'~1.0'} | ${'bump'} | ${'1.0.0'} | ${'1.1.7'} | ${'~1.1.7'}
${'1.0.*'} | ${'replace'} | ${'1.0.0'} | ${'1.1.0'} | ${'1.1.*'}
${'1.*'} | ${'replace'} | ${'1.0.0'} | ${'2.1.0'} | ${'2.*'}
${'~0.6.1'} | ${'replace'} | ${'0.6.8'} | ${'0.7.0-rc.2'} | ${'~0.7.0-rc'}
Expand Down

0 comments on commit 73c8227

Please sign in to comment.