Module: Homebrew::Livecheck Private

Extended by:
Output, Packages, Throttle, Utils::Output::Mixin
Defined in:
livecheck/livecheck.rb,
livecheck/error.rb,
livecheck/output.rb,
livecheck/options.rb,
livecheck/packages.rb,
livecheck/progress.rb,
livecheck/strategy.rb,
livecheck/throttle.rb,
livecheck/constants.rb,
livecheck/strategic.rb,
livecheck/strategy/git.rb,
livecheck/strategy/gnu.rb,
livecheck/strategy/npm.rb,
livecheck/strategy/xml.rb,
livecheck/strategy/cpan.rb,
livecheck/strategy/json.rb,
livecheck/strategy/pypi.rb,
livecheck/strategy/xorg.rb,
livecheck/strategy/yaml.rb,
livecheck/strategy/crate.rb,
livecheck/strategy/gnome.rb,
livecheck/skip_conditions.rb,
livecheck/strategy/apache.rb,
livecheck/strategy/hackage.rb,
livecheck/strategy/sparkle.rb,
livecheck/livecheck_version.rb,
livecheck/strategy/bitbucket.rb,
livecheck/strategy/launchpad.rb,
livecheck/strategy/ruby_gems.rb,
livecheck/strategy/page_match.rb,
livecheck/strategy/sourceforge.rb,
livecheck/strategy/header_match.rb,
livecheck/strategy/extract_plist.rb,
livecheck/strategy/github_latest.rb,
livecheck/strategy/github_releases.rb,
livecheck/strategy/electron_builder.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

The Livecheck module consists of methods used by the brew livecheck command. These methods print the requested livecheck information for formulae.

Defined Under Namespace

Modules: Constants, Output, Packages, SkipConditions, Strategic, Strategy, Throttle Classes: Error, LivecheckVersion, Options, Progress

Constant Summary collapse

NO_CURRENT_VERSION_MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"Unable to identify current version"
NO_VERSIONS_MSG =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"Unable to get versions"
GitHubReleases =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

Homebrew::Livecheck::Strategy::GithubReleases

Class Method Summary collapse

Methods included from Utils::Output::Mixin

issue_reporting_message, odebug, odeprecated, odie, odisabled, ofail, oh1, oh1_title, ohai, ohai_title, onoe, opoo, opoo_once, opoo_outside_github_actions, opoo_without_github_actions_annotation, pretty_cannot_install, pretty_deprecated, pretty_disabled, pretty_duration, pretty_incompatible, pretty_install_status, pretty_installed, pretty_removed, pretty_uninstalled, pretty_unmarked, pretty_upgradable, pretty_warning

Methods included from Packages

checkable_urls, current_version, livecheck_url_to_string, load_other_tap_strategies, package_or_resource_name, resolve_livecheck_reference, use_homebrew_curl?

Methods included from Output

report_error, status_hash, url_metadata

Methods included from Throttle

formula_or_cask_last_updated_timestamp, throttle_allows_bump?, throttle_interval_elapsed?, throttled_version

Class Method Details

.latest_version(formula_or_cask, referenced_formula_or_cask: nil, livecheck_references: [], json: false, full_name: false, verbose: false, debug: false) ⇒ Hash{Symbol => T.untyped}?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Identifies the latest version of the formula/cask and returns a Hash containing the version information. Returns nil if a latest version couldn't be found.

Parameters:

  • formula_or_cask (Formula, Cask::Cask)
  • referenced_formula_or_cask (Formula, Cask::Cask, nil) (defaults to: nil)
  • livecheck_references (Array<Formula, Cask::Cask>) (defaults to: [])
  • json (Boolean) (defaults to: false)
  • full_name (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)
  • debug (Boolean) (defaults to: false)

Returns:



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'livecheck/livecheck.rb', line 275

