Class: Homebrew::DevCmd::Bump Private
- Inherits:
-
AbstractCommand
- Object
- AbstractCommand
- Homebrew::DevCmd::Bump
- 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", "--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, { connect_timeout: Integer, max_time: Integer, timeout: Integer, retries: Integer })
- MAX_CONSECUTIVE_GITHUB_API_ERRORS =
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.
5- MAX_GITHUB_API_RETRIES =
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.
3- 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
- #args ⇒ Homebrew::DevCmd::Bump::Args private
- #compare_versions(current_version, new_version, formula_or_cask) ⇒ Hash{Symbol => Hash{Symbol => Boolean}} private
- #compare_versions_for_strategy(strategy, left, right) ⇒ Integer? private
- #message?(value) ⇒ Boolean private
- #retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, ambiguous_cask: false) ⇒ void private
- #retrieve_pull_requests(formula_or_cask, state: nil, version: nil) ⇒ Array<String>, ... private
- #retrieve_versions_by_arch(formula_or_cask:, repositories:) ⇒ VersionBumpInfo private
- #run ⇒ void private
- #skip_ineligible_package!(formula_or_cask) ⇒ Boolean private
- #version_args_for_bump(current_version:, new_version:, multiple_versions:, name:) ⇒ Array<String> private
-
#version_with_cooldown(version_info, current = nil) ⇒ Version?
private
Identifies the highest upstream version that has been released before the cooldown interval.
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_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
Constructor Details
This class inherits a constructor from Homebrew::AbstractCommand
Instance Method Details
#args ⇒ Homebrew::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.
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 |
# File 'dev-cmd/bump.rb', line 720 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.public_send(type) if current_version_value current_versions[type] = Livecheck::LivecheckVersion.create(formula_or_cask, current_version_value) end new_version_value = new_version.public_send(type) if (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 |
#compare_versions_for_strategy(strategy, left, right) ⇒ Integer?
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.
795 796 797 798 799 |
# File 'dev-cmd/bump.rb', line 795 def compare_versions_for_strategy(strategy, left, right) return Semver.compare(left, right) if strategy == "Npm" Version.new(left) <=> Version.new(right) 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.
788 789 790 791 792 |
# File 'dev-cmd/bump.rb', line 788 def (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.
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 664 665 666 |
# File 'dev-cmd/bump.rb', line 490 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:) 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 cooldown_skipped_version = version_info.cooldown_skipped_versions.values.max duplicate_pull_requests = version_info.duplicate_pull_requests open_bump_pull_requests = version_info.open_bump_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 if cooldown_skipped_version "#{title_name} #{Tty.yellow}has a new version in release cooldown#{Tty.reset}" else "#{title_name} #{Tty.green}is up to date!#{Tty.reset}" end else title_name end # Conditionally format output based on type of formula_or_cask current_versions = if multiple_versions[:current] && (current_version.linux_arm || current_version.linux_intel) [:arm, :intel, :linux_arm, :linux_intel].filter_map do |type| version = current_version.public_send(type) next unless version architecture = type.to_s.tr("_", " ") "#{architecture}: #{version}#{version_info.version_notes(type)}" end.join("\n ") elsif multiple_versions[:current] arm_version = current_version.arm || current_version.general intel_version = current_version.intel || current_version.general "arm: #{arm_version}#{version_info.version_notes(:arm)}" \ "\n intel: #{intel_version}#{version_info.version_notes(:intel)}" else "#{current_version.general}#{version_info.version_notes(:general)}" end new_versions = if multiple_versions[:new] && (new_version.linux_arm || new_version.linux_intel) [:arm, :intel, :linux_arm, :linux_intel].filter_map do |type| version = new_version.public_send(type) next unless version architecture = type.to_s.tr("_", " ") "#{architecture}: #{version}" end.join("\n ") elsif 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 latest_versions = if cooldown_skipped_version cooldown_days = Utils.pluralize("day", Homebrew::RELEASE_COOLDOWN_DAYS, include_count: true) "#{cooldown_skipped_version} (released less than #{cooldown_days} ago)" else throttle_note = throttled ? " (throttled)" : "" "#{new_versions}#{throttle_note}" end ohai title puts <<~EOS Current #{version_info.version_name} #{current_versions} Latest livecheck version: #{latest_versions} EOS puts "Bump-ready version: #{new_versions}" if cooldown_skipped_version 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? && !(new_version.general) && !versions_equal && !all_newer_than_upstream if duplicate_pull_requests duplicate_pull_requests_text = duplicate_pull_requests elsif open_bump_pull_requests duplicate_pull_requests_text = "none" open_bump_pull_requests_text = open_bump_pull_requests else duplicate_pull_requests_text = "none" open_bump_pull_requests_text = "none" end puts "Duplicate pull requests: #{duplicate_pull_requests_text}" puts "Open bump pull requests: #{open_bump_pull_requests_text}" if open_bump_pull_requests_text end if (!args.open_pr? && !args.write_pr_to) || (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) && current_version.general && new_version.general && 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? || open_bump_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", formula_or_cask.full_name, *version_args, "--no-browse", "--message=Created by `brew bump`", ] bump_pr_args << "--write-pr-to=#{args.write_pr_to}" if args.write_pr_to 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_pull_requests(formula_or_cask, state: nil, version: nil) ⇒ 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.
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 |
# File 'dev-cmd/bump.rb', line 906 def retrieve_pull_requests(formula_or_cask, state: nil, version: nil) tap_remote_repo = formula_or_cask.tap&.remote_repository || formula_or_cask.tap&.full_name odie "unexpected nil tap remote repository" if tap_remote_repo.nil? # Pull request titles use the short name and the search is already scoped # to the tap's repository, so a fully-qualified name would never match. name = Livecheck.package_or_resource_name(formula_or_cask) pull_requests = begin GitHub.fetch_pull_requests(name, tap_remote_repo, state:, version:) rescue GitHub::API::ValidationFailedError => e odebug "Error fetching pull requests for #{formula_or_cask} #{name}: #{e}" nil end return if pull_requests.blank? # If a version is provided, we keep all matches in case a contributor has # opened a PR with a non-standard title, e.g. "<name>: update to <version>". # Otherwise, filter results to reduce false positives. The filter is still # loose enough to allow synced formulae, e.g. "<name> <n2> ... <version>", # and titles with parentheses, e.g. "<name> <version> (<extra-message>)" if version.blank? pull_requests.select! do |pr| (title = pr["title"]) && title.start_with?("#{name} ") && title.exclude?(": ") end return if pull_requests.blank? end pull_requests.map { |pr| "#{pr["title"]} (#{Formatter.url(pr["html_url"])})" }.join(", ") end |
#retrieve_versions_by_arch(formula_or_cask:, repositories:) ⇒ 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.
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 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 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'dev-cmd/bump.rb', line 265 def retrieve_versions_by_arch(formula_or_cask:, repositories:) 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 = {} cooldown_skipped_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. = 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] } & = supported_archs if supported_archs.present? end end # Only resolve every platform for casks that already resolve to one version per operating system. # Casks with a shared version resolve versions by architecture only. platform_specific = false = .map do |arch| [nil, arch, is_cask_with_blocks ? arch : :general] end if formula_or_cask.is_a?(Cask::Cask) && formula_or_cask.on_os_blocks_exist? current_os = Homebrew::SimulateSystem.current_os macos = if MacOSVersion::SYMBOLS.include?(current_os) current_os else MacOSVersion.new(HOMEBREW_MACOS_NEWEST_SUPPORTED).to_sym end systems = { macos:, linux: :linux } detected_versions = {} loaded_cask = formula_or_cask.refresh_copy = BumpVersionParser::VERSION_PLATFORMS.filter_map do |version_type, (system, arch)| os = systems.fetch(system) tag = Utils::Bottles::Tag.new(system: os, arch:) loaded_cask.refresh_for_tag(tag) do next if tag.macos? && !loaded_cask.supports_macos? next if tag.linux? && !loaded_cask.supports_linux? supported_archs = loaded_cask.depends_on.arch&.filter_map { |dep| dep[:type] }&.uniq next if supported_archs.present? && supported_archs.exclude?(arch) next unless loaded_cask.version detected_versions[version_type] = Version.new(loaded_cask.version) [os, arch, version_type] end end macos_versions = detected_versions.values_at(:arm, :intel).compact.uniq linux_versions = detected_versions.values_at(:linux_arm, :linux_intel).compact.uniq if macos_versions.one? && linux_versions.one? && macos_versions != linux_versions platform_specific = true = end end .each do |os, arch, version_key| SimulateSystem.with(os:, arch:) do 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 loaded_formula_or_cask = formula_or_cask.refresh_copy next unless loaded_formula_or_cask.version 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, cooldown_skipped = livecheck_result(loaded_formula_or_cask, current_version_value) cooldown_skipped_versions[version_key] = cooldown_skipped if cooldown_skipped 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" || (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 # Collapse identical platform results to `general` # only when every platform returned a result. if platform_specific [new_versions, cooldown_skipped_versions].each do |versions| values = versions.values.compact next if values.size != .size || !values.uniq.one? versions.replace(general: values.first) end # Consolidate into a single general version when only one architecture # has a version or when the arm and intel versions are identical, as # happens with casks where only the checksums differ. elsif is_cask_with_blocks && current_versions.one? single_arch = current_versions.keys.fetch(0) current_versions = { general: current_versions[single_arch] } new_versions = { general: new_versions[single_arch] } cooldown_skipped_versions = { general: cooldown_skipped_versions[single_arch] }.compact else [current_versions, new_versions, cooldown_skipped_versions].each do |versions| next if versions[:arm].blank? || versions[:arm] != versions[:intel] versions.replace(general: versions[:arm]) end end current_version = BumpVersionParser.new(general: current_versions[:general], arm: current_versions[:arm], intel: current_versions[:intel], linux_arm: current_versions[:linux_arm], linux_intel: current_versions[:linux_intel]) begin new_version = BumpVersionParser.new(general: new_versions[:general], arm: new_versions[:arm], intel: new_versions[:intel], linux_arm: new_versions[:linux_arm], linux_intel: new_versions[:linux_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] || deprecated[:linux_arm] || deprecated[:linux_intel] || false } end # Collect resource version info for formulae with resources that have # explicit livecheck blocks, only when the formula has a newer version resource_versions = if formula_or_cask.is_a?(Formula) && (new_version_general = new_version.general).is_a?(Version) && (current_version_general = current_version.general) && new_version_general > current_version_general 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 } # Prefer ARM for the pull request version, matching bump-cask-pr. pull_request_version = [ [new_version.arm, current_version.arm], [new_version.intel, current_version.intel], [new_version.linux_arm, current_version.linux_arm], [new_version.linux_intel, current_version.linux_intel], [new_version.general, current_version.general], ].find do |candidate, current| candidate && !(candidate) && candidate != current end&.first&.to_s if pull_request_version duplicate_pull_requests = retrieve_pull_requests(formula_or_cask, version: pull_request_version) open_bump_pull_requests = if duplicate_pull_requests.nil? retrieve_pull_requests(formula_or_cask, state: "open") end end end VersionBumpInfo.new( type:, deprecated:, multiple_versions:, version_name:, current_version:, new_version:, resource_versions:, repology_latest:, newer_than_upstream:, cooldown_skipped_versions:, duplicate_pull_requests:, open_bump_pull_requests:, ) end |
#run ⇒ 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.
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 |
# File 'dev-cmd/bump.rb', line 128 def run # Formulae and casks may share a name and therefore a proposal file. if args.write_pr_to && !args.formula? && !args.cask? raise UsageError, "`--write-pr-to` requires `--formula` or `--cask`." end if args.prepare_prs || args.commit_pr_from || args.sign_pr? autobump_tap = Tap.fetch(args.tap || (args.cask? ? "Homebrew/cask" : "Homebrew/core")) if (file = args.prepare_prs) return Homebrew::Bump.prepare_prs(file, autobump_tap, casks: args.cask?) elsif (file = args.commit_pr_from) raise UsageError, "Specify one prepared formula or cask." if args.named.size != 1 Utils::GemSetup.install_bundler_gems!(groups: ["ast"]) return Homebrew::API.with_no_api_env do Homebrew::Bump.commit_prepared_pr(file, args.named.fetch(0), autobump_tap, casks: args.cask?) end end return Homebrew::Bump.sign_pr(autobump_tap) end Utils::GemSetup.install_bundler_gems!(groups: ["livecheck"]) Homebrew::API.with_no_api_env do excluded_autobump = [] if args.no_autobump? && args.no_named? 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? formula_files = args.cask? ? [] : tap.formula_files cask_files = args.formula? ? [] : tap.cask_files formula_files.map { |path| Formulary.from_path(path) } + cask_files.map { |path| Cask::CaskLoader.from_path(path) } 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)]) else formulae = args.cask? ? [] : Formula.all casks = args.formula? ? [] : Cask::Cask.all formulae + casks 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_package!(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.
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 |
# File 'dev-cmd/bump.rb', line 229 def skip_ineligible_package!(formula_or_cask) disabled = DeprecateDisable.disabled_on_all_platforms?(formula_or_cask) if formula_or_cask.is_a?(Formula) skip = disabled || formula_or_cask.head_only? name = formula_or_cask.name formula_status = disabled ? "disabled" : "HEAD-only" text = "Formula is #{formula_status} so not accepting updates.\n" else version = formula_or_cask.version skip = disabled || version.nil? || version.latest? name = formula_or_cask.token text = if disabled "Cask is disabled so not accepting updates.\n" elsif version.nil? "Cask has no version for the current platform so `brew bump` cannot check it.\n" else "Cask uses `version :latest` so `brew bump` cannot check it.\n" end end if !skip && (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.
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'dev-cmd/bump.rb', line 676 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.public_send(arch) next if new_arch_version.blank? || (new_arch_version) current_arch_version = if multiple_versions[:current] current_version.public_send(arch) else current_version.general end next if current_arch_version.blank? || new_arch_version <= current_arch_version arch_flag = arch.to_s.tr("_", "-") version_args << "--version-#{arch_flag}=#{new_arch_version}" end elsif multiple_versions[:current] if (new_version_general = new_version.general) && !(new_version_general) (BumpVersionParser::VERSION_SYMBOLS - [:general]).each do |arch| current_arch_version = current_version.public_send(arch) next if current_arch_version.blank? || new_version_general <= current_arch_version arch_flag = arch.to_s.tr("_", "-") version_args << "--version-#{arch_flag}=#{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.
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
# File 'dev-cmd/bump.rb', line 812 def version_with_cooldown(version_info, current = nil) return unless current latest_str = version_info[:latest_throttled] || version_info[:latest] latest = Version.new(latest_str) if latest_str return unless latest strategy = T.cast(version_info.dig(:meta, :strategy), T.nilable(String)) return unless compare_versions_for_strategy(strategy, latest.to_s, current.to_s)&.positive? url = version_info.dig(:meta, :url, :strategy) original_url = version_info.dig(:meta, :url, :original) current_str = current.to_s # Each strategy lists `[version, publish time]` pairs, without yanked # releases or prereleases (unless the current version is one). releases = case strategy when "Crate" return if (content = cooldown_content(url, version_info[:content])).blank? current_is_prerelease = Semver.prerelease?(current_str) content.each_line.filter_map do |line| release = Homebrew::Livecheck::Strategy::Json.parse_json(line) next if release["yanked"] next if !current_is_prerelease && Semver.prerelease?(release["vers"]) [release["vers"], release["pubtime"]] end when "Npm" return if (content = cooldown_content(url&.delete_suffix("/latest"))).blank? current_is_prerelease = Semver.prerelease?(current_str) json = Homebrew::Livecheck::Strategy::Json.parse_json(content) json["time"].to_h.except("created", "modified").reject do |version_str, _| !current_is_prerelease && Semver.prerelease?(version_str) end when "Pypi" suffix = Homebrew::Livecheck::Strategy::Pypi::URL_MATCH_REGEX.match(original_url.to_s)&.[](:suffix) return unless suffix return if (content = cooldown_content(url, version_info[:content])).blank? current_is_prerelease = current_str.match?(PYPI_UNSTABLE_VERSION_REGEX) json = Homebrew::Livecheck::Strategy::Json.parse_json(content) json["releases"].to_a.flat_map do |version_str, assets| next [] if !current_is_prerelease && version_str.match?(PYPI_UNSTABLE_VERSION_REGEX) assets.filter_map do |asset| [version_str, asset["upload_time_iso_8601"]] if !asset["yanked"] && asset["url"]&.end_with?(suffix) end end when "RubyGems" match = Homebrew::Livecheck::Strategy::RubyGems::URL_MATCH_REGEX.match(original_url.to_s) return unless match return if (content = cooldown_content(url&.sub(%r{/latest\.json\z}, ".json"))).blank? json = Homebrew::Livecheck::Strategy::Json.parse_json(content) return unless json.is_a?(Array) current_is_prerelease = Gem::Version.correct?(current_str) && Gem::Version.new(current_str).prerelease? json.filter_map do |release| next if release["platform"] != (match[:platform] || "ruby") next if release["prerelease"] && !current_is_prerelease [release["number"], release["created_at"]] end end return if releases.blank? latest_str = latest.to_s cooldown_interval = (DateTime.now - Homebrew::RELEASE_COOLDOWN_DAYS) cooldown_versions = releases.filter_map do |version_str, date_str| next unless date_str latest_comparison = compare_versions_for_strategy(strategy, version_str, latest_str) next if latest_comparison.nil? || latest_comparison.positive? current_comparison = compare_versions_for_strategy(strategy, version_str, current_str) next if current_comparison.nil? || current_comparison.negative? version_str if DateTime.parse(date_str) < cooldown_interval end cooldown_version = cooldown_versions.max do |left, right| compare_versions_for_strategy(strategy, left, right) || 0 end # Keep the current version when every newer release is in cooldown. Version.new(cooldown_version || current_str) end |