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

feat(gradle): bump strategy #33453

Merged
merged 13 commits into from
Feb 20, 2025
Merged
4 changes: 4 additions & 0 deletions lib/modules/manager/gradle/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,12 @@ describe('modules/manager/gradle/parser', () => {
it.each`
input | output
${'"foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
${'"foo:bar:1.2+"'} | ${{ depName: 'foo:bar', currentValue: '1.2+' }}
${'"foo:bar:1.2.3@zip"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', dataType: 'zip' }}
${'"foo:bar1:1"'} | ${{ depName: 'foo:bar1', currentValue: '1', managerData: { fileReplacePosition: 10 } }}
${'"foo:bar:[1.2.3, )"'} | ${{ depName: 'foo:bar', currentValue: '[1.2.3, )', managerData: { fileReplacePosition: 9 } }}
${'"foo:bar:[1.2.3, 1.2.4)"'} | ${{ depName: 'foo:bar', currentValue: '[1.2.3, 1.2.4)', managerData: { fileReplacePosition: 9 } }}
${'"foo:bar:[,1.2.4)"'} | ${{ depName: 'foo:bar', currentValue: '[,1.2.4)', managerData: { fileReplacePosition: 9 } }}
${'"foo:bar:x86@x86"'} | ${{ depName: 'foo:bar', currentValue: 'x86', managerData: { fileReplacePosition: 9 } }}
${'foo.bar = "foo:bar:1.2.3"'} | ${{ depName: 'foo:bar', currentValue: '1.2.3' }}
`('$input', ({ input, output }) => {
Expand Down
13 changes: 12 additions & 1 deletion lib/modules/manager/gradle/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ describe('modules/manager/gradle/utils', () => {
});

it('returns null for invalid inputs', () => {
const inputs = ['', undefined, null, 'foobar', 'latest'];
const inputs = [
'',
undefined,
null,
'foobar',
'latest',
'[1.6.0, ] , abc',
];
for (const input of inputs) {
expect(versionLikeSubstring(input)).toBeNull();
}
Expand All @@ -53,6 +60,9 @@ describe('modules/manager/gradle/utils', () => {
${'foo:bar:1.2.3@zip'} | ${true}
${'foo:bar:x86@x86'} | ${true}
${'foo.bar:baz:1.2.+'} | ${true}
${'foo.bar:baz:[1.6.0, ]'} | ${true}
${'foo.bar:baz:[, 1.6.0)'} | ${true}
${'foo.bar:baz:]1.6.0,]'} | ${true}
${'foo:bar:baz:qux'} | ${false}
${'foo:bar:baz:qux:quux'} | ${false}
${"foo:bar:1.2.3'"} | ${false}
Expand All @@ -74,6 +84,7 @@ describe('modules/manager/gradle/utils', () => {
${'foo.foo:bar.bar:1.2.3'} | ${{ depName: 'foo.foo:bar.bar', currentValue: '1.2.3' }}
${'foo.bar:baz:1.2.3'} | ${{ depName: 'foo.bar:baz', currentValue: '1.2.3' }}
${'foo:bar:1.2.+'} | ${{ depName: 'foo:bar', currentValue: '1.2.+' }}
${'foo.bar:baz:[1.6.0, ]'} | ${{ depName: 'foo.bar:baz', currentValue: '[1.6.0, ]' }}
${'foo:bar:1.2.3@zip'} | ${{ depName: 'foo:bar', currentValue: '1.2.3', dataType: 'zip' }}
${'foo:bar:baz:qux'} | ${null}
${'foo:bar:baz:qux:quux'} | ${null}
Expand Down
9 changes: 7 additions & 2 deletions lib/modules/manager/gradle/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import upath from 'upath';
import { regEx } from '../../../util/regex';
import { api as gradleVersioning } from '../../versioning/gradle';
import type { PackageDependency } from '../types';
import type {
GradleManagerData,
Expand All @@ -11,7 +12,7 @@ const artifactRegex = regEx(
'^[a-zA-Z][-_a-zA-Z0-9]*(?:\\.[a-zA-Z0-9][-_a-zA-Z0-9]*?)*$',
);

const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+]+)');
const versionLikeRegex = regEx('^(?<version>[-_.\\[\\](),a-zA-Z0-9+ ]+)');

// Extracts version-like and range-like strings from the beginning of input
export function versionLikeSubstring(
Expand All @@ -22,11 +23,15 @@ export function versionLikeSubstring(
}

const match = versionLikeRegex.exec(input);
const version = match?.groups?.version;
const version = match?.groups?.version?.trim();
if (!version || !regEx(/\d/).test(version)) {
return null;
}

if (!gradleVersioning.isValid(version)) {
return null;
}

return version;
}

Expand Down
11 changes: 11 additions & 0 deletions lib/modules/versioning/gradle/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,17 @@ describe('modules/versioning/gradle/index', () => {
${'[1.0,1.2],[1.3,1.5['} | ${'pin'} | ${'1.0'} | ${'1.2.4'} | ${'1.2.4'}
${'[1.2.3,)'} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'}
${'[1.2.3,['} | ${'pin'} | ${'1.2.3'} | ${'1.2.4'} | ${'1.2.4'}
${'[1.2.3]'} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4]'}
${'[1.0.0,1.2.3]'} | ${'bump'} | ${'1.0.0'} | ${'1.2.4'} | ${'[1.0.0,1.2.4]'}
${'[1.0.0,1.2.23]'} | ${'bump'} | ${'1.0.0'} | ${'1.2.23'} | ${'[1.0.0,1.2.23]'}
${'(,1.0]'} | ${'bump'} | ${'0.0.1'} | ${'2.0'} | ${'(,2.0]'}
${'],1.0]'} | ${'bump'} | ${'0.0.1'} | ${'2.0'} | ${'],2.0]'}
${'(,1.0)'} | ${'bump'} | ${'0.1'} | ${'2.0'} | ${'(,3.0)'}
${'],1.0['} | ${'bump'} | ${'2.0'} | ${'],2.0['} | ${'],1.0['}
${'[1.0,1.2],[1.3,1.5)'} | ${'bump'} | ${'1.0'} | ${'1.2.4'} | ${'[1.0,1.2],[1.3,1.5)'}
${'[1.0,1.2],[1.3,1.5['} | ${'bump'} | ${'1.0'} | ${'1.2.4'} | ${'[1.0,1.2],[1.3,1.5['}
${'[1.2.3,)'} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4,)'}
${'[1.2.3,['} | ${'bump'} | ${'1.2.3'} | ${'1.2.4'} | ${'[1.2.4,['}
`(
'getNewValue($currentValue, $rangeStrategy, $currentVersion, $newVersion, $expected) === $expected',
({
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/versioning/gradle/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const urls = [
'https://docs.gradle.org/current/userguide/single_versions.html#version_ordering',
];
export const supportsRanges = true;
export const supportedRangeStrategies: RangeStrategy[] = ['pin'];
export const supportedRangeStrategies: RangeStrategy[] = ['pin', 'bump'];

const equals = (a: string, b: string): boolean => compare(a, b) === 0;

Expand Down
Loading