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

Conversation

jck112
Copy link
Contributor

@jck112 jck112 commented Feb 23, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

Fixes: #16735

@jck112 jck112 changed the title Add support for --greedy* options in HOMEBREW_CASK_OPTS Add HOMEBREW_UPGRADE_GREEDY="auto-updates" and "latest" Feb 24, 2024
Copy link
Member

@reitermarkus reitermarkus left a comment

Choose a reason for hiding this comment

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

This should also be supported in brew outdated, which also has these options.

@jck112
Copy link
Contributor Author

jck112 commented Feb 25, 2024

This should also be supported in brew outdated, which also has these options.

Added in latest update.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks of the PR!

Sorry to contradict later in the day: I think this would be nicer as three separate variables instead.

@MikeMcQuaid
Copy link
Member

@reitermarkus If you disagree: let's discuss here instead.

@reitermarkus
Copy link
Member

As I mentioned in the issue, I prefer one variable since it avoids the case where multiple can be specified. For the user it's a choice between 1, latest and auto-updates.

@MikeMcQuaid
Copy link
Member

@reitermarkus Feels a bit weird to have 1 be one of these options and also there's few variables that take multiple values like that so may be more confusing than not.

@jck112
Copy link
Contributor Author

jck112 commented Feb 26, 2024

FWIW, the existing code does handle when multiple options are specified (e.g. brew upgrade --greedy --greedy-auto-updates --greedy-latest).

if casks.empty? && !greedy
if !greedy_auto_updates && !greedy_latest
ohai "Casks with 'auto_updates true' or 'version :latest' " \
"will not be upgraded; pass `--greedy` to upgrade them."
end
if greedy_auto_updates && !greedy_latest
ohai "Casks with 'version :latest' will not be upgraded; pass `--greedy-latest` to upgrade them."
end
if !greedy_auto_updates && greedy_latest
ohai "Casks with 'auto_updates true' will not be upgraded; pass `--greedy-auto-updates` to upgrade them."
end
end

If separate env vars are preferred I have a patch ready to go for that too (https://github.com/jck112/Homebrew-brew/commit/ea119ed07f3d943d0bb3fdf2f0f7b0c150f77a33).

@MikeMcQuaid
Copy link
Member

Thanks @jck112! Will let you know when we've decided.


@Homebrew/maintainers @Homebrew/cask any thoughts on one variable vs. many? We don't have many variables which have differing behaviours due to setting the same variable to different values so feels unintuitive but I'm open to other viewpoints.

@miccal
Copy link
Member

miccal commented Feb 27, 2024

Thanks @jck112! Will let you know when we've decided.

@Homebrew/maintainers @Homebrew/cask any thoughts on one variable vs. many? We don't have many variables which have differing behaviours due to setting the same variable to different values so feels unintuitive but I'm open to other viewpoints.

I would prefer just one variable :)

@Bo98
Copy link
Member

Bo98 commented Feb 27, 2024

My general opinion (to anything):

  • If the behaviour of multiple at the same time is well defined and supported (and not just a case of one overrides the other), then multiple variables makes sense
  • Otherwise just a single variable is best

@reitermarkus
Copy link
Member

Feels a bit weird to have 1 be one of these options

We can call it true or always if that makes it less weird, but the code currently accepts any value anyways.

We don't have many variables which have differing behaviours due to setting the same variable to different values

That's because we also don't have that many flags that have the same prefix with different behaviours like --greedy, --greedy-latest, --greedy-auto-updates.

The one I could find is --linux, --linux-self-hosted and --linux-wheezy in dispatch-build-bottle, but that doesn't really need a global setting.

@reitermarkus
Copy link
Member

reitermarkus commented Feb 27, 2024

If the behaviour of multiple at the same time is well defined and supported

That's actually a good question. I don't think it is well defined and more of an implementation detail. --greedy implies --greedy-latest and --greedy-auto-updates, but is --greedy-latest + --greedy-auto-updates equivalent to just --greedy?

@bevanjkay
Copy link
Member

bevanjkay commented Feb 27, 2024

Is --greedy-latest + --greedy-auto-updates equal to just --greedy?

Yeah, it is.


I think following the flags and having three variables makes sense to me.

@reitermarkus
Copy link
Member

Yeah, it is.

Okay, if it wasn't, separate variables would make sense to me.

Given that it is equivalent, one variable makes more sense to me.

@reitermarkus
Copy link
Member

I think following the flags and having three variables makes sense to me.

Personally, I think it would actually make more sense for the flags to be --greedy, --greedy latest and --greedy auto-updates so only one option can be specified. For now, they should at least have conflicts with each other.

@razvanazamfirei
Copy link
Member

I recall we passed on this in #15164, but I'm glad this is discussed. Regardless, I agree with the 3 variable approach if we are keeping the flags as they are.

I think it would actually make more sense for the flags to be --greedy, --greedy latest and --greedy auto-updates

I like this approach a lot more, with the one caveat that --greedy itself is confusing and not descriptive enough to differentiate it from the other options. Perhaps having something along the lines of --greedy all as an alias for --greedy?

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Ok, I'm convinced by this approach, thanks everyone and @jck112 again for the PR.

I've left one comment already but also:

Personally, I think it would actually make more sense for the flags to be --greedy, --greedy latest and --greedy auto-updates so only one option can be specified. For now, they should at least have conflicts with each other.

I strongly agree with this if we merge this PR. Not saying the values should necessarily be latest and auto-updates but whatever values we use should be consistent between there and here and we should fail on unknown other values.

This may require some deprecation cycles in later releases.

@jck112 if any of the above is confusing to you: my bad, sorry, ask whatever questions you need. Thanks again ❤️

Comment on lines +511 to +513
ENV["HOMEBREW_UPGRADE_GREEDY"].present? &&
!cask_upgrade_greedy_latest? &&
!cask_upgrade_greedy_auto_updates?
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).

@jck112
Copy link
Contributor Author

jck112 commented Feb 29, 2024

Based on my understanding of the discussion it seems the generally preferred approach would be:

  1. Change --greedy to accept 3 options: all, latest, auto-updates.
  2. Make -g and --greedy an alias for --greedy all.
  3. Deprecate --greedy-latest and --greedy-auto-updates and make them an alias for --greedy latest and --greedy auto-updates respectively.
  4. Modify HOMEBREW_UPGRADE_GREEDY to accept the same values as --greedy (i.e. "all", "latest", "auto-updates").
  5. Add some error handling / messaging for invalid values passed to --greedy and HOMEBREW_UPGRADE_GREEDY.

@MikeMcQuaid
Copy link
Member

@jck112 Sounds right to me! Don't need to be all in this PR if you don't want but, if they are, that might be nice!

@jck112
Copy link
Contributor Author

jck112 commented Mar 4, 2024

I spent some time working on this but ran into a few implementation details that require some input:

  1. Which format is preferred: "--greedy=all" or "--greedy all"? The former format is supported by an OptionalArgument type and both formats are supported by the PlacedArgument type. The type is determined internally by OptionParser by passing the format "--arg=[ARG]" or "--arg [ARG]" respectively. The parser.rb code requires moderate modifications to support PlacedArgument options.
  2. A side-effect of changing --greedy to a flag, is that the short version -g can also accept an argument (e.g. -gall, -gauto-updates, -glatest). The only way to avoid this with OptionParser is to declare -g as a separate switch, which would also mean it would be listed seperately in documentation (e.g. brew help upgrade).

@MikeMcQuaid
Copy link
Member

@jck112 Do something like flag "--greedy=" and then args.greedy.presence&.then do |greedy| to validate the argument (like in cmd/cleanup.rb)

@jck112
Copy link
Contributor Author

jck112 commented Mar 5, 2024

Are you okay getting rid of -g and --greedy (i.e. force users to switch to --greedy all)?

Doing flag "--greedy=" will create an option with RequiredArgument type, which means OptionParser will throw an error if the user provides --greedy without an argument:

$ brew upgrade --greedy
Error: missing argument: --greedy

@MikeMcQuaid
Copy link
Member

Are you okay getting rid of -g and --greedy (i.e. force users to switch to --greedy all)?

@jck112 We can make it hidden: true but cannot remove it just yet (unfortunately) as we'll need to go through a deprecation cycle.

Doing flag "--greedy=" will create an option with RequiredArgument type, which means OptionParser will throw an error if the user provides --greedy without an argument:

Ah. Annoying. @homebrew/brew any thoughts on how best to address this temporarily?

Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Mar 27, 2024
@github-actions github-actions bot closed this Apr 3, 2024
@github-actions github-actions bot added the outdated PR was locked due to age label May 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age stale No recent activity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HOMEBREW_UPGRADE_GREEDY="auto-updates" and "latest"
7 participants