Skip to content

Commit

Permalink
feat(versioning/gradle): Support Gradle prefix versions (#25379)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanowen committed Oct 25, 2023
1 parent 393cc51 commit 4753eb0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/modules/versioning/gradle/compare.ts
Expand Up @@ -50,6 +50,7 @@ export function tokenize(versionStr: string): Token[] | null {

function yieldToken(): void {
if (currentVal === '') {
// We tried to yield an empty token, which means we're in a bad state.
result = null;
}
if (result) {
Expand Down
7 changes: 7 additions & 0 deletions lib/modules/versioning/gradle/index.spec.ts
Expand Up @@ -267,6 +267,13 @@ describe('modules/versioning/gradle/index', () => {
currentValue | rangeStrategy | currentVersion | newVersion | expected
${'1'} | ${null} | ${null} | ${'1.1'} | ${'1.1'}
${'[1.2.3,]'} | ${null} | ${null} | ${'1.2.4'} | ${null}
${'+'} | ${null} | ${null} | ${'1.2.4'} | ${null}
${'1.+'} | ${null} | ${null} | ${'1.2.4'} | ${'1.+'}
${'1.+'} | ${null} | ${null} | ${'2.1.2'} | ${'2.+'}
${'1.+'} | ${null} | ${null} | ${'2'} | ${'2.+'}
${'1.3.+'} | ${null} | ${null} | ${'1.3.4'} | ${'1.3.+'}
${'1.3.+'} | ${null} | ${null} | ${'1.5.2'} | ${'1.5.+'}
${'1.3.+'} | ${null} | ${null} | ${'2'} | ${'2'}
${'[1.2.3]'} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'}
${'[1.0.0,1.2.3]'} | ${'pin'} | ${'1.0.0'} | ${'1.2.4'} | ${'1.2.4'}
${'[1.0.0,1.2.23]'} | ${'pin'} | ${'1.0.0'} | ${'1.2.23'} | ${'1.2.23'}
Expand Down
22 changes: 22 additions & 0 deletions lib/modules/versioning/gradle/index.ts
Expand Up @@ -195,6 +195,28 @@ function getNewValue({
if (isVersion(currentValue) || rangeStrategy === 'pin') {
return newVersion;
}

// Check if our version is of the form "1.2.+"
const prefixRange = parsePrefixRange(currentValue);
const parsedNewVersion = parse(newVersion);
if (prefixRange && parsedNewVersion) {
if (prefixRange.tokens.length > 0) {
if (prefixRange.tokens.length <= parsedNewVersion.length) {
const newPrefixed = prefixRange.tokens
.map((_, i) => parsedNewVersion[i].val)
.join('.');

return `${newPrefixed}.+`;
} else {
// our new version is shorter than our prefix range so drop our prefix range
return newVersion;
}
} else {
// our version is already "+" which includes ever version
return null;
}
}

return null;
}

Expand Down

0 comments on commit 4753eb0

Please sign in to comment.