diff --git a/lib/config/definitions.js b/lib/config/definitions.js index c0b89eaf691c849e3414687f69ebd41bd9c11f1c..95c5c90e09410795f90bea92f85f4efa63030bf0 100644 --- a/lib/config/definitions.js +++ b/lib/config/definitions.js @@ -953,7 +953,14 @@ const options = [ stage: 'package', type: 'json', default: { + rollbackPrs: false, fileMatch: ['(^|/)WORKSPACE$'], + major: { + prBodyDefinitions: { + Change: + '{{#if currentDigest}}digest -> `{{{newVersion}}}`{{else}}`{{{currentValue}}}` -> `{{{newValue}}}`{{/if}}', + }, + }, }, mergeable: true, }, diff --git a/lib/manager/bazel/extract.js b/lib/manager/bazel/extract.js index 01c9e88a59a1b33c51a65e09f7f6b38f4d9c6d1e..d0862dda203785985471b9ad7f099ca21eec02ea 100644 --- a/lib/manager/bazel/extract.js +++ b/lib/manager/bazel/extract.js @@ -102,6 +102,7 @@ function extractPackageFile(content) { dep.currentValue = currentValue || commit.substr(0, 7); dep.purl = 'pkg:go/' + importpath; if (commit) { + dep.currentValue = 'v0.0.0'; dep.currentDigest = commit; dep.digestOneAndOnly = true; } diff --git a/lib/manager/bazel/update.js b/lib/manager/bazel/update.js index e272302a83ddb1a47baab747f4993aab834b375b..0d4e2c591fef2dc498fd07db88d6c3b532764877 100644 --- a/lib/manager/bazel/update.js +++ b/lib/manager/bazel/update.js @@ -16,6 +16,12 @@ async function updateDependency(fileContent, upgrade) { newDef = upgrade.def .replace(/tag = "[^"]+"/, `tag = "${upgrade.newValue}"`) .replace(/commit = "[^"]+"/, `commit = "${upgrade.newDigest}"`); + if (upgrade.currentDigest && upgrade.updateType !== 'digest') { + newDef = newDef.replace( + /commit = "[^"]+"/, + `tag = "${upgrade.newValue}"` + ); + } } else if (upgrade.depType === 'http_archive') { const [, shortRepo] = upgrade.repo.split('/'); const newUrl = `https://github.com/${upgrade.repo}/releases/download/${ diff --git a/test/manager/bazel/__snapshots__/extract.spec.js.snap b/test/manager/bazel/__snapshots__/extract.spec.js.snap index b626a5714726f66d847366037b6f534a9ced7e40..e0cf46256c303a9283c33c082d04e73241442106 100644 --- a/test/manager/bazel/__snapshots__/extract.spec.js.snap +++ b/test/manager/bazel/__snapshots__/extract.spec.js.snap @@ -17,7 +17,7 @@ Array [ }, Object { "currentDigest": "dec09d789f3dba190787f8b4454c7d3c936fed9e", - "currentValue": "dec09d7", + "currentValue": "v0.0.0", "def": "go_repository( name = \\"com_github_google_uuid\\", importpath = \\"github.com/google/uuid\\", diff --git a/test/manager/bazel/__snapshots__/update.spec.js.snap b/test/manager/bazel/__snapshots__/update.spec.js.snap new file mode 100644 index 0000000000000000000000000000000000000000..ea2f62c5f935e2f06888a7c662045bf3e4ef1f4b --- /dev/null +++ b/test/manager/bazel/__snapshots__/update.spec.js.snap @@ -0,0 +1,93 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`manager/bazel/update updateDependency updates commit to tag 1`] = ` +" +workspace(name = \\"angular_bazel_example\\") + +go_repository( + name = \\"com_github_bitly_go-nsq\\", + importpath = \\"github.com/bitly/go-nsq\\", + tag = \\"v1.0.5\\" +) + +go_repository( + name = \\"com_github_google_uuid\\", + importpath = \\"github.com/google/uuid\\", + tag = \\"v1.0.3\\" +) + +go_repository( + name = \\"com_gopkgin_mgo_v2\\", + importpath = \\"gopkg.in/mgo.v2\\", + tag = \\"v2\\" +) + +git_repository( + name = \\"build_bazel_rules_nodejs\\", + remote = \\"https://github.com/bazelbuild/rules_nodejs.git\\", + tag = \\"0.3.1\\", +) + +load(\\"@build_bazel_rules_nodejs//:defs.bzl\\", \\"node_repositories\\") +node_repositories(package_json = [\\"//:package.json\\"]) + +git_repository( + name = \\"build_bazel_rules_typescript\\", + remote = \\"https://github.com/bazelbuild/rules_typescript.git\\", + tag = \\"0.6.1\\", +) + +load(\\"@build_bazel_rules_typescript//:defs.bzl\\", \\"ts_repositories\\") + +ts_repositories() + +local_repository( + name = \\"angular\\", + path = \\"node_modules/@angular/bazel\\", +) + +local_repository( + name = \\"rxjs\\", + path = \\"node_modules/rxjs/src\\", +) + +git_repository( + name = \\"io_bazel_rules_sass\\", + remote = \\"https://github.com/bazelbuild/rules_sass.git\\", + tag = \\"0.0.3\\", +) + +load(\\"@io_bazel_rules_sass//sass:sass.bzl\\", \\"sass_repositories\\") + +sass_repositories() + +git_repository( + name = \\"com_github_bazelbuild_buildtools\\", + remote = \\"https://github.com/bazelbuild/buildtools.git\\", + # Note, this commit matches the version of buildifier in angular/ngcontainer + commit = \\"b3b620e8bcff18ed3378cd3f35ebeb7016d71f71\\", +) + +http_archive( + name = \\"io_bazel_rules_go\\", + url = \\"https://github.com/bazelbuild/rules_go/releases/download/0.7.1/rules_go-0.7.1.tar.gz\\", + sha256 = \\"341d5eacef704415386974bc82a1783a8b7ffbff2ab6ba02375e1ca20d9b031c\\", +) + +http_archive( + name = \\"bazel_skylib\\", + sha256 = \\"b5f6abe419da897b7901f90cbab08af958b97a8f3575b0d3dd062ac7ce78541f\\", + strip_prefix = \\"bazel-skylib-0.5.0\\", + urls = [ + \\"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/archive/0.5.0.tar.gz\\", + \\"https://github.com/bazelbuild/bazel-skylib/archive/0.5.0.tar.gz\\", + ], +) + +load(\\"@io_bazel_rules_go//go:def.bzl\\", \\"go_rules_dependencies\\", \\"go_register_toolchains\\") + +go_rules_dependencies() + +go_register_toolchains() +" +`; diff --git a/test/manager/bazel/update.spec.js b/test/manager/bazel/update.spec.js index 85146febd8356265ff603d8782c233d70658326d..114e7bbb9b394b43110b3de567a19dfc8ac5bb8f 100644 --- a/test/manager/bazel/update.spec.js +++ b/test/manager/bazel/update.spec.js @@ -31,6 +31,26 @@ describe('manager/bazel/update', () => { const res = await bazelfile.updateDependency(content, upgrade); expect(res).not.toEqual(content); }); + it('updates commit to tag', async () => { + const upgrade = { + depName: 'com_github_google_uuid', + depType: 'go_repository', + def: `go_repository( + name = "com_github_google_uuid", + importpath = "github.com/google/uuid", + commit = "dec09d789f3dba190787f8b4454c7d3c936fed9e" +) +`, + currentValue: 'v0.0.0', + currentDigest: 'dec09d789f3dba190787f8b4454c7d3c936fed9e', + newValue: 'v1.0.3', + updateType: 'major', + }; + const res = await bazelfile.updateDependency(content, upgrade); + expect(res).toMatchSnapshot(); + expect(res).not.toEqual(content); + expect(res.includes('tag = "v1.0.3"')).toBe(true); + }); it('updates http archive', async () => { const upgrade = { depName: 'io_bazel_rules_go',