Skip to content

Commit

Permalink
formula_auditor: split audit_revision_and_version_scheme.
Browse files Browse the repository at this point in the history
Separate this into two methods so we can have separate skips for each.
  • Loading branch information
MikeMcQuaid committed Jan 12, 2024
1 parent dca9ff8 commit 724e14e
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
32 changes: 21 additions & 11 deletions Library/Homebrew/formula_auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ def audit_stable_version
end
end

def audit_revision_and_version_scheme
def audit_revision
new_formula_problem("New formulae should not define a revision.") if @new_formula && !formula.revision.zero?

return unless @git
Expand All @@ -806,20 +806,10 @@ def audit_revision_and_version_scheme
return if formula.stable.blank?

current_version = formula.stable.version
current_version_scheme = formula.version_scheme
current_revision = formula.revision

previous_committed, newest_committed = committed_version_info

unless previous_committed[:version_scheme].nil?
if current_version_scheme < previous_committed[:version_scheme]
problem "version_scheme should not decrease (from #{previous_committed[:version_scheme]} " \
"to #{current_version_scheme})"
elsif current_version_scheme > (previous_committed[:version_scheme] + 1)
problem "version_schemes should only increment by 1"
end
end

if (previous_committed[:version] != newest_committed[:version] ||
current_version != newest_committed[:version]) &&
!current_revision.zero? &&
Expand All @@ -836,6 +826,26 @@ def audit_revision_and_version_scheme
end
end

def audit_version_scheme
return unless @git
return unless formula.tap # skip formula not from core or any taps
return unless formula.tap.git? # git log is required
return if formula.stable.blank?

current_version_scheme = formula.version_scheme

previous_committed, = committed_version_info

return if previous_committed[:version_scheme].nil?

if current_version_scheme < previous_committed[:version_scheme]
problem "version_scheme should not decrease (from #{previous_committed[:version_scheme]} " \
"to #{current_version_scheme})"
elsif current_version_scheme > (previous_committed[:version_scheme] + 1)
problem "version_schemes should only increment by 1"
end
end

def audit_unconfirmed_checksum_change
return unless @git
return unless formula.tap # skip formula not from core or any taps
Expand Down
38 changes: 35 additions & 3 deletions Library/Homebrew/test/dev-cmd/audit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -961,10 +961,10 @@ class Foo#{foo_version} < Formula
end
end

describe "#audit_revision_and_version_scheme" do
describe "#audit_revision" do
subject do
fa = described_class.new(Formulary.factory(formula_path), git: true)
fa.audit_revision_and_version_scheme
fa.audit_revision
fa.problems.first&.fetch(:message)
end

Expand Down Expand Up @@ -1001,7 +1001,7 @@ class Foo < Formula
end
RUBY

fa.audit_revision_and_version_scheme
fa.audit_revision

expect(fa.new_formula_problems).to include(
a_hash_including(message: a_string_matching(/should not define a revision/)),
Expand Down Expand Up @@ -1083,6 +1083,38 @@ class Foo < Formula
it { is_expected.to be_nil }
end
end
end

describe "#audit_version_scheme" do
subject do
fa = described_class.new(Formulary.factory(formula_path), git: true)
fa.audit_version_scheme
fa.problems.first&.fetch(:message)
end

before do
origin_formula_path.dirname.mkpath
origin_formula_path.write <<~RUBY
class Foo#{foo_version} < Formula
url "https://brew.sh/foo-1.0.tar.gz"
sha256 "31cccfc6630528db1c8e3a06f6decf2a370060b982841cfab2b8677400a5092e"
revision 2
version_scheme 1
end
RUBY

origin_tap_path.mkpath
origin_tap_path.cd do
system "git", "init"
system "git", "add", "--all"
system "git", "commit", "-m", "init"
end

tap_path.mkpath
tap_path.cd do
system "git", "clone", origin_tap_path, "."
end
end

describe "version_schemes" do
describe "should not decrease with the same version" do
Expand Down

0 comments on commit 724e14e

Please sign in to comment.