Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attestation: specialize error when gh is old #17926

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Library/Homebrew/attestation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
return false if ENV.fetch("CI", false)
return false if OS.unsupported_configuration?

gh_version = Formula["gh"].any_installed_version

Check warning on line 65 in Library/Homebrew/attestation.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/attestation.rb#L65

Added line #L65 was not covered by tests
return false if gh_version.nil? || gh_version < "2.49"

# Always check credentials last to avoid unnecessary credential extraction.
(Homebrew::EnvConfig.developer? || Homebrew::EnvConfig.devcmdrun?) && GitHub::API.credentials.present?
end
Expand All @@ -78,7 +81,7 @@
# to prevent a cycle during bootstrapping. This can eventually be resolved
# by vendoring a pure-Ruby Sigstore verifier client.
with_env(HOMEBREW_NO_VERIFY_ATTESTATIONS: "1") do
@gh_executable = ensure_executable!("gh", reason: "verifying attestations", latest: true)
@gh_executable = ensure_formula_installed!("gh", reason: "verifying attestations", latest: true).opt_bin/"gh"
end

T.must(@gh_executable)
Expand Down
9 changes: 5 additions & 4 deletions Library/Homebrew/test/attestation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

RSpec.describe Homebrew::Attestation do
let(:fake_gh) { Pathname.new("/extremely/fake/gh") }
let(:fake_gh_formula) { instance_double(Formula, opt_bin: Pathname.new("/extremely/fake")) }
let(:fake_old_gh) { Pathname.new("/extremely/fake/old/gh") }
let(:fake_gh_creds) { "fake-gh-api-token" }
let(:fake_error_status) { instance_double(Process::Status, exitstatus: 1, termsig: nil) }
Expand Down Expand Up @@ -66,12 +67,12 @@
end

describe "::gh_executable" do
it "calls ensure_executable" do
expect(described_class).to receive(:ensure_executable!)
it "calls ensure_formula_installed" do
expect(described_class).to receive(:ensure_formula_installed!)
.with("gh", reason: "verifying attestations", latest: true)
.and_return(fake_gh)
.and_return(fake_gh_formula)

described_class.gh_executable
described_class.gh_executable == fake_gh
end
end

Expand Down