Class: Homebrew::DevCmd::Bump Private

Inherits:
AbstractCommand show all
Defined in:
dev-cmd/bump.rb,
sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi

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

Defined Under Namespace

Classes: Args, ResourceVersionInfo, VersionBumpInfo

Constant Summary collapse

DEFAULT_CURL_ARGS =

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.

[
  "--compressed",
  "--fail-with-body",
  "--location",
  "--max-redirs",
  "5",
  "--silent",
].freeze
DEFAULT_CURL_OPTIONS =

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.

T.let({
  connect_timeout: 15,
  max_time:        55,
  timeout:         60,
  retries:         0,
}.freeze, T::Hash[Symbol, T.untyped])
PYPI_UNSTABLE_VERSION_REGEX =

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.

/^(?:\d+!)?\d+(?:\.\d+)*(?:a|b|rc)\d+|\.dev\d+$/i
LIVECHECK_MESSAGE_REGEX =

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.

/^(?:error:|skipped|unable to get(?: throttled)? versions)/i
NEWER_THAN_UPSTREAM_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.

" (newer than upstream)"

Instance Method Summary collapse

Methods inherited from AbstractCommand

command, command_name, dev_cmd?, #initialize, parser, ruby_cmd?

Methods included from Utils::Output::Mixin

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

Constructor Details

This class inherits a constructor from Homebrew::AbstractCommand

Instance Method Details

#argsHomebrew::DevCmd::Bump::Args

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.



10
# File 'sorbet/rbi/dsl/homebrew/dev_cmd/bump.rbi', line 10

def args; end

#compare_versions(current_version, new_version, formula_or_cask) ⇒ Hash{Symbol => Hash{Symbol => Boolean}}

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:



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
664
665
666
667
668
669
670
671
672
# File 'dev-cmd/bump.rb', line 607

def compare_versions(current_version, new_version, formula_or_cask)
  current_versions = {}
  new_versions = {}
  BumpVersionParser::VERSION_SYMBOLS.each do |type|
    current_version_value = current_version.send(type)
    if current_version_value
      current_versions[type] = Livecheck::LivecheckVersion.create(formula_or_cask, current_version_value)
    end

    new_version_value = new_version.send(type)
    if message?(new_version_value)
      # Store a string, so we can easily tell when a value is a message
      # rather than a version
      new_versions[type] = new_version_value.to_s
    elsif new_version_value
      new_versions[type] = Livecheck::LivecheckVersion.create(formula_or_cask, new_version_value)
    end
  end

  multiple_versions = {
    current: current_versions.length > 1,
    new:     new_versions.length > 1,
  }

  current_version_types = current_versions.keys
  new_version_types = new_versions.keys
  comparison_pairs = {}

  # Compare the same version types when shared by current/new versions
  (current_version_types & new_version_types).each do |type|
    comparison_pairs[type] = [current_versions[type], new_versions[type]]
  end

  # Compare current versions to `new_version.general` when the current
  # version differs by arch but the new version does not
  if multiple_versions[:current] && new_versions.key?(:general)
    (current_version_types - new_version_types).each do |type|
      comparison_pairs[type] ||= [current_versions[type], new_versions[:general]]
    end
  end

  # Compare `current_version.general` to the highest new version when the
  # current version does not differ by arch but the new version does
  if !comparison_pairs.key?(:general) &&
     current_versions.key?(:general) &&
     multiple_versions[:new]
    highest_new_version = (new_version_types - current_version_types).filter_map do |type|
      version = new_versions[type]
      next unless version.is_a?(Livecheck::LivecheckVersion)

      version
    end.max
    comparison_pairs[:general] = [current_versions[:general], highest_new_version]
  end

  newer_than_upstream = {}
  comparison_pairs.each do |version_type, (current_value, new_value)|
    newer_than_upstream[version_type] = if new_value.is_a?(Livecheck::LivecheckVersion)
      (current_value > new_value)
    else
      false
    end
  end

  { multiple_versions:, newer_than_upstream: }
end

#message?(value) ⇒ Boolean

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:

  • (Boolean)


675
676
677
678
679
# File 'dev-cmd/bump.rb', line 675

def message?(value)
  return false if !value.is_a?(Cask::DSL::Version) && !value.is_a?(String)

  value.match?(LIVECHECK_MESSAGE_REGEX)
end

#retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, ambiguous_cask: 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.

Parameters:



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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
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
# File 'dev-cmd/bump.rb', line 402

def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, ambiguous_cask: false)
  version_info = retrieve_versions_by_arch(formula_or_cask:,
                                           repositories:,
                                           name:)

  deprecated = version_info.deprecated
  multiple_versions = version_info.multiple_versions
  current_version = version_info.current_version
  new_version = version_info.new_version
  repology_latest = version_info.repology_latest
  newer_than_upstream = version_info.newer_than_upstream
  duplicate_pull_requests = version_info.duplicate_pull_requests
  maybe_duplicate_pull_requests = version_info.maybe_duplicate_pull_requests

  versions_equal = (new_version == current_version)
  all_newer_than_upstream = newer_than_upstream.all? { |_k, v| v == true }

  title_name = ambiguous_cask ? "#{name} (cask)" : name
  title = if (repology_latest == current_version.general || !repology_latest.is_a?(Version)) && versions_equal
    "#{title_name} #{Tty.green}is up to date!#{Tty.reset}"
  else
    title_name
  end

  # Conditionally format output based on type of formula_or_cask
  current_versions = if multiple_versions[:current]
    "arm:   #{current_version.arm || current_version.general}" \
      "#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:arm]}" \
      "#{" (deprecated)" if deprecated[:arm]}" \
      "\n                          " \
      "intel: #{current_version.intel || current_version.general}" \
      "#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:intel]}" \
      "#{" (deprecated)" if deprecated[:intel]}"
  else
    "#{current_version.general}" \
      "#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:general]}" \
      "#{" (deprecated)" if deprecated[:general]}"
  end

  new_versions = if multiple_versions[:new] && new_version.arm && new_version.intel
    "arm:   #{new_version.arm}
                    intel: #{new_version.intel}"
  else
    new_version.general
  end

  throttled = formula_or_cask.livecheck.throttle || formula_or_cask.livecheck.throttle_days
  ohai title
  puts <<~EOS
    Current #{version_info.version_name}  #{current_versions}
    Latest livecheck version: #{new_versions}#{" (throttled)" if throttled}
  EOS
  puts <<~EOS unless skip_repology?(formula_or_cask)
    Latest Repology version:  #{repology_latest}
  EOS
  if formula_or_cask.is_a?(Formula) && formula_or_cask.synced_with_other_formulae?
    outdated_synced_formulae = synced_with(formula_or_cask, new_version.general)
    if !args.bump_synced? && outdated_synced_formulae.present?
      puts <<~EOS
        Version syncing:          #{title_name} version should be kept in sync with
                                  #{outdated_synced_formulae.join(", ")}.
      EOS
    end
  end

  # Display resource version info for formulae
  resource_versions = version_info.resource_versions
  puts "Resources with livecheck:" unless resource_versions.empty?
  resource_versions.each do |rv|
    status = if rv.latest_version.nil?
      "#{Tty.red}unable to get versions#{Tty.reset}"
    elsif rv.newer_than_upstream
      "#{Tty.red}#{rv.current_version}#{Tty.reset} -> #{rv.latest_version}#{NEWER_THAN_UPSTREAM_MSG}"
    elsif rv.outdated
      "#{rv.current_version} -> #{Tty.green}#{rv.latest_version}#{Tty.reset}"
    else
      "#{rv.current_version} -> #{rv.latest_version}"
    end
    puts "  #{rv.name}: #{status}"
  end

  if !args.no_pull_requests? &&
     !message?(new_version.general) &&
     !versions_equal &&
     !all_newer_than_upstream
    if duplicate_pull_requests
      duplicate_pull_requests_text = duplicate_pull_requests
    elsif maybe_duplicate_pull_requests
      duplicate_pull_requests_text = "none"
      maybe_duplicate_pull_requests_text = maybe_duplicate_pull_requests
    else
      duplicate_pull_requests_text = "none"
      maybe_duplicate_pull_requests_text = "none"
    end

    puts "Duplicate pull requests:  #{duplicate_pull_requests_text}"
    if maybe_duplicate_pull_requests_text
      puts "Maybe duplicate pull requests: #{maybe_duplicate_pull_requests_text}"
    end
  end

  if !args.open_pr? ||
     message?(new_version.general) ||
     all_newer_than_upstream
    return
  end

  if GitHub.too_many_open_prs?(formula_or_cask.tap)
    odie "You have too many PRs open: close or merge some first!"
  end

  if repology_latest.is_a?(Version) &&
     repology_latest > current_version.general &&
     repology_latest > new_version.general &&
     formula_or_cask.livecheck_defined?
    puts "#{title_name} was not bumped to the Repology version because it has a `livecheck` block."
  end
  if new_version.blank? || versions_equal ||
     (!new_version.general.is_a?(Version) && !multiple_versions[:new])
    return
  end

  return if duplicate_pull_requests.present?

  version_args = version_args_for_bump(current_version:, new_version:, multiple_versions:, name:)
  return if version_args.blank?

  bump_pr_args = [
    "bump-#{version_info.type}-pr",
    name,
    *version_args,
    "--no-browse",
    "--message=Created by `brew bump`",
  ]

  bump_pr_args << "--no-fork" if args.no_fork?

  if args.bump_synced? && outdated_synced_formulae.present?
    bump_pr_args << "--bump-synced=#{outdated_synced_formulae.join(",")}"
  end

  # Pass all livecheck-checked resources to bump-formula-pr, including
  # up-to-date and failed ones, so it can track what was checked
  if version_info.type == :formula && !resource_versions.empty?
    require "json"
    resource_data = resource_versions.map do |rv|
      { name: rv.name, current_version: rv.current_version, latest_version: rv.latest_version }
    end
    bump_pr_args << "--resource-versions=#{resource_data.to_json}"
  end

  result = system HOMEBREW_BREW_FILE, *bump_pr_args
  Homebrew.failed = true unless result
