Share attestation formula sorting and gh exe checking logic

This adds a new method to either move the `gh` formula to the front
of the formula list to be installed or checks that the `gh` formula
is already installed some other way.
This commit is contained in:
apainintheneck 2024-07-18 21:32:50 -07:00
parent 75cfa21068
commit 52cf4e30fc
4 changed files with 21 additions and 23 deletions

View File

@ -86,6 +86,24 @@ module Homebrew
T.must(@gh_executable)
end
# Prioritize installing `gh` first if it's in the formula list
# or check for the existence of the `gh` executable elsewhere.
#
# This ensures that a valid version of `gh` is installed before
# we use it to check the attestations of any other formulae we
# want to install.
#
# @api private
sig { params(formulae: T::Array[Formula]).returns(T::Array[Formula]) }
def self.sort_formulae_for_install(formulae)
if formulae.include?(Formula["gh"])
[Formula["gh"]] | formulae
else
Homebrew::Attestation.gh_executable
formulae
end
end
# Verifies the given bottle against a cryptographic attestation of build provenance.
#
# The provenance is verified as originating from `signing_repository`, which is a `String`

View File

@ -263,13 +263,7 @@ module Homebrew
end
end
if Homebrew::Attestation.enabled?
if formulae.include?(Formula["gh"])
formulae.unshift(T.must(formulae.delete(Formula["gh"])))
else
Homebrew::Attestation.gh_executable
end
end
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?
# if the user's flags will prevent bottle only-installations when no
# developer tools are available, we need to stop them early on

View File

@ -124,14 +124,7 @@ module Homebrew
end
end
if Homebrew::Attestation.enabled?
if formulae.include?(Formula["gh"])
# Move `gh` to the front of the list so that it gets installed first.
formulae = [Formula["gh"]] | formulae
else
Homebrew::Attestation.gh_executable
end
end
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?
Install.perform_preinstall_checks

View File

@ -134,14 +134,7 @@ module Homebrew
only_upgrade_formulae = formulae.present? && casks.blank?
only_upgrade_casks = casks.present? && formulae.blank?
if Homebrew::Attestation.enabled?
if formulae.include?(Formula["gh"])
# Move `gh` to the front of the list so that it gets installed first.
formulae = [Formula["gh"]] | formulae
else
Homebrew::Attestation.gh_executable
end
end
formulae = Homebrew::Attestation.sort_formulae_for_install(formulae) if Homebrew::Attestation.enabled?
upgrade_outdated_formulae(formulae) unless only_upgrade_casks
upgrade_outdated_casks(casks) unless only_upgrade_formulae