Skip to content

Commit

Permalink
cmd/install: infer --overwrite when in GitHub Actions
Browse files Browse the repository at this point in the history
Based on discussion at Homebrew/homebrew-core#195288.

I was initially inclined to scope this only to Python, but I think it
makes sense to apply more generally. The issue is that users often have
no control over what's already inside `HOMEBREW_PREFIX` when they run
`brew install`. Given that, I think it makes sense to assume users want
`--overwrite` unless configured otherwise with
`HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE`.
  • Loading branch information
carlocab committed Oct 23, 2024
1 parent f921bb4 commit 4c6cadd
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion Library/Homebrew/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,32 @@ def run
Install.perform_preinstall_checks_once
Install.check_cc_argv(args.cc)

overwrite = if GitHub::Actions.env_set? &&
ENV["HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE"].blank? &&
ENV["HOMEBREW_GITHUB_ACTIONS"].blank?
if ENV["HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE_WARNING"].blank?
message = <<~WARNING
In GitHub Actions, `brew install` behaves the same as `brew install --overwrite`.
To disable this behaviour, set `HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE`.
To silence this warning, set `HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE_WARNING`.
WARNING

puts GitHub::Actions::Annotation.new(:warning, message)

Check warning on line 313 in Library/Homebrew/cmd/install.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/install.rb#L313

Added line #L313 was not covered by tests

# Print warning only once.
github_env = ENV.fetch("GITHUB_ENV", "")

Check warning on line 316 in Library/Homebrew/cmd/install.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cmd/install.rb#L316

Added line #L316 was not covered by tests
if File.exist?(github_env) && File.writable?(github_env)
File.open(github_env, "a") { |f| f.puts("HOMEBREW_GITHUB_ACTIONS_NO_INSTALL_OVERWRITE_WARNING=1") }
end
end

true
else
args.overwrite?
end

Install.install_formulae(
installed_formulae,
build_bottle: args.build_bottle?,
Expand All @@ -313,7 +339,7 @@ def run
keep_tmp: args.keep_tmp?,
debug_symbols: args.debug_symbols?,
force: args.force?,
overwrite: args.overwrite?,
overwrite:,
debug: args.debug?,
quiet: args.quiet?,
verbose: args.verbose?,
Expand Down

0 comments on commit 4c6cadd

Please sign in to comment.