def self.latest_version(
  formula_or_cask,
  referenced_formula_or_cask: nil,
  livecheck_references: [],
  json: false, full_name: false, verbose: false, debug: false
)
  formula = formula_or_cask if formula_or_cask.is_a?(Formula)
  cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask)

  livecheck_defined = formula_or_cask.livecheck_defined?
  livecheck = formula_or_cask.livecheck
  referenced_livecheck = referenced_formula_or_cask&.livecheck

  livecheck_options = referenced_livecheck&.options&.merge(livecheck.options) || livecheck.options.deep_dup
  livecheck_url_options = livecheck_options.url_options.compact
  livecheck_url = livecheck.url || referenced_livecheck&.url
  livecheck_regex = livecheck.regex || referenced_livecheck&.regex
  livecheck_strategy = livecheck.strategy || referenced_livecheck&.strategy
  livecheck_strategy_block = livecheck.strategy_block || referenced_livecheck&.strategy_block
  livecheck_throttle = livecheck.throttle || referenced_livecheck&.throttle
  livecheck_throttle_days = livecheck.throttle_days || referenced_livecheck&.throttle_days

  referenced_package = referenced_formula_or_cask || formula_or_cask

  livecheck_url_string = livecheck_url_to_string(livecheck_url, referenced_package) if livecheck_url

  urls = [livecheck_url_string] if livecheck_url_string
  urls ||= checkable_urls(referenced_package)

  if debug
    if formula
      puts "Formula:          #{formula_name(formula, full_name:)}"
      puts "Head only?:       true" if formula.head_only?
    elsif cask
      puts "Cask:             #{cask_name(formula_or_cask, full_name:)}"
    end
    defined_label = livecheck_defined ? "Yes" : "No"
    puts "livecheck block?: #{defined_label}"
    if livecheck_throttle || livecheck_throttle_days
      throttle_items = []
      if livecheck_throttle
        throttle_items << "#{livecheck_throttle} #{Utils.pluralize("version", livecheck_throttle)}"
      end
      if livecheck_throttle_days
        throttle_items << "#{livecheck_throttle_days} #{Utils.pluralize("day", livecheck_throttle_days)}"
      end
      puts "Throttle:         #{throttle_items.join(" or ")}"
    end

    livecheck_references.each do |ref_formula_or_cask|
      reference_label = ref_formula_or_cask.is_a?(Formula) ? "Formula Ref:      " : "Cask Ref:         "
      puts "#{reference_label}#{package_or_resource_name(ref_formula_or_cask, full_name:)}"
    end
  end

  checked_urls = []
  urls.each_with_index do |original_url, i|
    url = original_url
    next if checked_urls.include?(url)

    strategies = Strategy.from_url(
      url,
      livecheck_strategy:,
      regex_provided:     livecheck_regex.present?,
      block_provided:     livecheck_strategy_block.present?,
    )
    strategy = Strategy.from_symbol(livecheck_strategy) || strategies.first
    next unless strategy

    strategy_name = livecheck_strategy_names(strategy)

    if strategy.respond_to?(:preprocess_url)
      url = strategy.preprocess_url(url)
      next if checked_urls.include?(url)
    end

    if debug
      print_strategy_info(original_url:, url:, url_spec: livecheck_url, url_options: livecheck_url_options,
                          strategies:, strategy:, regex: livecheck_regex, verbose:)
    end

    if livecheck_strategy.present?
      if livecheck_url.blank? && strategy.method(:find_versions).parameters.include?([:keyreq, :url])
        odebug "#{strategy_name} strategy requires a URL"
        next
      elsif livecheck_strategy != :page_match && strategies.exclude?(strategy)
        odebug "#{strategy_name} strategy does not apply to this URL"
        next
      end
    end

    if (livecheck_homebrew_curl = livecheck_options.homebrew_curl).nil?
      case strategy_name
      when "PageMatch", "HeaderMatch"
        if (homebrew_curl = use_homebrew_curl?(referenced_package, url))
          livecheck_options.homebrew_curl = homebrew_curl
          livecheck_homebrew_curl = homebrew_curl
        end
      end
    end
    if debug && !livecheck_homebrew_curl.nil?
      curl_label = livecheck_homebrew_curl ? "Yes" : "No"
      puts "Homebrew curl?:   #{curl_label}"
    end

    # Only use arguments that the strategy's `#find_versions` method
    # supports
    strategy_data = strategy.find_versions(
      **{ cask:, url:, regex: livecheck_regex, options: livecheck_options }
        .slice(*livecheck_find_versions_parameters(strategy))
        .compact,
      &livecheck_strategy_block
    )
    match_version_map = strategy_data[:matches]
    regex = strategy_data[:regex]
    messages = strategy_data[:messages]
    checked_urls << url

    if messages.is_a?(Array) && match_version_map.blank?
      puts messages unless json
      next if i + 1 < urls.length

      return status_hash(formula_or_cask, "error", messages, full_name:, verbose:)
    end

    if debug
      print_strategy_result(url:, regex: livecheck_regex, strategy_url: strategy_data[:url],
                            final_url: strategy_data[:final_url], strategy_regex: strategy_data[:regex],
                            cached: strategy_data[:cached])
    end

    filter_unstable_versions!(match_version_map, livecheck_defined:)
    next if match_version_map.blank?

    print_matches(match_version_map, verbose:) if debug

    version_info = {
      latest: Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(formula_or_cask, v) }),
    }

    if livecheck_throttle || livecheck_throttle_days
      version_info[:latest_throttled] = throttled_version(
        formula_or_cask, match_version_map, version_info[:latest],
        throttle_rate: livecheck_throttle, throttle_days: livecheck_throttle_days, debug:, verbose:
      )
    end

    if json && verbose
      version_info[:meta] = {}

      if livecheck_references.present?
        version_info[:meta][:references] = livecheck_references.map do |ref_formula_or_cask|
          case ref_formula_or_cask
          when Formula
            { formula: formula_name(ref_formula_or_cask, full_name:) }
          when Cask::Cask
            { cask: cask_name(ref_formula_or_cask, full_name:) }
          else
            T.absurd(ref_formula_or_cask) # simplecov:disable
          end
        end
      end

      if url != "None"
        version_info[:meta][:url] = (
          original_url:, url:, url_symbol: (livecheck_url if livecheck_url.is_a?(Symbol) && livecheck_url_string),
          strategy_url: strategy_data[:url], final_url: strategy_data[:final_url],
          url_options: livecheck_url_options
        )
      end
      version_info[:meta][:strategy] = strategy_name if strategy.present?
      version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names(s) } if strategies.present?
      version_info[:meta][:regex] = regex.inspect if regex.present?
      version_info[:meta][:cached] = true if strategy_data[:cached] == true
      version_info[:meta][:throttle] = livecheck_throttle if livecheck_throttle
      version_info[:meta][:throttle_days] = livecheck_throttle_days if livecheck_throttle_days

      if strategy_data[:content] && %w[Crate Pypi].include?(strategy_name)
        version_info[:content] = strategy_data[:content]
      end
    end

    return version_info
  end
  nil
