diff --git a/docs/usage/configuration-options.md b/docs/usage/configuration-options.md index 01cef5de8168ac6149f8a84e79e79fdfab02465f..f780c472f7fef8691a5fc8a965b99c86cccdc69c 100644 --- a/docs/usage/configuration-options.md +++ b/docs/usage/configuration-options.md @@ -1770,6 +1770,7 @@ For example, GitHub might automerge a Renovate branch even if it's behind the ba ## postUpdateOptions - `gomodTidy`: Run `go mod tidy` after Go module updates. This is implicitly enabled for major module updates when `gomodUpdateImportPaths` is enabled +- `gomodTidy1.17`: Run `go mod tidy -compat=1.17` after Go module updates. - `gomodUpdateImportPaths`: Update source import paths on major module updates, using [mod](https://github.com/marwan-at-work/mod) - `npmDedupe`: Run `npm dedupe` after `package-lock.json` updates - `yarnDedupeFewer`: Run `yarn-deduplicate --strategy fewer` after `yarn.lock` updates diff --git a/docs/usage/golang.md b/docs/usage/golang.md index 67f9b8c5dac9a883176bc14695126bb8871b1aef..f450e05c1fa7f70b3a88bcb47a0728d411c3a499 100644 --- a/docs/usage/golang.md +++ b/docs/usage/golang.md @@ -15,8 +15,8 @@ Renovate supports upgrading dependencies in `go.mod` files and their accompanyin 1. If Renovate finds an update, Renovate will update `go.mod` to the new value 1. Renovate runs `go get` to update the `go.sum` files 1. If the user has enabled the option `gomodUpdateImportPaths` in the [`postUpdateOptions`](https://docs.renovatebot.com/configuration-options/#postupdateoptions) array, then Renovate uses [mod](https://github.com/marwan-at-work/mod) to update import paths on major updates, which can update any Go source file -1. If the user has enabled the option `gomodTidy` in the [`postUpdateOptions`](https://docs.renovatebot.com/configuration-options/#postupdateoptions) array, then Renovate runs `go mod tidy`, which itself can update `go.mod` and `go.sum`. - 1. This is implicitly enabled for major updates if the user has enabled the option `gomodUpdateImportPaths` in the [`postUpdateOptions`](https://docs.renovatebot.com/configuration-options/#postupdateoptions) array +1. If the user has enabled the option `gomodTidy` or `gomodTidy1.17` in the [`postUpdateOptions`](https://docs.renovatebot.com/configuration-options/#postupdateoptions) array, then Renovate runs `go mod tidy` or `go mod tidy -compat=1.17` respectively, which itself can update `go.mod` and `go.sum`. + 1. `gomodTidy` is implicitly enabled for major updates if the user has enabled the option `gomodUpdateImportPaths` in the [`postUpdateOptions`](https://docs.renovatebot.com/configuration-options/#postupdateoptions) array. If go modules 1.17 compatibility is needed you need to explicitly set the option `gomodTidy1.17`. 1. `go mod vendor` is run if vendored modules are detected 1. A PR will be created with `go.mod`,`go.sum`, and any updated vendored files updated in the one commit 1. If the source repository has either a "changelog" file or uses GitHub releases, then Release Notes for each version will be embedded in the generated PR diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index 5b966d52dfd2db1df9f850004da09874f47a36a2..f8c8ede366e7a68f02e5433a925b1a47a6bd3767 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -1737,6 +1737,7 @@ const options: RenovateOptions[] = [ allowedValues: [ 'gomodUpdateImportPaths', 'gomodTidy', + 'gomodTidy1.17', 'npmDedupe', 'yarnDedupeFewer', 'yarnDedupeHighest', diff --git a/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap b/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap index 5b3c4f8c7231b20868ca5ac4c7878a81ada01a53..f623052a8cdb650a50506fb28419dfdb2bc3535b 100644 --- a/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap +++ b/lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap @@ -345,6 +345,47 @@ Array [ ] `; +exports[`manager/gomod/artifacts supports docker mode with gomodTidy1.17 1`] = ` +Array [ + Object { + "cmd": "docker pull renovate/go:latest", + "options": Object { + "encoding": "utf-8", + }, + }, + Object { + "cmd": "docker ps --filter name=renovate_go -aq", + "options": Object { + "encoding": "utf-8", + }, + }, + Object { + "cmd": "docker run --rm --name=renovate_go --label=renovate_child -v \\"/tmp/github/some/repo\\":\\"/tmp/github/some/repo\\" -v \\"/tmp/renovate/cache\\":\\"/tmp/renovate/cache\\" -e GOPROXY -e GOPRIVATE -e GONOPROXY -e GONOSUMDB -e GOFLAGS -e CGO_ENABLED -w \\"/tmp/github/some/repo\\" renovate/go:latest bash -l -c \\"go get -d ./... && go mod tidy -compat=1.17 && go mod tidy -compat=1.17\\"", + "options": Object { + "cwd": "/tmp/github/some/repo", + "encoding": "utf-8", + "env": Object { + "CGO_ENABLED": "1", + "GOFLAGS": "-modcacherw", + "GONOPROXY": "noproxy.example.com/*", + "GONOSUMDB": "1", + "GOPRIVATE": "private.example.com/*", + "GOPROXY": "proxy.example.com", + "HOME": "/home/user", + "HTTPS_PROXY": "https://example.com", + "HTTP_PROXY": "http://example.com", + "LANG": "en_US.UTF-8", + "LC_ALL": "en_US", + "NO_PROXY": "localhost", + "PATH": "/tmp/path", + }, + "maxBuffer": 10485760, + "timeout": 900000, + }, + }, +] +`; + exports[`manager/gomod/artifacts supports docker mode without credentials 1`] = ` Array [ Object { diff --git a/lib/manager/gomod/artifacts.spec.ts b/lib/manager/gomod/artifacts.spec.ts index d84c82d52b59697f5ed252ee016970eff0f56298..133f738e39af5855b09cf52f2fffb3a3228fe010 100644 --- a/lib/manager/gomod/artifacts.spec.ts +++ b/lib/manager/gomod/artifacts.spec.ts @@ -522,6 +522,33 @@ describe('manager/gomod/artifacts', () => { expect(execSnapshots).toMatchSnapshot(); }); + it('supports docker mode with gomodTidy1.17', async () => { + GlobalConfig.set({ ...adminConfig, binarySource: 'docker' }); + hostRules.find.mockReturnValueOnce({}); + fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); + fs.readLocalFile.mockResolvedValueOnce(null); // vendor modules filename + const execSnapshots = mockExecAll(exec); + git.getRepoStatus.mockResolvedValueOnce({ + modified: ['go.sum'], + } as StatusResult); + fs.readLocalFile.mockResolvedValueOnce('New go.sum 1'); + fs.readLocalFile.mockResolvedValueOnce('New go.sum 2'); + fs.readLocalFile.mockResolvedValueOnce('New go.sum 3'); + fs.readLocalFile.mockResolvedValueOnce('New go.mod'); + expect( + await gomod.updateArtifacts({ + packageFileName: 'go.mod', + updatedDeps: [], + newPackageFileContent: gomod1, + config: { + ...config, + postUpdateOptions: ['gomodTidy1.17'], + }, + }) + ).not.toBeNull(); + expect(execSnapshots).toMatchSnapshot(); + }); + it('catches errors', async () => { const execSnapshots = mockExecAll(exec); fs.readLocalFile.mockResolvedValueOnce('Current go.sum'); diff --git a/lib/manager/gomod/artifacts.ts b/lib/manager/gomod/artifacts.ts index e8a114a1b82b6e95ef4b9e17d91f7d446769bc07..d0e6260f5d2b21be33984fce875082d89cd10e7c 100644 --- a/lib/manager/gomod/artifacts.ts +++ b/lib/manager/gomod/artifacts.ts @@ -209,12 +209,16 @@ export async function updateArtifacts({ logger.debug({ cmd, args }, 'go mod tidy command skipped'); } + const tidyOpts = config.postUpdateOptions?.includes('gomodTidy1.17') + ? ' -compat=1.17' + : ''; const isGoModTidyRequired = !mustSkipGoModTidy && (config.postUpdateOptions?.includes('gomodTidy') || + config.postUpdateOptions?.includes('gomodTidy1.17') || (config.updateType === 'major' && isImportPathUpdateRequired)); if (isGoModTidyRequired) { - args = 'mod tidy'; + args = 'mod tidy' + tidyOpts; logger.debug({ cmd, args }, 'go mod tidy command included'); execCommands.push(`${cmd} ${args}`); } @@ -224,7 +228,7 @@ export async function updateArtifacts({ logger.debug({ cmd, args }, 'go mod vendor command included'); execCommands.push(`${cmd} ${args}`); if (isGoModTidyRequired) { - args = 'mod tidy'; + args = 'mod tidy' + tidyOpts; logger.debug({ cmd, args }, 'go mod tidy command included'); execCommands.push(`${cmd} ${args}`); } @@ -232,7 +236,7 @@ export async function updateArtifacts({ // We tidy one more time as a solution for #6795 if (isGoModTidyRequired) { - args = 'mod tidy'; + args = 'mod tidy' + tidyOpts; logger.debug({ cmd, args }, 'additional go mod tidy command included'); execCommands.push(`${cmd} ${args}`); } diff --git a/lib/manager/gomod/readme.md b/lib/manager/gomod/readme.md index 4902635cb5b971011a8e486b919cf77ea0456e47..62cd3782c068b3561066b3211536112b47a8ce01 100644 --- a/lib/manager/gomod/readme.md +++ b/lib/manager/gomod/readme.md @@ -2,6 +2,7 @@ You might be interested in the following `postUpdateOptions`: 1. `gomodTidy` - if you'd like Renovate to run `go mod tidy` after every update before raising the PR. 1. This is implicitly enabled for major updates if the user has enabled the option `gomodUpdateImportPaths` +1. `gomodTidy1.17` - if you'd like Renovate to run `go mod tidy -compat=1.17` after every update before raising the PR. 1. `gomodUpdateImportPaths` - if you'd like Renovate to update your source import paths on major updates before raising the PR. When Renovate is running using `binarySource=docker` (such as in the hosted WhiteSource Renovate app) then it will pick the latest compatible version of Go to run, i.e. the latest `1.x` release.