diff --git a/lib/manager/bazel/update.js b/lib/manager/bazel/update.js index 0d4e2c591fef2dc498fd07db88d6c3b532764877..d730bcc9061103710eb15fde61ddf8e13a360079 100644 --- a/lib/manager/bazel/update.js +++ b/lib/manager/bazel/update.js @@ -24,10 +24,22 @@ async function updateDependency(fileContent, upgrade) { } } else if (upgrade.depType === 'http_archive') { const [, shortRepo] = upgrade.repo.split('/'); - const newUrl = `https://github.com/${upgrade.repo}/releases/download/${ - upgrade.newValue - }/${shortRepo}-${upgrade.newValue}.tar.gz`; - const file = (await got(newUrl, { encoding: null })).body; + let newUrl; + let file; + try { + newUrl = `https://github.com/${upgrade.repo}/releases/download/${ + upgrade.newValue + }/${shortRepo}-${upgrade.newValue}.tar.gz`; + file = (await got(newUrl, { encoding: null })).body; + } catch (err) { + logger.debug( + 'Failed to download release download - trying archive instead' + ); + newUrl = `https://github.com/${upgrade.repo}/archive/${ + upgrade.newValue + }.tar.gz`; + file = (await got(newUrl, { encoding: null })).body; + } const hash = crypto .createHash('sha256') .update(file) diff --git a/test/manager/bazel/update.spec.js b/test/manager/bazel/update.spec.js index 114e7bbb9b394b43110b3de567a19dfc8ac5bb8f..07d2bc0312ce0ddfb110598bb455d07322438e2d 100644 --- a/test/manager/bazel/update.spec.js +++ b/test/manager/bazel/update.spec.js @@ -65,6 +65,21 @@ describe('manager/bazel/update', () => { expect(res).not.toEqual(content); expect(res.indexOf('0.8.1')).not.toBe(-1); }); + it('updates second time http archive', async () => { + const upgrade = { + depName: 'io_bazel_rules_go', + depType: 'http_archive', + repo: 'bazelbuild/rules_go', + def: `http_archive(\n name = "io_bazel_rules_go",\n url = "https://github.com/bazelbuild/rules_go/releases/download/0.7.1/rules_go-0.7.1.tar.gz",\n sha256 = "341d5eacef704415386974bc82a1783a8b7ffbff2ab6ba02375e1ca20d9b031c",\n)`, + currentValue: '0.7.1', + newValue: '0.8.1', + }; + got.mockReturnValueOnce(null); + got.mockReturnValueOnce({ body: '' }); + const res = await bazelfile.updateDependency(content, upgrade); + expect(res).not.toEqual(content); + expect(res.indexOf('0.8.1')).not.toBe(-1); + }); it('updates http urls array', async () => { const upgrade = { depName: 'bazel_skylib',