diff --git a/lib/modules/manager/gomod/artifacts.spec.ts b/lib/modules/manager/gomod/artifacts.spec.ts index 4c913e7fdff3023fd6785164fdb55e096cdcde4c..667eee6bdd7a3dde228eda6db9b93fef50510574 100644 --- a/lib/modules/manager/gomod/artifacts.spec.ts +++ b/lib/modules/manager/gomod/artifacts.spec.ts @@ -1434,6 +1434,55 @@ describe('modules/manager/gomod/artifacts', () => { ]); }); + it('skips updating import paths when incompatible version', async () => { + fs.readLocalFile + .mockResolvedValueOnce('Current go.sum') + .mockResolvedValueOnce(null); // vendor modules filename + const execSnapshots = mockExecAll(); + git.getRepoStatus.mockResolvedValueOnce( + partial<StatusResult>({ + modified: ['go.sum'], + }) + ); + fs.readLocalFile + .mockResolvedValueOnce('New go.sum') + .mockResolvedValueOnce('New go.mod'); + expect( + await gomod.updateArtifacts({ + packageFileName: 'go.mod', + updatedDeps: [ + { + depName: 'github.com/docker/docker', + newVersion: 'v23.0.0+incompatible', + }, + ], + newPackageFileContent: gomod1, + config: { + ...config, + updateType: 'major', + postUpdateOptions: ['gomodUpdateImportPaths'], + }, + }) + ).toEqual([ + { file: { type: 'addition', path: 'go.sum', contents: 'New go.sum' } }, + { file: { type: 'addition', path: 'go.mod', contents: 'New go.mod' } }, + ]); + expect(execSnapshots).toMatchObject([ + { + cmd: 'go get -d -t ./...', + options: { cwd: '/tmp/github/some/repo' }, + }, + { + cmd: 'go mod tidy', + options: { cwd: '/tmp/github/some/repo' }, + }, + { + cmd: 'go mod tidy', + options: { cwd: '/tmp/github/some/repo' }, + }, + ]); + }); + it('skips gomodTidy without gomodUpdateImportPaths on major update', async () => { fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename diff --git a/lib/modules/manager/gomod/artifacts.ts b/lib/modules/manager/gomod/artifacts.ts index 570ffed67a64be0579d81406e2f7292cc2dddbd1..6ef9025014685b5a2382cd01ded7a707456da2f6 100644 --- a/lib/modules/manager/gomod/artifacts.ts +++ b/lib/modules/manager/gomod/artifacts.ts @@ -129,14 +129,17 @@ function getUpdateImportPathCmds( } const updateImportCommands = updatedDeps - .filter(({ newVersion }) => valid(newVersion)) + .filter( + ({ newVersion }) => + valid(newVersion) && !newVersion!.endsWith('+incompatible') + ) .map(({ depName, newVersion }) => ({ depName: depName!, newMajor: major(newVersion!), })) // Skip path updates going from v0 to v1 .filter( - ({ depName, newMajor }) => depName.startsWith('gopkg.in') || newMajor > 1 + ({ depName, newMajor }) => depName.startsWith('gopkg.in/') || newMajor > 1 ) .map( diff --git a/lib/modules/manager/gomod/update.spec.ts b/lib/modules/manager/gomod/update.spec.ts index 240eb184eec37756f84c1a99a51045af5ed2cc65..6270bb8cc743001fdb49b669dc5ad0214baba36a 100644 --- a/lib/modules/manager/gomod/update.spec.ts +++ b/lib/modules/manager/gomod/update.spec.ts @@ -96,7 +96,7 @@ describe('modules/manager/gomod/update', () => { depType: 'require', }; const res = updateDependency({ fileContent: gomod1, upgrade }); - expect(res).not.toEqual(gomod2); + expect(res).not.toEqual(gomod1); expect(res).toContain('github.com/pkg/errors/v2 v2.0.0'); }); @@ -112,10 +112,27 @@ describe('modules/manager/gomod/update', () => { }; const res = updateDependency({ fileContent: gomod1, upgrade }); expect(res).toMatchSnapshot(); - expect(res).not.toEqual(gomod2); + expect(res).not.toEqual(gomod1); expect(res).toContain('gopkg.in/russross/blackfriday.v2 v2.0.0'); }); + it('skip replacing incompatible major updates', () => { + const upgrade = { + depName: 'github.com/Azure/azure-sdk-for-go', + managerData: { lineNumber: 8 }, + newMajor: 26, + updateType: 'major' as UpdateType, + currentValue: 'v25.1.0+incompatible', + newValue: 'v26.0.0+incompatible', + depType: 'require', + }; + const res = updateDependency({ fileContent: gomod1, upgrade }); + expect(res).not.toEqual(gomod1); + expect(res).toContain( + 'github.com/Azure/azure-sdk-for-go v26.0.0+incompatible' + ); + }); + it('returns null if mismatch', () => { const upgrade = { depName: 'github.com/aws/aws-sdk-go', diff --git a/lib/modules/manager/gomod/update.ts b/lib/modules/manager/gomod/update.ts index 47202948da111fc3534b76fe3aa09f1f31952beb..d2839abce36647b25a5aa425e774173e104b870b 100644 --- a/lib/modules/manager/gomod/update.ts +++ b/lib/modules/manager/gomod/update.ts @@ -105,7 +105,8 @@ export function updateDependency({ ); } else if ( upgrade.newMajor! > 1 && - !newLine.includes(`/v${upgrade.newMajor}`) + !newLine.includes(`/v${upgrade.newMajor}`) && + !upgrade.newValue!.endsWith('+incompatible') ) { if (depName === depNameNoVersion) { // If package currently has no version, pin to latest one.