end

.livecheck_find_versions_parameters(strategy_class) ⇒ Array<Symbol>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



51
52
53
54
55
56
# File 'livecheck/livecheck.rb', line 51

def self.livecheck_find_versions_parameters(strategy_class)
  @livecheck_find_versions_parameters ||= T.let({}, T.nilable(T::Hash[T::Class[Strategic], T::Array[Symbol]]))
  @livecheck_find_versions_parameters[strategy_class] ||=
    (T::Utils.signature_for_method(strategy_class.method(:find_versions))&.parameters ||
     strategy_class.method(:find_versions).parameters).map(&:second)
end

.livecheck_strategy_names(strategy_class) ⇒ String

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

Returns:



45
46
47
48
# File 'livecheck/livecheck.rb', line 45

def self.livecheck_strategy_names(strategy_class)
  @livecheck_strategy_names ||= T.let({}, T.nilable(T::Hash[T::Class[Strategic], String]))
  @livecheck_strategy_names[strategy_class] ||= Utils.demodulize(strategy_class.name)
end

.resource_version(resource, formula_latest, json: false, full_name: false, debug: false, quiet: false, verbose: false) ⇒ Hash{Symbol => T.untyped}

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Identifies the latest version of a resource and returns a Hash containing the version information. Returns nil if a latest version couldn't be found.

Parameters:

  • resource (Resource)
  • formula_latest (String)
  • json (Boolean) (defaults to: false)
  • full_name (Boolean) (defaults to: false)
  • debug (Boolean) (defaults to: false)
  • quiet (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)

Returns:



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# File 'livecheck/livecheck.rb', line 486

def self.resource_version(
  resource,
  formula_latest,
  json: false,
  full_name: false,
  debug: false,
  quiet: false,
  verbose: false
)
  livecheck_defined = resource.livecheck_defined?

  if debug
    puts "\n\n"
    puts "Resource:         #{resource.name}"
    defined_label = livecheck_defined ? "Yes" : "No"
    puts "livecheck block?: #{defined_label}"
  end

  resource_version_info = {}

  livecheck = resource.livecheck
  livecheck_options = livecheck.options.deep_dup
  livecheck_url_options = livecheck_options.url_options.compact
  livecheck_reference = livecheck.formula
  livecheck_url = livecheck.url
  livecheck_regex = livecheck.regex
  livecheck_strategy = livecheck.strategy
  livecheck_strategy_block = livecheck.strategy_block

  livecheck_url_string = livecheck_url_to_string(livecheck_url, resource) if livecheck_url

  urls = [livecheck_url_string] if livecheck_url_string
  urls = ["None"] if livecheck_reference == :parent
  urls ||= checkable_urls(resource)

  checked_urls = []
  urls.each_with_index do |original_url, i|
    url = original_url.gsub(Constants::LATEST_VERSION, formula_latest)
    next if checked_urls.include?(url)

    strategies = Strategy.from_url(
      url,
      livecheck_strategy:,
      regex_provided:     livecheck_regex.present?,
      block_provided:     livecheck_strategy_block.present?,
    )
    strategy = Strategy.from_symbol(livecheck_strategy) || strategies.first
    next if strategy.blank? && livecheck_reference != :parent

    strategy_name = livecheck_strategy_names(strategy) if strategy.present?

    if strategy.respond_to?(:preprocess_url)
      url = strategy.preprocess_url(url)
      next if checked_urls.include?(url)
    end

    if debug
      print_strategy_info(original_url:, url:, url_spec: livecheck_url, url_options: livecheck_url_options,
                          strategies:, strategy:, regex: livecheck_regex, verbose:)
      if livecheck_reference == :parent
        resource_owner = resource.owner
        raise "Resource owner is nil" if resource_owner.nil?

        formula = if full_name
          T.cast(resource_owner, ::Formula).full_name
        else
          resource_owner.name
        end
        puts "Formula Ref:      #{formula} (parent)"
      end
    end

    if livecheck_strategy.present?
      if livecheck_url.blank? && strategy.method(:find_versions).parameters.include?([:keyreq, :url])
        odebug "#{strategy_name} strategy requires a URL"
        next
      elsif livecheck_strategy != :page_match && strategies.exclude?(strategy)
        odebug "#{strategy_name} strategy does not apply to this URL"
        next
      end
    end
    puts if debug && strategy.blank? && livecheck_reference != :parent
    next if strategy.blank? && livecheck_reference != :parent

    puts "Homebrew curl?:   Yes" if debug && livecheck_options.homebrew_curl

    if livecheck_reference == :parent
      match_version_map = { formula_latest => Version.new(formula_latest) }
      cached = true
    else
      # Only use arguments that the strategy's `#find_versions` method
      # supports
      strategy_data = strategy.find_versions(
        **{ url:, regex: livecheck_regex, options: livecheck_options }
          .slice(*livecheck_find_versions_parameters(strategy))
          .compact,
        &livecheck_strategy_block
      )
      match_version_map = strategy_data[:matches]
      regex = strategy_data[:regex]
      messages = strategy_data[:messages]
      cached = strategy_data[:cached]
    end

    checked_urls << url

    if messages.is_a?(Array) && match_version_map.blank?
      puts messages unless json
      next if i + 1 < urls.length

      return status_hash(resource, "error", messages, verbose:)
    end

    if debug
      print_strategy_result(url:, regex: livecheck_regex, strategy_url: strategy_data&.dig(:url),
                            final_url: strategy_data&.dig(:final_url), strategy_regex: strategy_data&.dig(:regex),
                            cached:)
    end

    filter_unstable_versions!(match_version_map, livecheck_defined:)
    next if match_version_map.blank?

    print_matches(match_version_map, verbose:) if debug

    res_current = current_version(resource)
    return status_hash(resource, "error", [NO_CURRENT_VERSION_MSG], verbose:) if res_current.nil?

    res_latest = Version.new(match_version_map.values.max_by { |v| LivecheckVersion.create(resource, v) })

    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

    resource_version_info = {
      resource: resource.name,
      version:  {
        current:             res_current.to_s,
        latest:              res_latest.to_s,
        outdated:            is_outdated,
        newer_than_upstream: is_newer_than_upstream,
      },
    }

    resource_version_info[:meta] = {
      livecheck_defined: livecheck_defined,
    }
    if livecheck_reference == :parent
      resource_owner = resource.owner
      raise "Resource owner is nil" if resource_owner.nil?

      formula = if full_name
        T.cast(resource_owner, ::Formula).full_name
      else
        resource_owner.name
      end
      resource_version_info[:meta][:references] =
        [{ formula:, symbol: :parent }]
    end
    if url != "None"
      resource_version_info[:meta][:url] = (
        original_url:, url:, url_symbol: (livecheck_url if livecheck_url.is_a?(Symbol) && livecheck_url_string),
        strategy_url: strategy_data&.dig(:url), final_url: strategy_data&.dig(:final_url),
        url_options: livecheck_url_options
      )
    end
    resource_version_info[:meta][:strategy] = strategy_name if strategy.present?
    if strategies.present?
      resource_version_info[:meta][:strategies] = strategies.map { |s| livecheck_strategy_names(s) }
    end
    resource_version_info[:meta][:regex] = regex.inspect if regex.present?
    resource_version_info[:meta][:cached] = true if cached == true
  rescue => e
    Homebrew.failed = true
    report_error(resource, e, json:, quiet: quiet && !json, debug:, verbose:)
  end
  resource_version_info
end

.run_checks(formulae_and_casks_to_check, full_name: false, handle_name_conflict: false, check_resources: false, json: false, newer_only: false, extract_plist: false, debug: false, quiet: false, verbose: false) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Executes the livecheck logic for each formula/cask in the formulae_and_casks_to_check array and prints the results.

Parameters:

  • formulae_and_casks_to_check (Array<Formula, Cask::Cask>)
  • full_name (Boolean) (defaults to: false)
  • handle_name_conflict (Boolean) (defaults to: false)
  • check_resources (Boolean) (defaults to: false)
  • json (Boolean) (defaults to: false)
  • newer_only (Boolean) (defaults to: false)
  • extract_plist (Boolean) (defaults to: false)
  • debug (Boolean) (defaults to: false)
  • quiet (Boolean) (defaults to: false)
  • verbose (Boolean) (defaults to: false)


74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'livecheck/livecheck.rb', line 74

def self.run_checks(
  formulae_and_casks_to_check,
  full_name: false, handle_name_conflict: false, check_resources: false, json: false, newer_only: false,
  extract_plist: false, debug: false, quiet: false, verbose: false
)
  load_other_tap_strategies(formulae_and_casks_to_check)

  ambiguous_casks = if handle_name_conflict
    ambiguous_packages(formulae_and_casks_to_check, full_name: true).grep(Cask::Cask)
  else
    []
  end
  ambiguous_names = if full_name
    []
  else
    ambiguous_packages(formulae_and_casks_to_check - ambiguous_casks)
  end

  has_a_newer_upstream_version = T.let(false, T::Boolean)

  formulae_and_casks_total = formulae_and_casks_to_check.count
  progress = Progress.new(total: formulae_and_casks_total, enabled: json && !quiet && $stderr.tty?)

  # Allow ExtractPlist strategy if only one formula/cask is being checked.
  extract_plist = true if formulae_and_casks_total == 1

  formulae_checked = formulae_and_casks_to_check.map.with_index do |formula_or_cask, i|
    formula = formula_or_cask if formula_or_cask.is_a?(Formula)
    cask = formula_or_cask if formula_or_cask.is_a?(Cask::Cask)
    head = formula&.head
    head&.downloader&.quiet!

    use_full_name = full_name || ambiguous_names.include?(formula_or_cask)
    name = package_or_resource_name(formula_or_cask, full_name: use_full_name)

    referenced_formula_or_cask, livecheck_references =
      resolve_livecheck_reference(formula_or_cask, full_name: use_full_name, debug:)

    puts(i.positive? ? "\n----------\n\n" : "") if debug

    # Check skip conditions for a referenced formula/cask
    if referenced_formula_or_cask
      skip_info = SkipConditions.referenced_skip_information(
        referenced_formula_or_cask,
        name,
        full_name:     use_full_name,
        verbose:,
        extract_plist:,
      )
    end

    skip_info ||= SkipConditions.skip_information(
      formula_or_cask,
      full_name:     use_full_name,
      verbose:,
      extract_plist:,
    )
    if skip_info.present?
      next skip_info if json && !newer_only

      SkipConditions.print_skip_information(skip_info) if !newer_only && !quiet
      next
    end

    # Use the `stable` version for comparison except for installed
    # HEAD-only formulae. A formula with `stable` and `head` that's
    # installed using `--head` will still use the `stable` version for
    # comparison.
    current = current_version(formula_or_cask)
    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:)
    end

    current_str = current.to_s
    current = LivecheckVersion.create(formula_or_cask, current)

    latest = if formula&.head_only? && head
      Version.new(head.downloader.fetch_last_commit)
    else
      version_info = latest_version(
        formula_or_cask,
        referenced_formula_or_cask:,
        livecheck_references:,
        json:, full_name: use_full_name, verbose:, debug:
      )
      version_info[:latest] if version_info.present?
    end

    check_for_resources = check_resources && formula_or_cask.is_a?(Formula) && formula_or_cask.resources.present?
    if check_for_resources
      resource_version_info = formula_or_cask.resources.map do |resource|
        res_skip_info ||= SkipConditions.skip_information(resource, verbose:)
        next res_skip_info if res_skip_info.present?

        res_version_info = resource_version(
          resource,
          latest.to_s,
          json:,
          full_name: use_full_name,
          debug:,
          quiet:,
          verbose:,
        )
        res_version_info.presence || status_hash(resource, "error", [NO_VERSIONS_MSG], verbose:)
      end.compact_blank
      Homebrew.failed = true if resource_version_info.any? { |info| info[:status] == "error" }
      resource_version_info.each { |info| info.delete(:meta) } if json && !verbose
    end

    if latest.blank?
      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,
                                                                             verbose:)
      latest_info[:resources] = resource_version_info if check_for_resources

      next latest_info
    end

    if (m = latest.to_s.match(/(.*)-release$/)) && !current.to_s.match(/.*-release$/)
      latest = Version.new(m[1])
    end

    latest_str = latest.to_s
    latest = LivecheckVersion.create(formula_or_cask, latest)

    info = {}
    info[:formula] = name if formula
    info[:cask] = name if cask
    # HEAD-only formulae compare commit hashes rather than ordered versions.
    outdated = if formula&.head_only?
      current != latest
    else
      current < latest
    end
    info[:version] = {
      current:             current_str,
      latest:              latest_str,
      latest_throttled:    version_info&.dig(:latest_throttled),
      outdated:,
      newer_than_upstream: (formula&.stable? || cask) && (current > latest),
    }.compact
    info[:meta] = {
      livecheck_defined: formula_or_cask.livecheck_defined?,
    }
    info[:meta][:head_only] = true if formula&.head_only?
    info[:meta].merge!(version_info[:meta]) if version_info.present? && version_info.key?(:meta)

    info[:resources] = resource_version_info if check_for_resources

    next if newer_only && !info[:version][:outdated]

    has_a_newer_upstream_version = true

    if json
      progress.increment
      info.delete(:meta) unless verbose
      next info
    end
    puts if debug
    print_latest_version(info, verbose:, ambiguous_cask: ambiguous_casks.include?(formula_or_cask))
    print_resources_info(resource_version_info, verbose:) if check_for_resources
    nil
  rescue => e
    Homebrew.failed = true
    progress.increment if json
    report_error(formula_or_cask, e, json:, quiet:, debug:, verbose:,
                 full_name: full_name || ambiguous_names.include?(formula_or_cask),
                 ambiguous_cask: ambiguous_casks.include?(formula_or_cask)).tap do
      print_resources_info(resource_version_info, verbose:) if !json && !quiet && check_for_resources
    end
  end

  puts "No newer upstream versions." if newer_only && !has_a_newer_upstream_version && !debug && !json && !quiet

  return unless json

  progress.finish

  puts JSON.pretty_generate(formulae_checked.compact)
end