diff --git a/lib/config/definitions.js b/lib/config/definitions.js index b37632b49879bf0ca5e088afce63d5da3d8d999a..e21b310b5d8f64b82c1de65ca071a30c7ab09001 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -1064,6 +1064,12 @@ const options = [ }, mergeable: true, }, + { + name: 'gomodTidy', + description: 'Enable to run `go mod tidy` after Go module updates', + type: 'boolean', + default: false, + }, { name: 'ruby', releaseStatus: 'alpha', diff --git a/lib/manager/gomod/artifacts.js b/lib/manager/gomod/artifacts.js index e51935d31de3bea41a3b828f77c2dbb205405134..1827baebceaecb51f898de3bd9bc5d335db4c9ee 100644 --- a/lib/manager/gomod/artifacts.js +++ b/lib/manager/gomod/artifacts.js @@ -78,6 +78,28 @@ async function getArtifacts( { seconds, type: 'go.sum', stdout, stderr }, 'Generated lockfile' ); + // istanbul ignore if + if (config.gomodTidy) { + if (config.gitFs) { + args = 'mod tidy'; + logger.debug({ cmd, args }, 'go mod tidy command'); + ({ stdout, stderr } = await exec(`${cmd} ${args}`, { + cwd, + shell: true, + env, + })); + duration = process.hrtime(startTime); + seconds = Math.round(duration[0] + duration[1] / 1e9); + logger.info( + { seconds, type: 'go.sum', stdout, stderr }, + 'Tidied lockfile' + ); + } else { + logger.warn( + 'Renovate administrator should enable gitFs in order to support tidying go modules' + ); + } + } const res = []; // istanbul ignore if if (config.gitFs) { diff --git a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap index e50697a4d8a95998c0156957170801a51dac6287..d5161e4c7305e6220eb3532355bcf3936df12b50 100644 --- a/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap +++ b/test/workers/repository/updates/__snapshots__/flatten.spec.js.snap @@ -27,6 +27,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -124,6 +125,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -219,6 +221,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -318,6 +321,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -413,6 +417,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -512,6 +517,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}}", @@ -609,6 +615,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}} Docker tags", @@ -706,6 +713,7 @@ Array [ "gitAuthor": null, "gitFs": null, "gitPrivateKey": null, + "gomodTidy": false, "group": Object { "branchTopic": "{{{groupSlug}}}", "commitMessageTopic": "{{{groupName}}} Docker tags", diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md index 672988d933737d56bcc8484cb1e22bebb4a047a6..fc6a7bbbd4298fb02f8eba047e5d1d119e71a796 100644 --- a/website/docs/configuration-options.md +++ b/website/docs/configuration-options.md @@ -247,6 +247,8 @@ Configuration added here applies for all Go-related updates, however currently t Configuration for Go Modules (`go mod`). Supersedes anything in the `go` config object. +## gomodTidy + ## gradle Configuration for Java gradle projects