Skip to content
Snippets Groups Projects
Unverified Commit 2082aaaf authored by Jason Bedard's avatar Jason Bedard Committed by GitHub
Browse files

fix(bazel): support github tag refs (#17931)

parent c449c85d
No related branches found
No related tags found
No related merge requests found
...@@ -55,6 +55,14 @@ http_archive( ...@@ -55,6 +55,14 @@ http_archive(
], ],
) )
http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = [
"https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"
],
)
local_repository( local_repository(
name = "angular", name = "angular",
path = "node_modules/@angular/bazel", path = "node_modules/@angular/bazel",
......
...@@ -269,6 +269,22 @@ exports[`modules/manager/bazel/extract extractPackageFile() extracts multiple ty ...@@ -269,6 +269,22 @@ exports[`modules/manager/bazel/extract extractPackageFile() extracts multiple ty
}, },
"packageName": "bazelbuild/bazel-toolchains", "packageName": "bazelbuild/bazel-toolchains",
}, },
{
"currentValue": "5.5.3",
"datasource": "github-releases",
"depName": "rules_nodejs",
"depType": "http_archive",
"managerData": {
"def": "http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = [
"https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"
],
)",
},
"packageName": "bazelbuild/rules_nodejs",
},
{ {
"currentValue": "0.0.3", "currentValue": "0.0.3",
"datasource": "github-releases", "datasource": "github-releases",
...@@ -454,3 +470,37 @@ exports[`modules/manager/bazel/extract extractPackageFile() handle comments and ...@@ -454,3 +470,37 @@ exports[`modules/manager/bazel/extract extractPackageFile() handle comments and
}, },
] ]
`; `;
exports[`modules/manager/bazel/extract extractPackageFile() sequential http_archive 1`] = `
[
{
"currentValue": "v1.1.2",
"datasource": "github-tags",
"depName": "aspect_rules_js",
"depType": "http_archive",
"managerData": {
"def": "http_archive(
name = "aspect_rules_js",
sha256 = "db9f446752fe4100320cf8487e8fd476b9af0adf6b99b601bcfd70b289bb0598",
strip_prefix = "rules_js-1.1.2",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.2.tar.gz",
)",
},
"packageName": "aspect-build/rules_js",
},
{
"currentValue": "5.5.3",
"datasource": "github-releases",
"depName": "rules_nodejs",
"depType": "http_archive",
"managerData": {
"def": "http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"],
)",
},
"packageName": "bazelbuild/rules_nodejs",
},
]
`;
...@@ -16,6 +16,7 @@ describe('modules/manager/bazel/common', () => { ...@@ -16,6 +16,7 @@ describe('modules/manager/bazel/common', () => {
expect(parseArchiveUrl('https://example.com/')).toBeNull(); expect(parseArchiveUrl('https://example.com/')).toBeNull();
expect(parseArchiveUrl('https://github.com/foo/bar')).toBeNull(); expect(parseArchiveUrl('https://github.com/foo/bar')).toBeNull();
// Archive of a commit.
expect( expect(
parseArchiveUrl( parseArchiveUrl(
'https://github.com/foo/bar/archive/abcdef0123abcdef0123abcdef0123abcdef0123.tar.gz' 'https://github.com/foo/bar/archive/abcdef0123abcdef0123abcdef0123abcdef0123.tar.gz'
...@@ -26,6 +27,7 @@ describe('modules/manager/bazel/common', () => { ...@@ -26,6 +27,7 @@ describe('modules/manager/bazel/common', () => {
currentValue: 'abcdef0123abcdef0123abcdef0123abcdef0123', currentValue: 'abcdef0123abcdef0123abcdef0123abcdef0123',
}); });
// Archive of a release
expect( expect(
parseArchiveUrl( parseArchiveUrl(
'https://github.com/foo/bar/releases/download/1.2.3/foobar-1.2.3.tar.gz' 'https://github.com/foo/bar/releases/download/1.2.3/foobar-1.2.3.tar.gz'
...@@ -35,6 +37,17 @@ describe('modules/manager/bazel/common', () => { ...@@ -35,6 +37,17 @@ describe('modules/manager/bazel/common', () => {
repo: 'foo/bar', repo: 'foo/bar',
currentValue: '1.2.3', currentValue: '1.2.3',
}); });
// Archive of a tag.
expect(
parseArchiveUrl(
'https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.2.tar.gz'
)
).toEqual({
datasource: 'github-tags',
repo: 'aspect-build/rules_js',
currentValue: 'v1.1.2',
});
}); });
test('gitDependency', () => { test('gitDependency', () => {
...@@ -235,6 +248,24 @@ describe('modules/manager/bazel/common', () => { ...@@ -235,6 +248,24 @@ describe('modules/manager/bazel/common', () => {
depType: 'http_archive', depType: 'http_archive',
packageName: 'foo/bar', packageName: 'foo/bar',
}); });
expect(
httpDependency({
rule: 'http_archive',
name: 'aspect_rules_js',
sha256:
'db9f446752fe4100320cf8487e8fd476b9af0adf6b99b601bcfd70b289bb0598',
urls: [
'https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.2.tar.gz',
],
})
).toEqual({
currentValue: 'v1.1.2',
datasource: 'github-tags',
depName: 'aspect_rules_js',
depType: 'http_archive',
packageName: 'aspect-build/rules_js',
});
}); });
test('dockerDependency', () => { test('dockerDependency', () => {
...@@ -261,26 +292,50 @@ describe('modules/manager/bazel/common', () => { ...@@ -261,26 +292,50 @@ describe('modules/manager/bazel/common', () => {
}); });
}); });
test('extractDepFromTarget', () => { describe('extractDepFromTarget', () => {
expect(extractDepFromTarget({ rule: 'foo', name: 'bar' })).toBeNull(); it('returns null and warns for unknown rule type', () => {
expect(extractDepFromTarget({ rule: 'foo', name: 'bar' })).toBeNull();
expect( expect(logger.logger.warn).toHaveBeenCalledWith(
extractDepFromTarget({ 'Bazel dependency extractor function not found for foo'
rule: 'git_repository', );
name: 'foo_bar', });
tag: '1.2.3',
remote: 'https://github.com/foo/bar', it('extracts from git_repository', () => {
}) expect(
).toEqual({ extractDepFromTarget({
datasource: 'github-releases', rule: 'git_repository',
depType: 'git_repository', name: 'foo_bar',
depName: 'foo_bar', tag: '1.2.3',
packageName: 'foo/bar', remote: 'https://github.com/foo/bar',
currentValue: '1.2.3', })
).toEqual({
datasource: 'github-releases',
depType: 'git_repository',
depName: 'foo_bar',
packageName: 'foo/bar',
currentValue: '1.2.3',
});
}); });
expect(logger.logger.warn).toHaveBeenCalledWith( it('extracts from http_archive', () => {
'Bazel dependency extractor function not found for foo' expect(
); extractDepFromTarget({
rule: 'http_archive',
name: 'rules_nodejs',
sha256:
'5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064',
urls: [
'https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz',
],
})
).toEqual({
datasource: 'github-releases',
depType: 'http_archive',
depName: 'rules_nodejs',
packageName: 'bazelbuild/rules_nodejs',
currentValue: '5.5.3',
});
});
}); });
}); });
...@@ -29,10 +29,19 @@ export function parseArchiveUrl( ...@@ -29,10 +29,19 @@ export function parseArchiveUrl(
if (path[2] === 'releases' && path[3] === 'download') { if (path[2] === 'releases' && path[3] === 'download') {
datasource = GithubReleasesDatasource.id; datasource = GithubReleasesDatasource.id;
currentValue = path[4]; currentValue = path[4];
} } else if (
if (path[2] === 'archive') { path[2] === 'archive' &&
path[3] === 'refs' &&
path[4] === 'tags'
) {
datasource = GithubTagsDatasource.id;
currentValue = path[5];
} else if (path[2] === 'archive') {
datasource = GithubTagsDatasource.id; datasource = GithubTagsDatasource.id;
currentValue = path[3]; currentValue = path[3];
}
if (currentValue) {
// Strip archive extension to get hash or tag. // Strip archive extension to get hash or tag.
// Tolerates formats produced by Git(Hub|Lab) and allowed by http_archive // Tolerates formats produced by Git(Hub|Lab) and allowed by http_archive
// Note: Order matters in suffix list to strip, e.g. .tar.gz. // Note: Order matters in suffix list to strip, e.g. .tar.gz.
...@@ -41,8 +50,7 @@ export function parseArchiveUrl( ...@@ -41,8 +50,7 @@ export function parseArchiveUrl(
currentValue = currentValue.slice(0, -extension.length); currentValue = currentValue.slice(0, -extension.length);
} }
} }
}
if (currentValue) {
return { datasource, repo, currentValue }; return { datasource, repo, currentValue };
} }
return null; return null;
......
...@@ -17,7 +17,7 @@ describe('modules/manager/bazel/extract', () => { ...@@ -17,7 +17,7 @@ describe('modules/manager/bazel/extract', () => {
it('extracts multiple types of dependencies', () => { it('extracts multiple types of dependencies', () => {
const res = extractPackageFile(Fixtures.get('WORKSPACE1')); const res = extractPackageFile(Fixtures.get('WORKSPACE1'));
expect(res?.deps).toHaveLength(17); expect(res?.deps).toHaveLength(18);
expect(res?.deps).toMatchSnapshot(); expect(res?.deps).toMatchSnapshot();
}); });
...@@ -133,5 +133,29 @@ go_repository( ...@@ -133,5 +133,29 @@ go_repository(
); );
expect(gitlabRemote?.deps[0].skipReason).toBe('unsupported-remote'); expect(gitlabRemote?.deps[0].skipReason).toBe('unsupported-remote');
}); });
it('sequential http_archive', () => {
// Sequential http_archive
// See https://github.com/aspect-build/rules_swc/commit/d4989f9dfed781dc0226421fb9373b45052e7bc8
const res = extractPackageFile(
`
http_archive(
name = "aspect_rules_js",
sha256 = "db9f446752fe4100320cf8487e8fd476b9af0adf6b99b601bcfd70b289bb0598",
strip_prefix = "rules_js-1.1.2",
url = "https://github.com/aspect-build/rules_js/archive/refs/tags/v1.1.2.tar.gz",
)
http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz"],
)
`
);
expect(res?.deps).toHaveLength(2);
expect(res?.deps).toMatchSnapshot();
});
}); });
}); });
...@@ -110,4 +110,69 @@ describe('modules/manager/bazel/parser', () => { ...@@ -110,4 +110,69 @@ describe('modules/manager/bazel/parser', () => {
], ],
}); });
}); });
it('parses http_archive', () => {
const input = `http_archive(
name = "rules_nodejs",
sha256 = "5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064",
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz",
)`;
const res = parse(input);
expect(res).toEqual({
meta: [
{ data: { length: 12, offset: 32 }, path: [0, 'name'] },
{ data: { length: 64, offset: 67 }, path: [0, 'sha256'] },
{ data: { length: 97, offset: 151 }, path: [0, 'url'] },
{ data: { length: 256, offset: 0 }, path: [0] },
],
targets: [
{
sha256:
'5aef09ed3279aa01d5c928e3beb248f9ad32dde6aafe6373a8c994c3ce643064',
url: 'https://github.com/bazelbuild/rules_nodejs/releases/download/5.5.3/rules_nodejs-core-5.5.3.tar.gz',
name: 'rules_nodejs',
rule: 'http_archive',
},
],
});
});
it('parses http_archive with prefixes and multiple urls', () => {
const input = `http_archive(
name = "bazel_toolchains",
sha256 = "4b1468b254a572dbe134cc1fd7c6eab1618a72acd339749ea343bd8f55c3b7eb",
strip_prefix = "bazel-toolchains-d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4.tar.gz",
"https://github.com/bazelbuild/bazel-toolchains/archive/d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4.tar.gz",
],
)`;
const res = parse(input);
expect(res).toEqual({
meta: [
{ data: { length: 16, offset: 30 }, path: [0, 'name'] },
{ data: { length: 64, offset: 67 }, path: [0, 'sha256'] },
{ data: { length: 57, offset: 158 }, path: [0, 'strip_prefix'] },
{ data: { length: 121, offset: 248 }, path: [0, 'urls', 0] },
{ data: { length: 102, offset: 385 }, path: [0, 'urls', 1] },
{ data: { length: 506, offset: 0 }, path: [0] },
],
targets: [
{
sha256:
'4b1468b254a572dbe134cc1fd7c6eab1618a72acd339749ea343bd8f55c3b7eb',
urls: [
'https://mirror.bazel.build/github.com/bazelbuild/bazel-toolchains/archive/d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4.tar.gz',
'https://github.com/bazelbuild/bazel-toolchains/archive/d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4.tar.gz',
],
strip_prefix:
'bazel-toolchains-d665ccfa3e9c90fa789671bf4ef5f7c19c5715c4',
name: 'bazel_toolchains',
rule: 'http_archive',
},
],
});
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment