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

Add HOMEBREW_UPGRADE_GREEDY="auto-updates" and "latest" #16736

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 0 additions & 2 deletions Library/Homebrew/cask/upgrade.rb
Expand Up @@ -40,8 +40,6 @@ def self.upgrade_casks(

quarantine = true if quarantine.nil?

greedy = true if Homebrew::EnvConfig.upgrade_greedy?

outdated_casks = if casks.empty?
Caskroom.casks(config: Config.from_args(args)).select do |cask|
cask.outdated?(greedy: greedy, greedy_latest: greedy_latest,
Expand Down
9 changes: 6 additions & 3 deletions Library/Homebrew/cmd/outdated.rb
Expand Up @@ -32,13 +32,16 @@ def self.outdated_args
"formula is outdated. Otherwise, the repository's HEAD will only be checked for " \
"updates when a new stable or development version has been released."
switch "-g", "--greedy",
description: "Also include outdated casks with `auto_updates true` or `version :latest`."
description: "Also include outdated casks with `auto_updates true` or `version :latest`.",
env: :cask_upgrade_greedy

switch "--greedy-latest",
description: "Also include outdated casks including those with `version :latest`."
description: "Also include outdated casks including those with `version :latest`.",
env: :cask_upgrade_greedy_latest

switch "--greedy-auto-updates",
description: "Also include outdated casks including those with `auto_updates true`."
description: "Also include outdated casks including those with `auto_updates true`.",
env: :cask_upgrade_greedy_auto_updates

conflicts "--quiet", "--verbose", "--json"
conflicts "--formula", "--cask"
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cmd/upgrade.rb
Expand Up @@ -91,12 +91,15 @@ def upgrade_args
}],
[:switch, "-g", "--greedy", {
description: "Also include casks with `auto_updates true` or `version :latest`.",
env: :cask_upgrade_greedy,
}],
[:switch, "--greedy-latest", {
description: "Also include casks with `version :latest`.",
env: :cask_upgrade_greedy_latest,
}],
[:switch, "--greedy-auto-updates", {
description: "Also include casks with `auto_updates true`.",
env: :cask_upgrade_greedy_auto_updates,
}],
[:switch, "--[no-]binaries", {
description: "Disable/enable linking of helper executables (default: enabled).",
Expand Down
22 changes: 20 additions & 2 deletions Library/Homebrew/env_config.rb
Expand Up @@ -341,8 +341,9 @@ module EnvConfig
boolean: true,
},
HOMEBREW_UPGRADE_GREEDY: {
description: "If set, pass `--greedy` to all cask upgrade commands.",
boolean: true,
description: "When set to \"auto-updates\", \"latest\", or any other value (e.g. \"1\"), pass " \
"`--greedy-auto-updates`, `--greedy-latest`, or `--greedy` respectively to all cask " \
"upgrade commands.",
},
HOMEBREW_SIMULATE_MACOS_ON_LINUX: {
description: "If set, running Homebrew on Linux will simulate certain macOS code paths. This is useful " \
Expand Down Expand Up @@ -504,5 +505,22 @@ def cask_opts_require_sha?
def automatically_set_no_install_from_api?
ENV["HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API"].present?
end

sig { returns(T::Boolean) }
def cask_upgrade_greedy?
ENV["HOMEBREW_UPGRADE_GREEDY"].present? &&
!cask_upgrade_greedy_latest? &&
!cask_upgrade_greedy_auto_updates?
Comment on lines +511 to +513
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a little weird/loose for "any value except latest or auto-updates implies greedy". Maybe we should only allow this value to be set to 1 or greedy or some few known values and error out otherwise?

Copy link
Contributor Author

@jck112 jck112 Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously HOMEBREW_UPGRADE_GREEDY was a Boolean so accepting any value is to maintain compatibility with any existing value a user may have set (e.g. "1", "true", "yes", etc).

However I agree that it would be nicer to accept specific values (e.g. "all", "latest", and "auto-updates") with some error handling to warn about invalid values and help users migrate from previously valid values (e.g. "1", etc).

end

sig { returns(T::Boolean) }
def cask_upgrade_greedy_latest?
ENV["HOMEBREW_UPGRADE_GREEDY"] == "latest"
end

sig { returns(T::Boolean) }
def cask_upgrade_greedy_auto_updates?
ENV["HOMEBREW_UPGRADE_GREEDY"] == "auto-updates"
end
end
end
4 changes: 2 additions & 2 deletions Library/Homebrew/env_config.rbi
Expand Up @@ -232,8 +232,8 @@ module Homebrew::EnvConfig
sig { returns(T::Boolean) }
def self.update_to_tag?; end

sig { returns(T::Boolean) }
def self.upgrade_greedy?; end
sig { returns(T.nilable(String)) }
def self.upgrade_greedy; end

sig { returns(T::Boolean) }
def self.verbose?; end
Expand Down
81 changes: 81 additions & 0 deletions Library/Homebrew/test/env_config_spec.rb
Expand Up @@ -63,4 +63,85 @@
expect(env_config.make_jobs).to eql("16")
end
end

describe ".cask_upgrade_greedy" do
it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "1"
expect(env_config.cask_upgrade_greedy?).to be(true)
end

it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "true"
expect(env_config.cask_upgrade_greedy?).to be(true)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest"
expect(env_config.cask_upgrade_greedy?).to be(false)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates"
expect(env_config.cask_upgrade_greedy?).to be(false)
end

it "returns false by default" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = ""
expect(env_config.cask_upgrade_greedy?).to be(false)
end
end

describe ".cask_upgrade_greedy_latest" do
it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "1"
expect(env_config.cask_upgrade_greedy_latest?).to be(false)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "true"
expect(env_config.cask_upgrade_greedy_latest?).to be(false)
end

it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest"
expect(env_config.cask_upgrade_greedy_latest?).to be(true)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates"
expect(env_config.cask_upgrade_greedy_latest?).to be(false)
end

it "returns false by default" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = ""
expect(env_config.cask_upgrade_greedy_latest?).to be(false)
end
end

describe ".cask_upgrade_greedy_auto_updates" do
it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"1\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "1"
expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"true\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "true"
expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false)
end

it "returns false if \"HOMEBREW_UPGRADE_GREEDY\" set to \"latest\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "latest"
expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false)
end

