Skip to content

Commit b0b5c89

Browse files
authored
Merge pull request #23338 from Homebrew/fix-version-detection
Fix GitHub release version detection
2 parents 60cc972 + bae7b04 commit b0b5c89

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

Library/Homebrew/formula_auditor.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,10 +997,11 @@ def audit_stable_version
997997
current_version_scheme = formula.version_scheme
998998

999999
previous_version_info, base_ref_version_info = committed_version_info
1000+
return unless (base_ref_version = base_ref_version_info[:version])
10001001

1001-
if (base_ref_version = base_ref_version_info[:version]) &&
1002-
current_version < base_ref_version &&
1003-
current_version_scheme == previous_version_info[:version_scheme]
1002+
if current_version == base_ref_version && current_version.to_s != base_ref_version.to_s
1003+
problem "Stable: version should not change from #{base_ref_version} to #{current_version}"
1004+
elsif current_version < base_ref_version && current_version_scheme == previous_version_info[:version_scheme]
10041005
problem "Stable: version should not decrease (from #{base_ref_version} to #{current_version})"
10051006
end
10061007
end

Library/Homebrew/test/formula_auditor_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,12 @@ class Foo#{foo_version} < Formula
14271427
end
14281428

14291429
describe "versions" do
1430+
context "when uncommitted should not change formatting" do
1431+
before { formula_gsub "foo-1.0.tar.gz", "foo-1.0.0.tar.gz" }
1432+
1433+
it { is_expected.to match("Stable: version should not change from 1.0 to 1.0.0") }
1434+
end
1435+
14301436
context "when uncommitted should not decrease" do
14311437
before { formula_gsub "foo-1.0.tar.gz", "foo-0.9.tar.gz" }
14321438

Library/Homebrew/test/version_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,12 @@
691691
.to be_detected_from("https://wwwlehre.dhbw-stuttgart.de/~sschulz/WORK/E_DOWNLOAD/V_1.9/E.tgz")
692692
end
693693

694+
specify "GitHub release tag takes precedence over asset filename" do
695+
url = "https://github.com/dvorka-oss/hstr/releases/download/v3.2/hstr-3.2.0-tarball.tgz"
696+
697+
expect(described_class.detect(url).to_s).to eq("3.2")
698+
end
699+
694700
specify "w.x.y.z url-only version style" do
695701
expect(described_class.new("2.3.2.0"))
696702
.to be_detected_from("https://github.com/JustArchi/ArchiSteamFarm/releases/download/2.3.2.0/ASF.zip")

Library/Homebrew/version.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ def self.parse(spec, detected_from_url: false)
388388
# e.g. `https://github.com/petdance/ack/tarball/1.93_02`
389389
UrlParser.new(%r{github\.com/.+/(?:zip|tar)ball/(?:v|\w+-)?((?:\d+[._-])+\d*)$}),
390390

391+
# GitHub releases
392+
# e.g. `https://github.com/foo/bar/releases/download/v1.2/foo-1.2.0.tar.gz`
393+
UrlParser.new(%r{github\.com/.+/releases/download/(?:[rvV]_?)?(#{NUMERIC_WITH_DOTS})/}),
394+
391395
# e.g. `https://github.com/erlang/otp/tarball/OTP_R15B01 (erlang style)`
392396
UrlParser.new(/[_-]([Rr]\d+[AaBb]\d*(?:-\d+)?)/),
393397

0 commit comments

Comments
 (0)