From afb2a3dbb0e255d90278f2653004996e6a1edc0f Mon Sep 17 00:00:00 2001 From: Rhys Arkins Date: Sat, 28 Oct 2023 15:57:51 +0200 Subject: [PATCH] fix(gomod): support updating semver go directive (#25479) --- lib/modules/versioning/go-mod-directive/index.spec.ts | 6 ++++-- lib/modules/versioning/go-mod-directive/index.ts | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/modules/versioning/go-mod-directive/index.spec.ts b/lib/modules/versioning/go-mod-directive/index.spec.ts index b19faa97e831d6..21a71df7007ea5 100644 --- a/lib/modules/versioning/go-mod-directive/index.spec.ts +++ b/lib/modules/versioning/go-mod-directive/index.spec.ts @@ -29,7 +29,7 @@ describe('modules/versioning/go-mod-directive/index', () => { version | expected ${'1'} | ${false} ${'1.2'} | ${true} - ${'1.2.3'} | ${false} + ${'1.2.3'} | ${true} `('isValid("$version") === $expected', ({ version, expected }) => { expect(!!semver.isValid(version)).toBe(expected); }); @@ -70,8 +70,10 @@ describe('modules/versioning/go-mod-directive/index', () => { ${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.17.0'} | ${'1.17'} ${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'} ${'1.16'} | ${'replace'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'} - ${'1.16'} | ${'replace'} | ${'1.16.4'} | ${'2.0.0'} | ${'2.0'} + ${'1.16'} | ${'replace'} | ${'1.21.2'} | ${'1.21.2'} | ${'1.21.2'} ${'1.16'} | ${'widen'} | ${'1.16.4'} | ${'1.16.4'} | ${'1.16'} + ${'1.16'} | ${'bump'} | ${'1.16.4'} | ${'1.21.3'} | ${'1.21.3'} + ${'1.21.2'} | ${'bump'} | ${'1.21.2'} | ${'1.21.3'} | ${'1.21.3'} `( 'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"', ({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { diff --git a/lib/modules/versioning/go-mod-directive/index.ts b/lib/modules/versioning/go-mod-directive/index.ts index d62b842e430b16..eaa7dbadb63e50 100644 --- a/lib/modules/versioning/go-mod-directive/index.ts +++ b/lib/modules/versioning/go-mod-directive/index.ts @@ -9,7 +9,7 @@ export const urls = ['https://go.dev/ref/mod']; export const supportsRanges = true; export const supportedRangeStrategies: RangeStrategy[] = ['bump', 'replace']; -const validRegex = regEx(/^\d+\.\d+$/); +const validRegex = regEx(/^\d+\.\d+(\.\d+)?$/); function toNpmRange(range: string): string { return `^${range}`; @@ -25,9 +25,15 @@ function getNewValue({ newVersion, }: NewValueConfig): string { if (rangeStrategy === 'bump') { + if (npm.matches(newVersion, '>=1.20.0')) { + return newVersion; + } return shorten(newVersion); } if (rangeStrategy === 'replace' && !matches(currentValue, newVersion)) { + if (npm.matches(newVersion, '>=1.20.0')) { + return newVersion; + } return shorten(newVersion); } return currentValue;