Skip to content

Commit ef2e8ce

Browse files
committed
bump: split multiple_versions on current/new
The `multiple_versions` boolean is true if the current or new versions are split based on arch but this can cause unexpected behavior when `multiple_versions` is used as a conditional. In some places we need to check whether there are multiple current versions and in other places we need to check if there are multiple new versions, so the existing value isn't granular enough. This may not be a problem when both current and new have the same version setup but it can cause issues when there's a difference. This changes `multiple_versions` to a hash with boolean values and updates related conditions to use the contextually appropriate value. This resolves a couple of issues: * The current version for multi-arch casks with one `version` were being split into arm/intel values in the output when the new versions differ based on arch and vice versa. This effectively ensures that the current and new versions are only split in the output when the version differs. * The `deprecated[:general]` value wasn't being properly set when the current and new versions didn't have the same version setup, as the fallback value specifically needs to be set when there aren't multiple current versions. Besides that, we also need to specifically check if there are multiple current versions to be able to properly identify current versions that are newer than the upstream version when both current and new don't have the same version setup but this will be addressed in another commit.
1 parent 97ae79c commit ef2e8ce

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

Library/Homebrew/dev-cmd/bump.rb

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Bump < AbstractCommand
1414
class VersionBumpInfo < T::Struct
1515
const :type, Symbol
1616
const :deprecated, T::Hash[Symbol, T::Boolean], default: {}
17-
const :multiple_versions, T::Boolean
17+
const :multiple_versions, T::Hash[Symbol, T::Boolean], default: {}
1818
const :version_name, String
1919
const :current_version, BumpVersionParser
2020
const :new_version, BumpVersionParser
@@ -385,9 +385,11 @@ def retrieve_versions_by_arch(formula_or_cask:, repositories:, name:)
385385
new_versions = { general: new_versions[:arm] }
386386
end
387387

388-
multiple_versions = old_versions.values_at(:arm, :intel).all?(&:present?) ||
389-
new_versions.values_at(:arm, :intel).all?(&:present?)
390-
deprecated[:general] ||= deprecated[:arm] || false unless multiple_versions
388+
multiple_versions = {}
389+
multiple_versions[:current] = old_versions.values_at(:arm, :intel).all?(&:present?)
390+
multiple_versions[:new] = new_versions.values_at(:arm, :intel).all?(&:present?)
391+
392+
deprecated = { general: deprecated[:arm] || false } unless multiple_versions[:current]
391393

392394
current_version = BumpVersionParser.new(general: old_versions[:general],
393395
arm: old_versions[:arm],
@@ -421,7 +423,7 @@ def retrieve_versions_by_arch(formula_or_cask:, repositories:, name:)
421423
!newer_than_upstream.all? { |_k, v| v == true }
422424
# We use the ARM version for the pull request version. This is
423425
# consistent with the behavior of bump-cask-pr.
424-
pull_request_version = if multiple_versions
426+
pull_request_version = if multiple_versions[:new]
425427
new_version.arm.to_s
426428
else
427429
new_version.general.to_s
@@ -485,7 +487,7 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
485487
end
486488

487489
# Conditionally format output based on type of formula_or_cask
488-
current_versions = if multiple_versions
490+
current_versions = if multiple_versions[:current]
489491
"arm: #{current_version.arm || current_version.general}" \
490492
"#{NEWER_THAN_UPSTREAM_MSG if newer_than_upstream[:arm]}" \
491493
"#{" (deprecated)" if deprecated[:arm]}" \
@@ -499,7 +501,7 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
499501
"#{" (deprecated)" if deprecated[:general]}"
500502
end
501503

502-
new_versions = if multiple_versions && new_version.arm && new_version.intel
504+
new_versions = if multiple_versions[:new] && new_version.arm && new_version.intel
503505
"arm: #{new_version.arm}
504506
intel: #{new_version.intel}"
505507
else
@@ -562,13 +564,13 @@ def retrieve_and_display_info_and_open_pr(formula_or_cask, name, repositories, a
562564
puts "#{title_name} was not bumped to the Repology version because it has a `livecheck` block."
563565
end
564566
if new_version.blank? || versions_equal ||
565-
(!new_version.general.is_a?(Version) && !multiple_versions)
567+
(!new_version.general.is_a?(Version) && !multiple_versions[:new])
566568
return
567569
end
568570

569571
return if duplicate_pull_requests.present?
570572

571-
version_args = if multiple_versions
573+
version_args = if multiple_versions[:new]
572574
%W[--version-arm=#{new_version.arm} --version-intel=#{new_version.intel}]
573575
else
574576
"--version=#{new_version.general}"

0 commit comments

Comments
 (0)