Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livecheck: refactor HEAD-only formula handling #19338

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def container(**kwargs)
#
# @see DSL::Version
# @api public
sig { params(arg: T.nilable(T.any(String, Symbol))).returns(T.nilable(DSL::Version)) }
def version(arg = nil)
set_unique_stanza(:version, arg.nil?) do
if !arg.is_a?(String) && arg != :latest
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ def any_installed_prefix

# Returns the {PkgVersion} for this formula if it is installed.
# If not, return `nil`.
sig { returns(T.nilable(PkgVersion)) }
def any_installed_version
any_installed_keg&.version
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ def elisp_installed?
(path/"share/emacs/site-lisp"/name).children.any? { |f| ELISP_EXTENSIONS.include? f.extname }
end

sig { returns(PkgVersion) }
def version
require "pkg_version"
PkgVersion.parse(path.basename.to_s)
Expand Down
25 changes: 17 additions & 8 deletions Library/Homebrew/livecheck/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# command. These methods print the requested livecheck information
# for formulae.
module Livecheck
NO_CURRENT_VERSION_MSG = "Unable to identify current version"
NO_VERSIONS_MSG = "Unable to get versions"

UNSTABLE_VERSION_KEYWORDS = T.let(%w[
alpha
beta
Expand Down Expand Up @@ -249,13 +252,20 @@
# comparison.
current = if formula
if formula.head_only?
Version.new(formula.any_installed_version.version.commit)
else
T.must(formula.stable).version
formula_commit = formula.any_installed_version&.version&.commit
Version.new(formula_commit) if formula_commit
elsif (stable = formula.stable)
stable.version
end
else
Version.new(formula_or_cask.version)
end
unless current
raise Livecheck::Error, NO_CURRENT_VERSION_MSG unless json
next if quiet

next status_hash(formula_or_cask, "error", [NO_CURRENT_VERSION_MSG], full_name: use_full_name, verbose:)

Check warning on line 267 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L267

Added line #L267 was not covered by tests
end

current_str = current.to_s
current = LivecheckVersion.create(formula_or_cask, current)
Expand Down Expand Up @@ -289,7 +299,7 @@
verbose:,
)
if res_version_info.empty?
status_hash(resource, "error", ["Unable to get versions"], verbose:)
status_hash(resource, "error", [NO_VERSIONS_MSG], verbose:)
else
res_version_info
end
Expand All @@ -299,13 +309,12 @@
end

if latest.blank?
no_versions_msg = "Unable to get versions"
raise Livecheck::Error, no_versions_msg unless json
raise Livecheck::Error, NO_VERSIONS_MSG unless json
next if quiet

next version_info if version_info.is_a?(Hash) && version_info[:status] && version_info[:messages]

latest_info = status_hash(formula_or_cask, "error", [no_versions_msg], full_name: use_full_name,
latest_info = status_hash(formula_or_cask, "error", [NO_VERSIONS_MSG], full_name: use_full_name,

Check warning on line 317 in Library/Homebrew/livecheck/livecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/livecheck/livecheck.rb#L317

Added line #L317 was not covered by tests
verbose:)
if check_for_resources
unless verbose
Expand Down Expand Up @@ -986,7 +995,7 @@
res_current = T.must(resource.version)
res_latest = Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(resource, v) })

return status_hash(resource, "error", ["Unable to get versions"], verbose:) if res_latest.blank?
return status_hash(resource, "error", [NO_VERSIONS_MSG], verbose:) if res_latest.blank?

is_outdated = res_current < res_latest
is_newer_than_upstream = res_current > res_latest
Expand Down
Loading