188 Commits

Author SHA1 Message Date
Mike McQuaid
b1559f38a0
Add HOMEBREW_UPGRADE_GREEDY_CASKS
A space-separated list of casks. Homebrew will act as if `--greedy`
was passed when upgrading any cask on this list.
2025-02-25 15:34:49 +00:00
Eric Knibbe
99de228fc2
docs: various manpage grammar fixes 2025-02-05 13:38:39 +01:00
Mike McQuaid
7ff99e2353
Use ~ instead of ${HOME}
Partial revert of Homebrew/brew#19153
See https://github.com/Homebrew/brew/pull/19153#discussion_r1930678587
2025-01-27 15:19:59 +00:00
Mike McQuaid
bbf5a9f479
env_config: use environment variables consistently
- use e.g. `$HOMEBREW_*` for cases where only the environment variable
  is the entire backtick-quoted string
- use e.g. `${HOMEBREW_*}` for cases where the environment variable is
  part of a backtick-quoted string to make clear what parts are variable
  and what parts are not
- use `export HOMEBREW_*=...` for cases where we're talking about
  setting the environment variable (because it likely needs to be
  exported to work how they want)

Inspired by https://github.com/Homebrew/homebrew-bundle/pull/1579 making
similar changes for Homebrew/homebrew-bundle.
2025-01-27 14:21:27 +00:00
Mike McQuaid
bb74d26a93
Fix HOMEBREW_*BREW_WRAPPER behaviour
- handle reading from variables that may not be defined yet
- avoid unnecessary handling of defined variables
- fix incorrect `env_config.rbi` file entry
- add `HOMEBREW_NO_FORCE_BREW_WRAPPER` to disable
  `HOMEBREW_FORCE_BREW_WRAPPER` functionality if needed
2025-01-08 14:10:55 +00:00
Mike McQuaid
e9b4979f40
Add support for Homebrew wrappers
Allow the ability for a system administrator to use
`HOMEBREW_BREW_WRAPPER` and `HOMEBREW_FORCE_BREW_WRAPPER` variables to
enforce the usage of a particular `brew` command for non-trivial (e.g.
`brew --prefix` is considered trivial, it doesn't need to write to the
prefix) Homebrew commands.

This also introduces a `HOMEBREW_ORIGINAL_BREW_FILE` variable for some
internal usage; `HOMEBREW_BREW_FILE` was being used internally for
both "how should we shell out to Homebrew" and "what should we use
to check permissions on Homebrew". `HOMEBREW_ORIGINAL_BREW_FILE` is
now used just for the latter case.

Inspired by conversation in
https://github.com/Homebrew/homebrew-bundle/pull/1551 which suggested
this was worth fixing in wider than just `brew bundle`.
2025-01-07 17:40:18 +00:00
Mike McQuaid
d87d336c82
Add HOMEBREW_FORCE_API_AUTO_UPDATE
If set, this will update the Homebrew API formula or cask data even if
`HOMEBREW_NO_AUTO_UPDATE` is set.

This is useful in cases where you want to update the cached API data but
don't want to update Homebrew itself.

Co-authored-by: Bo Anderson <mail@boanderson.me>
2025-01-07 16:27:44 +00:00
Issy Long
683f85f4b0
Merge pull request #18984 from Homebrew/livecheck-skip-autobumped-formulae
dev-cmd/livecheck: Skip autobumped formulae
2025-01-04 15:27:16 +00:00
Issy Long
ce562c312b
Alphabetical envvars; better variable names; just the one loop 2025-01-04 14:26:05 +00:00
Issy Long
a71786a332
Flag and envvar to include autobumped formulae
- This is useful for maintainers to check the full range of livecheck functionality.
2025-01-02 17:20:38 +00:00
Issy Long
ae952482a7
env_config: Improve the deprecated envvar message
Before:

```
❯ HOMEBREW_NO_ANALYTICS=0 brew formula-analytics --days-ago=2
Error: Calling HOMEBREW_NO_ANALYTICS=0 is deprecated! Use If you wish to enable HOMEBREW_NO_ANALYTICS, use HOMEBREW_NO_ANALYTICS=1
If you wish to disable HOMEBREW_NO_ANALYTICS, use HOMEBREW_NO_ANALYTICS= (an empty value). instead.
```

After:

```
❯ HOMEBREW_NO_ANALYTICS=0 brew formula-analytics --days-ago=2
Error: Calling HOMEBREW_NO_ANALYTICS=0 is deprecated! Use HOMEBREW_NO_ANALYTICS=1 to enable and HOMEBREW_NO_ANALYTICS= (an empty value) to disable instead.
```
2024-12-28 22:34:40 +00:00
Carlo Cabrera
1fbe4366a0
Support setting GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL
Our autobump workflow sets the author and committer to the user who
triggered the workflow, defaulting to @BrewTestBot for scheduled runs.

