Skip to content
Snippets Groups Projects
Unverified Commit 1cf50e90 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix(bazel): use github-tags for http archives (#7861)

Closes #7852
parent 00dea833
No related branches found
No related tags found
No related merge requests found
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "GBDeviceInfo",
url = "https://github.com/lmirosevic/GBDeviceInfo/archive/6.3.0.tar.gz",
sha256 = "d7666275dff039407ea467c3083b83e24934101777c8b55b6b1b3b7e9a9e220b",
strip_prefix = "GBDeviceInfo-6.3.0/GBDeviceInfo"
)
http_archive(
name = "com_github_nelhage_rules_boost",
url = "https://github.com/nelhage/rules_boost/archive/135d46b4c9423ee7d494c78a21ff621bc73c12f3.tar.gz",
sha256 = "3651f5dda0f7296e4cecafacc7f9d1f274be0fd64e30bebd74e28ffba28fe77f",
strip_prefix = "rules_boost-135d46b4c9423ee7d494c78a21ff621bc73c12f3",
)
load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()
...@@ -31,7 +31,7 @@ exports[`lib/manager/bazel/extract extractPackageFile() extracts dependencies fr ...@@ -31,7 +31,7 @@ exports[`lib/manager/bazel/extract extractPackageFile() extracts dependencies fr
Array [ Array [
Object { Object {
"currentDigest": "0356bef3fbbabec5f0e196ecfacdeb6db62d48c0", "currentDigest": "0356bef3fbbabec5f0e196ecfacdeb6db62d48c0",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "subpar", "depName": "subpar",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "google/subpar", "lookupName": "google/subpar",
...@@ -48,7 +48,7 @@ Array [ ...@@ -48,7 +48,7 @@ Array [
}, },
Object { Object {
"currentValue": "0.6.0", "currentValue": "0.6.0",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "bazel_skylib", "depName": "bazel_skylib",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "bazelbuild/bazel-skylib", "lookupName": "bazelbuild/bazel-skylib",
...@@ -65,6 +65,43 @@ Array [ ...@@ -65,6 +65,43 @@ Array [
] ]
`; `;
exports[`lib/manager/bazel/extract extractPackageFile() extracts github tags 1`] = `
Array [
Object {
"currentValue": "6.3.0",
"datasource": "github-tags",
"depName": "GBDeviceInfo",
"depType": "http_archive",
"lookupName": "lmirosevic/GBDeviceInfo",
"managerData": Object {
"def": "http_archive(
name = \\"GBDeviceInfo\\",
url = \\"https://github.com/lmirosevic/GBDeviceInfo/archive/6.3.0.tar.gz\\",
sha256 = \\"d7666275dff039407ea467c3083b83e24934101777c8b55b6b1b3b7e9a9e220b\\",
strip_prefix = \\"GBDeviceInfo-6.3.0/GBDeviceInfo\\"
)",
},
"repo": "lmirosevic/GBDeviceInfo",
},
Object {
"currentDigest": "135d46b4c9423ee7d494c78a21ff621bc73c12f3",
"datasource": "github-tags",
"depName": "com_github_nelhage_rules_boost",
"depType": "http_archive",
"lookupName": "nelhage/rules_boost",
"managerData": Object {
"def": "http_archive(
name = \\"com_github_nelhage_rules_boost\\",
url = \\"https://github.com/nelhage/rules_boost/archive/135d46b4c9423ee7d494c78a21ff621bc73c12f3.tar.gz\\",
sha256 = \\"3651f5dda0f7296e4cecafacc7f9d1f274be0fd64e30bebd74e28ffba28fe77f\\",
strip_prefix = \\"rules_boost-135d46b4c9423ee7d494c78a21ff621bc73c12f3\\",
)",
},
"repo": "nelhage/rules_boost",
},
]
`;
exports[`lib/manager/bazel/extract extractPackageFile() extracts multiple types of dependencies 1`] = ` exports[`lib/manager/bazel/extract extractPackageFile() extracts multiple types of dependencies 1`] = `
Array [ Array [
Object { Object {
...@@ -90,7 +127,7 @@ Array [ ...@@ -90,7 +127,7 @@ Array [
}, },
Object { Object {
"currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8", "currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "distroless", "depName": "distroless",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "GoogleContainerTools/distroless", "lookupName": "GoogleContainerTools/distroless",
...@@ -106,7 +143,7 @@ Array [ ...@@ -106,7 +143,7 @@ Array [
}, },
Object { Object {
"currentDigest": "d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4", "currentDigest": "d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "bazel_toolchains", "depName": "bazel_toolchains",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "bazelbuild/bazel-toolchains", "lookupName": "bazelbuild/bazel-toolchains",
...@@ -140,7 +177,7 @@ Array [ ...@@ -140,7 +177,7 @@ Array [
}, },
Object { Object {
"currentValue": "0.5.0", "currentValue": "0.5.0",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "bazel_skylib", "depName": "bazel_skylib",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "bazelbuild/bazel-skylib", "lookupName": "bazelbuild/bazel-skylib",
...@@ -159,7 +196,7 @@ Array [ ...@@ -159,7 +196,7 @@ Array [
}, },
Object { Object {
"currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8", "currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "distroless", "depName": "distroless",
"depType": "http_archive", "depType": "http_archive",
"lookupName": "GoogleContainerTools/distroless", "lookupName": "GoogleContainerTools/distroless",
...@@ -175,7 +212,7 @@ Array [ ...@@ -175,7 +212,7 @@ Array [
}, },
Object { Object {
"currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8", "currentDigest": "446923c3756ceeaa75888f52fcbdd48bb314fbf8",
"datasource": "github-releases", "datasource": "github-tags",
"depName": "distroless", "depName": "distroless",
"depType": "http_file", "depType": "http_file",
"lookupName": "GoogleContainerTools/distroless", "lookupName": "GoogleContainerTools/distroless",
......
...@@ -6,6 +6,11 @@ const workspaceFile = readFileSync( ...@@ -6,6 +6,11 @@ const workspaceFile = readFileSync(
'utf8' 'utf8'
); );
const workspace2File = readFileSync(
'lib/manager/bazel/__fixtures__/WORKSPACE2',
'utf8'
);
const fileWithBzlExtension = readFileSync( const fileWithBzlExtension = readFileSync(
'lib/manager/bazel/__fixtures__/repositories.bzl', 'lib/manager/bazel/__fixtures__/repositories.bzl',
'utf8' 'utf8'
...@@ -25,6 +30,10 @@ describe('lib/manager/bazel/extract', () => { ...@@ -25,6 +30,10 @@ describe('lib/manager/bazel/extract', () => {
const res = extractPackageFile(workspaceFile); const res = extractPackageFile(workspaceFile);
expect(res.deps).toMatchSnapshot(); expect(res.deps).toMatchSnapshot();
}); });
it('extracts github tags', () => {
const res = extractPackageFile(workspace2File);
expect(res.deps).toMatchSnapshot();
});
it('extracts dependencies from *.bzl files', () => { it('extracts dependencies from *.bzl files', () => {
const res = extractPackageFile(fileWithBzlExtension); const res = extractPackageFile(fileWithBzlExtension);
expect(res.deps).toMatchSnapshot(); expect(res.deps).toMatchSnapshot();
......
...@@ -3,6 +3,7 @@ import { parse as _parse } from 'url'; ...@@ -3,6 +3,7 @@ import { parse as _parse } from 'url';
import parse from 'github-url-from-git'; import parse from 'github-url-from-git';
import * as datasourceDocker from '../../datasource/docker'; import * as datasourceDocker from '../../datasource/docker';
import * as datasourceGithubReleases from '../../datasource/github-releases'; import * as datasourceGithubReleases from '../../datasource/github-releases';
import * as datasourceGithubTags from '../../datasource/github-tags';
import * as datasourceGo from '../../datasource/go'; import * as datasourceGo from '../../datasource/go';
import { logger } from '../../logger'; import { logger } from '../../logger';
import { SkipReason } from '../../types'; import { SkipReason } from '../../types';
...@@ -11,6 +12,7 @@ import * as dockerVersioning from '../../versioning/docker'; ...@@ -11,6 +12,7 @@ import * as dockerVersioning from '../../versioning/docker';
import { PackageDependency, PackageFile } from '../common'; import { PackageDependency, PackageFile } from '../common';
interface UrlParsedResult { interface UrlParsedResult {
datasource: string;
repo: string; repo: string;
currentValue: string; currentValue: string;
} }
...@@ -26,15 +28,18 @@ function parseUrl(urlString: string): UrlParsedResult | null { ...@@ -26,15 +28,18 @@ function parseUrl(urlString: string): UrlParsedResult | null {
} }
const path = url.path.split('/').slice(1); const path = url.path.split('/').slice(1);
const repo = path[0] + '/' + path[1]; const repo = path[0] + '/' + path[1];
let datasource: string;
let currentValue: string = null; let currentValue: string = null;
if (path[2] === 'releases' && path[3] === 'download') { if (path[2] === 'releases' && path[3] === 'download') {
datasource = datasourceGithubReleases.id;
currentValue = path[4]; currentValue = path[4];
} }
if (path[2] === 'archive') { if (path[2] === 'archive') {
datasource = datasourceGithubTags.id;
currentValue = path[3].replace(/\.tar\.gz$/, ''); currentValue = path[3].replace(/\.tar\.gz$/, '');
} }
if (currentValue) { if (currentValue) {
return { repo, currentValue }; return { datasource, repo, currentValue };
} }
// istanbul ignore next // istanbul ignore next
return null; return null;
...@@ -232,7 +237,7 @@ export function extractPackageFile( ...@@ -232,7 +237,7 @@ export function extractPackageFile(
} else { } else {
dep.currentValue = parsedUrl.currentValue; dep.currentValue = parsedUrl.currentValue;
} }
dep.datasource = datasourceGithubReleases.id; dep.datasource = parsedUrl.datasource;
dep.lookupName = dep.repo; dep.lookupName = dep.repo;
deps.push(dep); deps.push(dep);
} else if ( } else if (
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment