Skip to content

Commit

Permalink
fix(homebrew): handle new github archive url format (#29138)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikaro committed May 20, 2024
1 parent 5b88dd6 commit e035f05
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 33 deletions.
6 changes: 3 additions & 3 deletions lib/modules/manager/homebrew/__fixtures__/ibazel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
# limitations under the License.

=begin
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
=end
# url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
# url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
# sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'

$sha256 = '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4';
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"

# To generate run:
# curl https://codeload.github.com/bazelbuild/bazel-watcher/tar.gz/v0.8.2 | sha256sum
Expand Down
24 changes: 21 additions & 3 deletions lib/modules/manager/homebrew/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exports[`modules/manager/homebrew/extract extractPackageFile() extracts "archive
"ownerName": "bazelbuild",
"repoName": "bazel-watcher",
"sha256": "26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz",
},
},
],
Expand All @@ -37,6 +37,24 @@ exports[`modules/manager/homebrew/extract extractPackageFile() extracts "release
`;

exports[`modules/manager/homebrew/extract extractPackageFile() handles no space before class header 1`] = `
{
"deps": [
{
"currentValue": "v0.8.2",
"datasource": "github-tags",
"depName": "bazelbuild/bazel-watcher",
"managerData": {
"ownerName": "bazelbuild",
"repoName": "bazel-watcher",
"sha256": "26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz",
},
},
],
}
`;

exports[`modules/manager/homebrew/extract extractPackageFile() handles old "archive" github url format 1`] = `
{
"deps": [
{
Expand Down Expand Up @@ -122,7 +140,7 @@ exports[`modules/manager/homebrew/extract extractPackageFile() skips if sha256 f
"ownerName": "bazelbuild",
"repoName": "bazel-watcher",
"sha256": "26f5125218fad2741d3caf937b0229",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz",
},
"skipReason": "invalid-sha256",
},
Expand All @@ -141,7 +159,7 @@ exports[`modules/manager/homebrew/extract extractPackageFile() skips if there is
"ownerName": "bazelbuild",
"repoName": "bazel-watcher",
"sha256": null,
"url": "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz",
"url": "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz",
},
"skipReason": "invalid-sha256",
},
Expand Down
55 changes: 53 additions & 2 deletions lib/modules/manager/homebrew/__snapshots__/update.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ exports[`modules/manager/homebrew/update updates "archive" github dependency 1`]
# limitations under the License.
=begin
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
=end
# url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
# url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
# sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
$sha256 = '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4';
Expand Down Expand Up @@ -114,6 +114,57 @@ end
"
`;
exports[`modules/manager/homebrew/update updates "archive" github dependency from old url format 1`] = `
"# Copyright 2018 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
=begin
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
=end
# url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
# sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
$sha256 = '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4';
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
# To generate run:
# curl https://codeload.github.com/bazelbuild/bazel-watcher/tar.gz/v0.8.2 | sha256sum
sha256 '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
bottle :unneeded
depends_on "bazelbuild/tap/bazel" => :build
def install
system 'bazel', 'build', '--config=release', '--verbose_failures', '--experimental_platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64', '//ibazel:ibazel'
bin.install 'bazel-bin/ibazel/darwin_amd64_pure_stripped/ibazel' => 'ibazel'
end
test do
# Since ibazel loops in most cases the quickest check of valididty
# I can think of is to get the version output which happens when
# invoked without any arguments.
system bin / 'ibazel'
end
end
"
`;
exports[`modules/manager/homebrew/update updates "releases" github dependency 1`] = `
"=begin
url "https://github.com/aide/aide/releases/download/v0.16.1/aide-0.16.1.tar.gz"
Expand Down
28 changes: 21 additions & 7 deletions lib/modules/manager/homebrew/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('modules/manager/homebrew/extract', () => {
expect(res).toMatchSnapshot();
});

it('handles no space before class header', () => {
it('handles old "archive" github url format', () => {
const content = `class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
Expand All @@ -58,12 +58,26 @@ describe('modules/manager/homebrew/extract', () => {
expect(res).toMatchSnapshot();
});

it('handles no space before class header', () => {
const content = `class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
const res = extractPackageFile(content);
expect(res).not.toBeNull();
expect(res?.deps[0].skipReason).toBeUndefined();
expect(res).toMatchSnapshot();
});

it('returns null for invalid class header 1', () => {
const content = `
class Ibazel !?# Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
Expand All @@ -75,7 +89,7 @@ describe('modules/manager/homebrew/extract', () => {
class Ibazel < NotFormula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
Expand All @@ -87,7 +101,7 @@ describe('modules/manager/homebrew/extract', () => {
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
not_url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
not_url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
Expand All @@ -102,7 +116,7 @@ describe('modules/manager/homebrew/extract', () => {
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url ??https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url ??https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
Expand Down Expand Up @@ -132,7 +146,7 @@ describe('modules/manager/homebrew/extract', () => {
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
not_sha256 '26f5125218fad2741d3caf937b02296d803900e5f153f5b1f733f15391b9f9b4'
end
`;
Expand All @@ -147,7 +161,7 @@ describe('modules/manager/homebrew/extract', () => {
class Ibazel < Formula
desc 'IBazel is a tool for building Bazel targets when source files change.'
homepage 'https://github.com/bazelbuild/bazel-watcher'
url "https://github.com/bazelbuild/bazel-watcher/archive/v0.8.2.tar.gz"
url "https://github.com/bazelbuild/bazel-watcher/archive/refs/tags/v0.8.2.tar.gz"
sha256 '26f5125218fad2741d3caf937b0229'
end
`;
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/manager/homebrew/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ export function parseUrlPath(
const repoName = s[1];
let currentValue: string | undefined;
if (s[2] === 'archive') {
// old archive url in form: [...]/archive/<tag>.tar.gz
currentValue = s[3];
if (currentValue === 'refs') {
// new archive url in form: [...]/archive/refs/tags/<tag>.tar.gz
currentValue = s[5];
}
const targz = currentValue.slice(
currentValue.length - 7,
currentValue.length,
Expand Down

0 comments on commit e035f05

Please sign in to comment.