This can be confusing for maintainers when GitHub shows up as
"Unverified" because the commit is signed with @BrewTestBot's key.[^1]

Let's fix that by configuring our autobump workflow to always commit as
@BrewTestBot, so that the committer matches the GPG signature. To do
that, we need to add support for setting `GIT_COMMITTER_NAME` and
`GIT_COMMITTER_EMAIL`.

[^1]: See, for example, Homebrew/homebrew-core#197234.
2024-11-11 18:45:38 +08:00
Mike McQuaid
dd7d91bc6f
Improve/fix HOMEBREW_FORBIDDEN_LICENSES handling
`HOMEBREW_FORBIDDEN_LICENSES` now actually checks for valid SPDX license
identifiers rather than requiring the user to guess.

When an identifier is invalid, it will be ignore and warned about
instead.
2024-10-17 08:34:03 +01:00
Carlo Cabrera
78065c5781
env_config: deprecate setting boolean vars to falsy values
The way we handle boolean environment variables is a bit unfortunate.
For example, setting `HOMEBREW_EVAL_ALL=false` actually enables
`HOMEBREW_EVAL_ALL`.

Let's fix this by deprecating setting boolean environment variables to
common false-y values (`false`, `0`, `nil`, `no`, and `off`) so that we
can later ignore these false-y values when reading boolean environment
variables.
2024-09-25 21:15:53 +08:00
Mike McQuaid
e3a1a9dccf
Improve locking UX
My experience recently playing around with our locking behaviour is
that, while mostly seamless and not seen by users, it's leaks
implementation details a bit too heavily.

As a result, the following improvements are in this commit:
- Ensure that, whenever possible, we tell the user the actual command
  that is holding a given lock instead of the lock name (an internal
  implementation detail)
- Make the locking error output a little more consistent and user
  friendly
- Add a `DownloadLock` class to simplify locking downloads
- Add a `HOMEBREW_LOCK_CONTEXT` variable to allow adding additional
  context for logging error messages
- Lock paths and leave deciding how this translates to lock names up
  to the locking code itself
- Lock the Cellar/Caskroom paths explicitly rather than implicitly

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-07-30 17:51:02 +01:00
Bo Anderson
10cbf191dc
Add env to disable finding packages from paths 2024-07-25 11:37:44 +01:00
Bo Anderson
d39a3a3030
Merge pull request #17788 from Homebrew/more-sorbet-strict
sorbet: Bump more files to `typed: strict`
2024-07-25 02:23:23 +01:00
Issy Long
6ad0ebd5b4
env_config: Tighten hash types some more
Co-authored-by: Bo Anderson <mail@boanderson.me>
2024-07-24 23:16:58 +01:00
Bo Anderson
93dbb9593d
Add env to disable Debrew 2024-07-24 06:16:18 +01:00
Issy Long
3290b7e616
env_config: Bump to Sorbet typed: strict 2024-07-17 16:02:01 -04:00
Mike McQuaid
b8ff4b3d23
Widen attestation verification rollout
Take 2 of https://github.com/Homebrew/brew/pull/17692 but with:

- provide and document `HOMEBREW_NO_VERIFY_ATTESTATIONS`
- don't try to run unless there's GitHub credentials
- don't try to run unless `gh` is installed
- don't try to run in CI

While we're here:
- split out a `Homebrew::EnvConfig.devcmdrun?` helper method
- add some missing `Homebrew::EnvConfig.github_api_token` presence
  checks
2024-07-14 11:50:57 -04:00
Bo Anderson
2b454328ca
Remove non-Portable Ruby bootsnap support 2024-06-19 16:08:05 +01:00
Mike McQuaid
ba6ec7066b
Revert "Revert "Enable HOMEBREW_AUTOREMOVE by autoremove_default"" 2024-05-26 15:39:45 +01:00
Carlo Cabrera
ffd6c1f5c3
Revert "Enable HOMEBREW_AUTOREMOVE by autoremove_default"
`autoremove` is destructive, and it can be difficult for users to
recover from it occuring when they weren't expecting it.

Fixes #17363
Fixes Homebrew/discussions#5395

