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

cask: audit for minimal OS version in sparkle feeds #14060

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 32 additions & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,38 @@ def check_livecheck_version
false
end

def check_livecheck_min_os
return unless online?
return unless cask.livecheckable?
return unless cask.livecheck.strategy == :sparkle

out, _, status = curl_output(cask.livecheck.url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
out, _, status = curl_output(cask.livecheck.url)
out, _, status = curl_output("--fail", "--silent", "--location", cask.livecheck.url)

So that it will detect non-200 codes, follow redirects etc.

return unless status.success?

require "rexml/document"

xml = begin
REXML::Document.new(out)
rescue REXML::ParseException
nil
end

return if xml.blank?

item = xml.get_elements("//rss//channel//item").first
Copy link
Member

@Bo98 Bo98 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
item = xml.get_elements("//rss//channel//item").first
item = xml.elements["//rss//channel//item"]

Just for consistent code style with below. elements[...] should be the same as get_elements(...).first.

Doesn't really matter though.

return if item.blank?

min_os = item.elements["sparkle:minimumSystemVersion"].text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_os = item.elements["sparkle:minimumSystemVersion"].text
min_os = item.elements["sparkle:minimumSystemVersion"]&.text

If there's no minimum version, then this will be nil.

return if min_os.blank?

min_os_string = OS::Mac::Version.new(min_os).strip_patch
Copy link
Member

@Bo98 Bo98 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
min_os_string = OS::Mac::Version.new(min_os).strip_patch
begin
min_os_string = OS::Mac::Version.new(min_os).strip_patch
rescue MacOSVersionError
return
end

In case the source returns an invalid macOS version, or one we don't support (e.g. Yosemite and earlier).

cask_min_os = cask.depends_on.macos.version

return if cask_min_os == min_os_string

add_error "Upstream defined #{min_os_string} as minimal OS version and the cask defined #{cask_min_os}"
end

sig { void }
def check_appcast_contains_version
return unless appcast?
Expand Down