it "returns true if \"HOMEBREW_UPGRADE_GREEDY\" set to \"auto-updates\"" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = "auto-updates"
expect(env_config.cask_upgrade_greedy_auto_updates?).to be(true)
end

it "returns false by default" do
ENV["HOMEBREW_UPGRADE_GREEDY"] = ""
expect(env_config.cask_upgrade_greedy_auto_updates?).to be(false)
end
end
end
2 changes: 1 addition & 1 deletion docs/Manpage.md
Expand Up @@ -2357,7 +2357,7 @@ command execution e.g. `$(cat file)`.
<br>If set, use Pry for the `brew irb` command.

- `HOMEBREW_UPGRADE_GREEDY`
<br>If set, pass `--greedy` to all cask upgrade commands.
<br>When set to "auto-updates", "latest", or any other value (e.g. "1"), pass `--greedy-auto-updates`, `--greedy-latest`, or `--greedy` respectively to all cask upgrade commands.

- `HOMEBREW_SIMULATE_MACOS_ON_LINUX`
<br>If set, running Homebrew on Linux will simulate certain macOS code paths. This is useful when auditing macOS formulae while on Linux.
Expand Down
2 changes: 1 addition & 1 deletion manpages/brew.1
Expand Up @@ -3464,7 +3464,7 @@ If set, use Pry for the \fBbrew irb\fR command\.
\fBHOMEBREW_UPGRADE_GREEDY\fR
.
.br
If set, pass \fB\-\-greedy\fR to all cask upgrade commands\.
When set to "auto\-updates", "latest", or any other value (e\.g\. "1"), pass \fB\-\-greedy\-auto\-updates\fR, \fB\-\-greedy\-latest\fR, or \fB\-\-greedy\fR respectively to all cask upgrade commands\.
.
.TP
\fBHOMEBREW_SIMULATE_MACOS_ON_LINUX\fR
Expand Down