end

#retrieve_versions_by_arch(formula_or_cask:, repositories:, name:) ⇒ VersionBumpInfo

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:



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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
# File 'dev-cmd/bump.rb', line 222

def retrieve_versions_by_arch(formula_or_cask:, repositories:, name:)
  is_cask_with_blocks = formula_or_cask.is_a?(Cask::Cask) && formula_or_cask.on_system_blocks_exist?
  type, version_name = if formula_or_cask.is_a?(Formula)
    [:formula, "formula version:"]
  else
    [:cask, "cask version:   "]
  end

  deprecated = {}
  current_versions = {}
  new_versions = {}

  repology_latest = repositories.present? ? Repology.latest_version(repositories) : "not found"
  repology_latest_is_a_version = repology_latest.is_a?(Version)

  # When blocks are absent, arch is not relevant. For consistency, we
  # simulate the arm architecture.
  arch_options = is_cask_with_blocks ? OnSystem::ARCH_OPTIONS : [:arm]

  # If the cask restricts to specific architectures via
  # `depends_on arch:`, only simulate those architectures.
  if is_cask_with_blocks && formula_or_cask.is_a?(Cask::Cask)
    arch_deps = formula_or_cask.depends_on.arch
    if arch_deps.present?
      supported_archs = arch_deps.filter_map { |dep| dep[:type] } & arch_options
      arch_options = supported_archs if supported_archs.present?
    end
  end

  arch_options.each do |arch|
    SimulateSystem.with(arch:) do
      version_key = is_cask_with_blocks ? arch : :general

      # We reload the formula/cask here to ensure we're getting the
      # correct version for the current arch
      if formula_or_cask.is_a?(Formula)
        loaded_formula_or_cask = formula_or_cask
        stable = loaded_formula_or_cask.stable
        raise "unexpected nil stable" unless stable

        current_version_value = stable.version
      else
        sourcefile_path = formula_or_cask.sourcefile_path
        raise "unexpected nil sourcefile_path" unless sourcefile_path

        loaded_formula_or_cask = Cask::CaskLoader.load(sourcefile_path)
        current_version_value = Version.new(loaded_formula_or_cask.version)
      end

      deprecated[version_key] = loaded_formula_or_cask.deprecated?
      formula_or_cask_has_livecheck = loaded_formula_or_cask.livecheck_defined?

      livecheck_latest = livecheck_result(loaded_formula_or_cask, current_version_value)
      livecheck_latest_is_a_version = livecheck_latest.is_a?(Version)

      new_version_value = if (livecheck_latest_is_a_version &&
                              Livecheck::LivecheckVersion.create(formula_or_cask, livecheck_latest) >=
                              Livecheck::LivecheckVersion.create(formula_or_cask, current_version_value)) ||
                             current_version_value == "latest" ||
                             message?(livecheck_latest)
        livecheck_latest
      elsif repology_latest_is_a_version &&
            !formula_or_cask_has_livecheck &&
            repology_latest > current_version_value &&
            current_version_value != "latest"
        repology_latest
      end.presence

      # Fall back to the upstream version if there isn't a new version
      # value at this point, as this will allow us to surface an upstream
      # version that's lower than the current version.
      new_version_value ||= livecheck_latest if livecheck_latest_is_a_version
      new_version_value ||= repology_latest if repology_latest_is_a_version && !formula_or_cask_has_livecheck

      # Store old and new versions
      current_versions[version_key] = current_version_value
      new_versions[version_key] = new_version_value
    end
  end

  # Consolidate into a single general version when only one architecture
  # was simulated (e.g. `depends_on arch:` restricts to a single arch) or
  # when the arm and intel versions are identical, as happens with casks
  # where only the checksums differ.
  if is_cask_with_blocks && arch_options.length == 1
    single_arch = arch_options[0]
    current_versions = { general: current_versions[single_arch] }
    new_versions = { general: new_versions[single_arch] }
  else
    if current_versions[:arm].present? && current_versions[:arm] == current_versions[:intel]
      current_versions = { general: current_versions[:arm] }
    end
    if new_versions[:arm].present? && new_versions[:arm] == new_versions[:intel]
      new_versions = { general: new_versions[:arm] }
    end
  end

  current_version = BumpVersionParser.new(general: current_versions[:general],
                                          arm:     current_versions[:arm],
                                          intel:   current_versions[:intel])

  begin
    new_version = BumpVersionParser.new(general: new_versions[:general],
                                        arm:     new_versions[:arm],
                                        intel:   new_versions[:intel])
  rescue
    # When livecheck fails, we fail gracefully. Otherwise VersionParser
    # will raise a usage error
    new_version = BumpVersionParser.new(general: "unable to get versions")
  end

  compare_versions(current_version, new_version, formula_or_cask) =>
    { multiple_versions:, newer_than_upstream: }
  if !multiple_versions[:current] && deprecated[:general].nil?
    deprecated = { general: deprecated[:arm] || deprecated[:intel] || false }
  end

  # Collect resource version info for formulae with resources that have explicit livecheck blocks
  resource_versions = if formula_or_cask.is_a?(Formula) && new_version.general.is_a?(Version)
    collect_resource_versions(formula_or_cask, new_version.general.to_s)
  else
    []
  end

  if !args.no_pull_requests? &&
     !newer_than_upstream.all? { |_k, v| v == true }
    pull_request_version = nil
    if (new_version_arm = new_version.arm) &&
       !message?(new_version_arm) &&
       (new_version_arm != current_version.arm)
      # We use the ARM version for the pull request version even if there
      # are multiple arch versions to be consistent with the behavior of
      # bump-cask-pr.
      pull_request_version = new_version_arm.to_s
    elsif (new_version_intel = new_version.intel) &&
          !message?(new_version_intel) &&
          (new_version_intel != current_version.intel)
      pull_request_version = new_version_intel.to_s
    elsif (new_version_general = new_version.general) &&
          !message?(new_version_general) &&
          (new_version_general != current_version.general)
      pull_request_version = new_version_general.to_s
    end

    if pull_request_version
      duplicate_pull_requests = retrieve_pull_requests(
        formula_or_cask,
        name,
        version: pull_request_version,
      )

      maybe_duplicate_pull_requests = if duplicate_pull_requests.nil?
        retrieve_pull_requests(formula_or_cask, name)
      end
    end
  end

  VersionBumpInfo.new(
    type:,
    deprecated:,
    multiple_versions:,
    version_name:,
    current_version:,
    new_version:,
    resource_versions:,
    repology_latest:,
    newer_than_upstream:,
    duplicate_pull_requests:,
    maybe_duplicate_pull_requests:,
  )
end

#runvoid

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.



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
# File 'dev-cmd/bump.rb', line 104

def run
  Homebrew.install_bundler_gems!(groups: ["livecheck"])

  Homebrew.with_no_api_env do
    eval_all = args.eval_all?
    eval_all ||= args.no_named? && Homebrew::EnvConfig.tap_trust_configured?

    excluded_autobump = []
    if args.no_autobump? && eval_all
      excluded_autobump.concat(autobumped_formulae_or_casks(CoreTap.instance)) if args.formula?
      excluded_autobump.concat(autobumped_formulae_or_casks(CoreCaskTap.instance, casks: true)) if args.cask?
    end

    formulae_and_casks = if args.auto?
      raise UsageError, "`--formula` or `--cask` must be passed with `--auto`." if !args.formula? && !args.cask?

      tap_arg = args.tap
      raise UsageError, "`--tap=` must be passed with `--auto`." if tap_arg.blank?

      tap = Tap.fetch(tap_arg)
      autobump_list = tap.autobump
      what = args.cask? ? "casks" : "formulae"
      raise UsageError, "No autobumped #{what} found." if autobump_list.blank?

      # Only run bump on the first formula in each synced group
      if args.bump_synced? && args.formula?
        synced_formulae = Set.new(tap.synced_versions_formulae.flat_map { it.drop(1) })
      end

      autobump_list.filter_map do |name|
        qualified_name = "#{tap.name}/#{name}"
        next Cask::CaskLoader.load(qualified_name) if args.cask?
        next if synced_formulae&.include?(name)

        Formulary.factory(qualified_name)
      end
    elsif args.tap
      tap = Tap.fetch(args.tap)
      raise UsageError, "`--tap` requires `--auto` for official taps." if tap.official?

      formulae = args.cask? ? [] : tap.formula_files.map { |path| Formulary.factory(path) }
      casks = args.formula? ? [] : tap.cask_files.map { |path| Cask::CaskLoader.load(path) }
      formulae + casks
    elsif args.installed?
      formulae = args.cask? ? [] : Formula.installed
      casks = args.formula? ? [] : Cask::Caskroom.casks
      formulae + casks
    elsif args.named.present?
      T.cast(args.named.to_formulae_and_casks_with_taps, T::Array[T.any(Formula, Cask::Cask)])
    elsif eval_all
      formulae = args.cask? ? [] : Formula.all(eval_all:)
      casks = args.formula? ? [] : Cask::Cask.all(eval_all:)
      formulae + casks
    else
      raise UsageError,
            "`brew bump` without named arguments needs `--installed`, `HOMEBREW_REQUIRE_TAP_TRUST=1` or " \
            "`HOMEBREW_NO_REQUIRE_TAP_TRUST=1` set!"
    end

    if (start_with = args.start_with)
      formulae_and_casks.select! do |formula_or_cask|
        Utils.name_or_token(formula_or_cask).start_with?(start_with)
      end
    end

    formulae_and_casks = formulae_and_casks.sort_by do |formula_or_cask|
      Utils.name_or_token(formula_or_cask)
    end

    formulae_and_casks -= excluded_autobump

    if args.repology? && !Utils::Curl.curl_supports_tls13?
      begin
        Formula["curl"].ensure_installed!(reason: "Repology queries") unless HOMEBREW_BREWED_CURL_PATH.exist?
      rescue FormulaUnavailableError
        opoo "A newer `curl` is required for Repology queries."
      end
    end

    handle_formulae_and_casks(formulae_and_casks)
  end
end

#skip_ineligible_formulae!(formula_or_cask) ⇒ Boolean

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:

  • (Boolean)


190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'dev-cmd/bump.rb', line 190

def skip_ineligible_formulae!(formula_or_cask)
  if formula_or_cask.is_a?(Formula)
    skip = formula_or_cask.disabled? || formula_or_cask.head_only?
    name = formula_or_cask.name
    text = "Formula is #{formula_or_cask.disabled? ? "disabled" : "HEAD-only"} so not accepting updates.\n"
  else
    skip = formula_or_cask.disabled? || formula_or_cask.version.latest?
    name = formula_or_cask.token
    text = if formula_or_cask.disabled?
      "Cask is disabled so not accepting updates.\n"
    else
      "Cask uses `version :latest` so `brew bump` cannot check it.\n"
    end
  end
  if (tap = formula_or_cask.tap) && !tap.allow_bump?(name)
    skip = true
    text = "#{text.split.first} is autobumped so will have bump PRs opened by BrewTestBot every ~3 hours.\n"
  end
  return false unless skip

  ohai name
  puts text
  true
end

#version_args_for_bump(current_version:, new_version:, multiple_versions:, name:) ⇒ Array<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:



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
# File 'dev-cmd/bump.rb', line 565

def version_args_for_bump(current_version:, new_version:, multiple_versions:, name:)
  version_args = T.let([], T::Array[String])

  if multiple_versions[:new]
    (BumpVersionParser::VERSION_SYMBOLS - [:general]).each do |arch|
      new_arch_version = new_version.send(arch)
      next if new_arch_version.blank? || message?(new_arch_version)

      current_arch_version = if multiple_versions[:current]
        current_version.send(arch)
      else
        current_version.general
      end
      next if current_arch_version.blank? || new_arch_version <= current_arch_version

      version_args << "--version-#{arch}=#{new_arch_version}"
    end
  elsif multiple_versions[:current]
    if (new_version_general = new_version.general) && !message?(new_version_general)
      (BumpVersionParser::VERSION_SYMBOLS - [:general]).each do |arch|
        current_arch_version = current_version.send(arch)
        next if current_arch_version.blank? || new_version_general <= current_arch_version

        version_args << "--version-#{arch}=#{new_version_general}"
      end
    end

    opoo "`#{name}` needs to be manually updated using one version" if version_args.blank?
  elsif new_version.general
    version_args << "--version=#{new_version.general}"
  end

  version_args
end

#version_with_cooldown(version_info, current = nil) ⇒ Version?

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 highest upstream version that has been released before the cooldown interval.

Parameters:

Returns:



692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
# File 'dev-cmd/bump.rb', line 692

def version_with_cooldown(version_info, current = nil)
  return unless current

  latest = Version.new(version_info[:latest]) if version_info[:latest]
  return unless latest
  return if latest <= current

  strategy = T.cast(version_info.dig(:meta, :strategy), T.nilable(String))
  case strategy
  when "Npm"
    url = version_info.dig(:meta, :url, :strategy)&.delete_suffix("/latest")
    return unless url

    stdout, _stderr, status = Utils::Curl.curl_output(*DEFAULT_CURL_ARGS, url, **DEFAULT_CURL_OPTIONS).to_a
    return unless status.success?
    return if (content = stdout.scrub).blank?

    json = Homebrew::Livecheck::Strategy::Json.parse_json(content)
    release_dates = json["time"]&.except("created", "modified")
                                &.transform_values { |v| DateTime.parse(v) }
    return unless release_dates.present?

    current_str = current.to_s
    current_is_prerelease = current_str.include?("-")
    cooldown_interval = (DateTime.now - Homebrew::RELEASE_COOLDOWN_DAYS)
    release_dates.sort_by { |_, date| date }.reverse_each do |version_str, date|
      version = Version.new(version_str)
      return version if version_str == current_str
      next if (version > latest) || (version < current)

      # TODO: Properly handle prerelease version comparison
      next if !current_is_prerelease && version_str.include?("-")

      return version if date < cooldown_interval
    end
  when "Pypi"
    url = version_info.dig(:meta, :url, :strategy)
    original_url = version_info.dig(:meta, :url, :original)
    return if !url || !original_url

    suffix = Homebrew::Livecheck::Strategy::Pypi::URL_MATCH_REGEX.match(original_url)&.[](:suffix)
    return unless suffix

    content = version_info[:content]
    unless content
      stdout, _stderr, status = Utils::Curl.curl_output(*DEFAULT_CURL_ARGS, url, **DEFAULT_CURL_OPTIONS).to_a
      return unless status.success?

      content = stdout.scrub
    end
    return if content.blank?

    json = Homebrew::Livecheck::Strategy::Json.parse_json(content)
    return unless (releases = json["releases"])

    current_str = current.to_s
    current_is_prerelease = current_str.match?(PYPI_UNSTABLE_VERSION_REGEX)
    cooldown_interval = (DateTime.now - Homebrew::RELEASE_COOLDOWN_DAYS)
    releases.sort_by { |k, _| Version.new(k) }.reverse_each do |version_str, assets|
      version = Version.new(version_str)
      return version if version_str == current_str
      next if (version > latest) || (version < current)
      next if !current_is_prerelease && version_str.match?(PYPI_UNSTABLE_VERSION_REGEX)

      assets.each do |asset|
        next if asset["yanked"]
        next unless asset["url"]&.end_with?(suffix)
        next unless (date_str = asset["upload_time_iso_8601"])

        date = DateTime.parse(date_str)
        return version if date < cooldown_interval
      end
    end
  when "RubyGems"
    url = version_info.dig(:meta, :url, :strategy)&.sub(%r{/latest\.json\z}, ".json")
    original_url = version_info.dig(:meta, :url, :original)
    return if !url || !original_url

    match = Homebrew::Livecheck::Strategy::RubyGems::URL_MATCH_REGEX.match(original_url)
    return unless match

    stdout, _stderr, status = Utils::Curl.curl_output(*DEFAULT_CURL_ARGS, url, **DEFAULT_CURL_OPTIONS).to_a
    return unless status.success?
    return if (content = stdout.scrub).blank?

    json = Homebrew::Livecheck::Strategy::Json.parse_json(content)
    return unless json.is_a?(Array)

    current_str = current.to_s
    cooldown_interval = (DateTime.now - Homebrew::RELEASE_COOLDOWN_DAYS)
    json.sort_by { |release| Version.new(release["number"]) }.reverse_each do |release|
      next if release["platform"] != (match[:platform] || "ruby")

      version_str = release["number"]
      version = Version.new(version_str)
      return version if version_str == current_str
      next if (version > latest) || (version < current)
      next if release["prerelease"] &&
              !(Gem::Version.correct?(current_str) && Gem::Version.new(current_str).prerelease?)
      next unless (date_str = release["created_at"])

      return version if DateTime.parse(date_str) < cooldown_interval
    end
  end
end