This reverts commit 3d114161b3c3f1a95b94e8530f5bc45bb44bbbd9.
This reverts commit efb14a0ec264c4ef408dbbd5330905dd230e979c.
2024-05-25 23:19:42 +08:00
Mike McQuaid
0c1766510a
env_config: add HOMEBREW_BUNDLE_USER_CACHE.
Used to configure `BUNDLE_USER_CACHE`.
2024-05-18 00:08:42 +09:00
Mike McQuaid
9586473f77
brew style --fix 2024-05-17 14:25:54 +09:00
Mike McQuaid
a37864da0f
Add HOMEBREW_ARTIFACT_DOMAIN_NO_FALLBACK
This fits the use-case I've heard multiple times where people want to
rely exclusively on their artifact provider.

Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2024-05-14 21:45:37 +09:00
Mike McQuaid
3d114161b3
Enable HOMEBREW_AUTOREMOVE by autoremove_default
Enabled `HOMEBREW_AUTOREMOVE` by default, and added
`HOMEBREW_NO_AUTOREMOVE` to disable it.

Co-authored-by: Ruoyu Zhong <zhongruoyu@outlook.com>
2024-05-09 13:47:52 +01:00
Carlo Cabrera
071dd93ef2
env_config: add HOMEBREW_ALLOWED_TAPS
This is the inverse of `HOMEBREW_FORBIDDEN_TAPS`.
2024-05-03 14:44:05 +01:00
Mike McQuaid
b5f857b627
Merge pull request #17081 from alebcay/formula-offline-phases
Support for opt-in network isolation in build/test sandboxes
2024-04-23 08:30:10 +01:00
Caleb Xu
c938f89c28
env_config: new variables for allowing/denying network access 2024-04-22 22:36:00 -04:00
Markus Reiter
4b432c7ea4
Explicitly mark non-private APIs. 2024-04-22 21:16:49 +02:00
Mike McQuaid
c683e011b8
Merge pull request #17049 from trail-of-forks/ww/attestation
attestation: add initial attestation helpers, integrate into `brew install`
2024-04-12 15:52:51 +01:00
Issy Long
dd5ea99f58
Alphabetize EnvConfig::ENVS and regenerate docs 2024-04-11 17:58:08 +01:00
William Woodruff
578c2bc9da
rubocop fixes
Signed-off-by: William Woodruff <william@yossarian.net>
2024-04-08 16:21:31 -04:00
William Woodruff
48e39bb51d
attestation: add initial attestation helpers
Adds the basic attestation verification APIs, as well
as a pre-pour check against `HOMEBREW_VERIFY_ATTESTATIONS`
that verifies the attestation (or backfill as necessary)
for bottles from homebrew-core.

Signed-off-by: William Woodruff <william@yossarian.net>
2024-04-08 16:18:15 -04:00
Mike McQuaid
1474806527
Add more HOMEBREW_FORBIDDEN_* configuration
We already had `HOMEBREW_FORBIDDEN_LICENSES` but this commit adds
`HOMEBREW_FORBIDDEN_CASKS`, `HOMEBREW_FORBIDDEN_FORMULAE` and
`HOMEBREW_FORBIDDEN_TAPS` for also forbidding those.

Relatedly, add `HOMEBREW_FORBIDDEN_OWNER` and
`HOMEBREW_FORBIDDEN_OWNER_CONTACT` to allow customising these
messages.

There were no existing tests for `HOMEBREW_FORBIDDEN_LICENSES` so have
added more tests for all of these checks.

Co-authored-by: Bo Anderson <mail@boanderson.me>
2024-04-08 16:38:32 +01:00
Mike McQuaid
21d99c5e89
brew.rb: tell more people to not report issues.
- We should tell people to not report issues if they are running in an
  unsupported configuration.
- We should tell people to run `brew update` before reporting issues if
  they have `HOMEBREW_NO_AUTO_UPDATE` set.
- We should tell people to not report issues in more types of
  exceptions.
- Warn people in `HOMEBREW_NO_AUTO_UPDATE` documentation.
- DRY up `brew.rb` exception handling.

Co-authored-by: Colin Dean <colindean@users.noreply.github.com>
2024-04-03 08:16:01 +01:00
Eric Knibbe
e63b1f4da5
docs: monospace suggested values 2024-02-04 15:42:26 +01:00
Patrick Linnane
6c3eaf6832
Manpage: update GitHub rate limit link 2023-11-04 12:48:00 -07:00
Mike McQuaid
eb1355e624
Add HOMEBREW_SUDO_THROUGH_SUDO_USER
This environment variable allows telling Homebrew to use the `SUDO_USER`
variable to `sudo` through that user when Homebrew (Cask) attempts to
run `sudo`.

While we're here, clarify in some messaging that we're running `sudo`
and that that's the password we're asking for; the specific password is
configuration dependent and not the specific password for the user.

Similarly, remove the `Package installers may write to any location`
output; it's kinda spammy and doesn't feel like the right place.
2023-09-29 18:49:44 +01:00
Eric Knibbe
c493b5e680
cmd+dev-cmd: fixes for output formatting 2023-09-11 02:29:57 -04:00
Eric Knibbe
931f762598
docs+rubydoc: various grammar/wording fixes 2023-09-11 02:26:37 -04:00
Mike McQuaid
98c8dd01e4
Merge pull request #15868 from MikeMcQuaid/more_install_from_api_again
brew.sh: don't set `HOMEBREW_NO_INSTALL_FROM_API` automatically.
2023-08-15 14:27:06 +01:00
Mike McQuaid
1481eac57c
brew.sh: don't set HOMEBREW_NO_INSTALL_FROM_API automatically.
My understanding is that now https://github.com/Homebrew/brew/pull/15778
has been merged this should now work fine on both older macOS versions
and non-default prefixes so let's try this again.
2023-08-15 11:42:02 +01:00
Clint Harrison
4ade9351e4
Allow HOMEBREW_CURLRC to provide a path for curl --config
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
Co-authored-by: Carlo Cabrera <30379873+carlocab@users.noreply.github.com>
2023-08-15 11:29:02 +01:00
eugenesvk
2c7c064040 Allow hiding new formula/cask sections on update 2023-08-07 20:38:54 +07:00
Mike McQuaid
375a7ee8dc
Allow configuring Homebrew with .env files
For a long time people have requested some sort of configuration files
for Homebrew. Now: here's the first version of that.

Similarly to how you can configure Git for a system, a repository or
a user: you can configure Homebrew for a system, a prefix or a user.

The system-wide configuration file is `/etc/homebrew/brew.env`, the
prefix-specific configuration file is
`$HOMEBREW_PREFIX/etc/homebrew/brew.env`
and the user-specific configuration file is `~/.homebrew/brew.env`.

As we need to read these files from Bash in `bin/brew` (so they can)
influence functionality ASAP: they are in a simple format that Bash
can read. It may be that we have more complex array or hash data in
future that's configured through JSON or YAML (most likely JSON as we
use it more) and stored in a `brew.json`/`brew.yaml` file in the same
directory.

As this is relying on `eval` in Bash which is fairly dangerous: we
filter the lines with a regex to ensure we're only permitting setting
`HOMEBREW_*` variables and nothing more.

To give a bit of power to system administrators, the
`HOMEBREW_SYSTEM_ENV_TAKES_PRIORITY` variable can be set in
`/etc/homebrew/brew.env` to ensure that the system-wide configuration
file is loaded last and overrides any prefix or user settings.

Now that we have an actual location for configuration files, let's also
change the `brew livecheck` watchlist configuration file to be in this
directory and deprecate the existing location. As this is a developer
command and the mitigation is to just move the file: we don't need to
follow the normal deprecation process here.
2023-07-28 17:17:14 +01:00
Mike McQuaid
21d8f82056
Add/use HOMEBREW_INSTALL_FROM_API_UNSUPPORTED
When we're automatically setting `HOMEBREW_NO_INSTALL_FROM_API`
when on an old macOS version or with a non-default prefix (e.g. cases
where you're going to be mostly building from source).

My initial plan was to set
`HOMEBREW_AUTOMATICALLY_SET_NO_INSTALL_FROM_API` in these cases but
it's used differently enough it made sense to add another internal
variable instead: `HOMEBREW_INSTALL_FROM_API_UNSUPPORTED`.

At the moment this is only used to avoid printing the "You have set
`HOMEBREW_NO_INSTALL_FROM_API`" message inside `brew update` but may
make sense to use in other places over time.

Ideally, we'll get rid of these automatic sets of
`HOMEBREW_NO_INSTALL_FROM_API` and perhaps even the variable entirely.
2023-07-27 12:36:54 +01:00
apainintheneck
c9dea04bd4 cmd/install: upgrade already installed casks
Previously, the behavior was to warn users that a cask was already
installed and then skip modifying the installed version. This is
different to how we handled things with formulas. For them we would
upgrade any already installed formulas. This just brings casks in line
with what we already do with formulas.

Changes:
- cmd/install: Upgrade already installed casks if HOMEBREW_NO_INSTALL_UPGRADE
  is not set
- env_config: Update wording of HOMEBREW_NO_INSTALL_UPGRADE to include casks
- remove error that was only used to alert about already installed casks

Note:
- The upgrade command for casks defaults to --greedy when you pass named casks
  to the command which means that this will always default to that behavior
  since you must specify the name of the cask when installing.
2023-07-23 18:50:39 -07:00