Skip to content
Snippets Groups Projects
Unverified Commit 1af05b72 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

feat(bazel): Support GitLab-based http archives (#20393)

parent fb7197ac
No related branches found
No related tags found
No related merge requests found
...@@ -163,5 +163,51 @@ describe('modules/manager/bazel/extract', () => { ...@@ -163,5 +163,51 @@ describe('modules/manager/bazel/extract', () => {
expect(res?.deps).toHaveLength(2); expect(res?.deps).toHaveLength(2);
expect(res?.deps).toMatchSnapshot(); expect(res?.deps).toMatchSnapshot();
}); });
it('http_archive with GitLab url', () => {
// Sequential http_archive
// See https://github.com/aspect-build/rules_swc/commit/d4989f9dfed781dc0226421fb9373b45052e7bc8
const res = extractPackageFile(
codeBlock`
http_archive(
name = "eigen3",
url = "https://gitlab.com/libeigen/eigen/-/archive/3.3.5/eigen-3.3.5.zip",
strip_prefix = "eigen-3.3.5",
sha256 = "0e7aeece6c8874146c2a4addc437eebdf1ec4026680270f00e76705c8186f0b5",
build_file = "@//third_party:eigen3.BUILD",
)
http_archive(
name = "eigen",
build_file = "//third_party:eigen.BUILD",
sha256 = "d76992f1972e4ff270221c7ee8125610a8e02bb46708a7295ee646e99287083b", # SHARED_EIGEN_SHA
strip_prefix = "eigen-90ee821c563fa20db4d64d6991ddca256d5c52f2",
urls = [
"https://storage.googleapis.com/mirror.tensorflow.org/gitlab.com/libeigen/eigen/-/archive/90ee821c563fa20db4d64d6991ddca256d5c52f2/eigen-90ee821c563fa20db4d64d6991ddca256d5c52f2.tar.gz",
"https://gitlab.com/foo/bar",
"https://gitlab.com/libeigen/eigen/-/archive/90ee821c563fa20db4d64d6991ddca256d5c52f2/eigen-90ee821c563fa20db4d64d6991ddca256d5c52f2.tar.gz",
],
)
`
);
expect(res?.deps).toHaveLength(2);
expect(res?.deps).toMatchObject([
{
currentValue: '3.3.5',
datasource: 'gitlab-releases',
depName: 'eigen3',
depType: 'http_archive',
packageName: 'libeigen/eigen',
},
{
currentDigest: '90ee821c563fa20db4d64d6991ddca256d5c52f2',
datasource: 'gitlab-tags',
depName: 'eigen',
depType: 'http_archive',
packageName: 'libeigen/eigen',
},
]);
});
}); });
}); });
...@@ -4,6 +4,8 @@ import { escapeRegExp, regEx } from '../../../../util/regex'; ...@@ -4,6 +4,8 @@ import { escapeRegExp, regEx } from '../../../../util/regex';
import { parseUrl } from '../../../../util/url'; import { parseUrl } from '../../../../util/url';
import { GithubReleasesDatasource } from '../../../datasource/github-releases'; import { GithubReleasesDatasource } from '../../../datasource/github-releases';
import { GithubTagsDatasource } from '../../../datasource/github-tags'; import { GithubTagsDatasource } from '../../../datasource/github-tags';
import { GitlabReleasesDatasource } from '../../../datasource/gitlab-releases';
import { GitlabTagsDatasource } from '../../../datasource/gitlab-tags';
import type { PackageDependency } from '../../types'; import type { PackageDependency } from '../../types';
// Source: https://bazel.build/rules/lib/repo/http // Source: https://bazel.build/rules/lib/repo/http
...@@ -76,6 +78,27 @@ export function parseGithubPath( ...@@ -76,6 +78,27 @@ export function parseGithubPath(
: { datasource, packageName, currentValue: value }; : { datasource, packageName, currentValue: value };
} }
function parseGitlabPath(pathname: string): Partial<PackageDependency> | null {
// https://gitlab.com/libeigen/eigen/-/archive/3.3.5/eigen-3.3.5.zip
// https://gitlab.com/libeigen/eigen/-/archive/90ee821c563fa20db4d64d6991ddca256d5c52f2/eigen-90ee821c563fa20db4d64d6991ddca256d5c52f2.tar.gz
const [p0, p1, p2, p3, p4] = pathname.split('/').slice(1);
const packageName = p0 + '/' + p1;
if (p2 === '-' && p3 === 'archive' && p4) {
return isHash(p4)
? {
datasource: GitlabTagsDatasource.id,
packageName,
currentDigest: p4,
}
: {
datasource: GitlabReleasesDatasource.id,
packageName,
currentValue: p4,
};
}
return null;
}
export function parseArchiveUrl( export function parseArchiveUrl(
urlString: string | undefined | null urlString: string | undefined | null
): Partial<PackageDependency> | null { ): Partial<PackageDependency> | null {
...@@ -89,6 +112,10 @@ export function parseArchiveUrl( ...@@ -89,6 +112,10 @@ export function parseArchiveUrl(
return parseGithubPath(url.pathname); return parseGithubPath(url.pathname);
} }
if (url?.host === 'gitlab.com') {
return parseGitlabPath(url.pathname);
}
return null; return null;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment