1222 Commits

Author SHA1 Message Date
Mike McQuaid
2d5eab2e1c
brew style --fix 2022-06-30 08:56:21 +01:00
Sean Molenaar
93ed7646b0
utils: allow developers to differ in ruby minor versions 2022-06-26 16:27:16 +02:00
Xuehai Pan
8f9f18fe59 utils/shfmt.sh: allow long shfmt arguments 2022-06-18 17:27:56 +08:00
Bo Anderson
02164a35db
Use ORIGINAL_PATHS over envs; reject nil PATH 2022-06-17 19:47:57 +01:00
Bo Anderson
e78665f4f7
Replace ENV["HOME"] with Dir.home 2022-06-17 19:47:57 +01:00
Bo Anderson
40bbdc659e
Fix some Style/FetchEnvVar offences 2022-06-17 19:47:57 +01:00
Bo Anderson
cd73e6bac5
Introduce more Ruby constants for values set by brew.sh 2022-06-17 19:47:57 +01:00
Bo Anderson
a10b16828f
utils/analytics: use curl shim 2022-06-17 19:47:56 +01:00
Bo Anderson
8d0ef708db
utils/curl: fix TLSv1.3 caching to be based on real paths 2022-06-17 19:47:56 +01:00
Bo Anderson
50437ca07e
Clear cached curl path where HOMEBREW_CURL changes 2022-06-17 19:47:55 +01:00
Bo Anderson
75d882b9d8
utils/pypi: handle HTTP error codes 2022-06-10 18:47:33 +01:00
Sam Ford
403a4d4a49
Curl: Check all responses for protected cookies
The response from a URL protected by Cloudflare may only provide a
relevant cookie on the first response but
`#curl_http_content_headers_and_checksum` only returns the headers of
the final response. In this scenario, `#curl_check_http_content` isn't
able to properly detect the protected URL and this is surfaced as an
error instead of skipping the URL.

This resolves the issue by including the array of response hashes in
the return value from `#curl_http_content_headers_and_checksum`, so
we can check all the responses in `#curl_check_http_content`.
2022-05-25 16:50:03 -04:00
Sam Ford
7b23bc64e5
Curl: Rename :status to :status_code
The return hash from `#curl_http_content_headers_and_checksum`
contains a `:status`, which is the status code of the last response.
This string value comes from `#parse_curl_response`, where the key is
`:status_code` instead.

Aligning these keys technically allows us to pass either of these
hashes to the `#url_protected_by_*` methods, as both contain
`:status_code` and `:headers` in the expected format.
2022-05-25 16:50:02 -04:00
Bo Anderson
580fb58f62
utils/github: take last artifact rather than first 2022-05-24 23:31:29 +01:00
Sam Ford
40b8fd3406
url_protected_by_*: Check multiple headers
Before `#parse_curl_output` was introduced and related methods were
updated to use it, `#url_protected_by_cloudflare?` and
`#url_protected_by_incapsula?` were checking a string of all the
headers from a response and using a regex to check related header
values.

However, when `#curl_http_content_headers_and_checksum` was updated
to use `#parse_curl_output` internally, the `:headers` value became
a hash generated by `#parse_curl_response`. The `#url_protected_by_*`
methods were updated to work with the hash value but this wasn't able
to fully replicate the previous behavior because
`#parse_curl_response` was only keeping the last instance of a given
header (maintaining pre-existing behavior). This is an issue for
these methods because they check `Set-Cookie` headers and there can
be multiple instances of this header in a response.

This commit updates these methods to handle an array of strings in
addition to the existing string support. This change ensures that
these methods properly check all `Set-Cookie` headers, effectively
reinstating the previous behavior.

Past that, this updates one of the early return values in
`#url_protected_by_cloudflare?` to be `false` instead of an implicit
`nil`. After adding a type signature to this method, it became clear
that it wasn't always returning a boolean value and this fixes it.
2022-05-06 10:51:26 -04:00
Sam Ford
94449d07c0
parse_curl_response: Handle duplicate headers
`Curl#parse_curl_response` only includes the last instance of a given
header in its `:headers` hash (replicating pre-existing behavior).
This is a problem for headers like `Set-Cookie`, which can appear more
than once in a response.

This commit addresses the issue by collecting duplicate headers into
an array instead. Headers that only appear once in the response will
still have a string value but headers that appear more than once will
be an array of strings. Whenever headers from `#parse_curl_response`
are used (directly or indirectly), it's important to conditionally
handle the expected types.
2022-05-06 10:51:22 -04:00
Alexander Bayandin
6643f58b49
utils/curl: get encoding from header 2022-05-04 00:13:56 +01:00
Alexander Bayandin
4575ddf909
utils/curl: force utf-8 encoding for text content 2022-05-02 13:57:51 +01:00
Sam Ford
b7a4360433
#parse_curl_output: increase default max_iterations
The `max_iterations` value in `#parse_curl_output` is only intended
to prevent its `while` loop from potentially turning into an endless
loop. This should only come into play in exceptional circumstances
but the current default value (5) is low enough that we're seeing it
under normal circumstances.

`#parse_curl_output` isn't intended to restrict the number of
redirections (this should be done using the `--max-redirs` option in
`curl) but it's effectively doing this in rare cases due to the low
`max_iterations` default. This is a problem because `curl` can
successfully return a response only to have `#parse_curl_output`
error in relation to `max_iterations`.

Originally the code in `#parse_curl_output` was used in the context
of livecheck, where it's not a huge issue if a check fails. However,
now the `#parse_curl_output` method is used in important parts of
brew like `#curl_download`. We've received a report of a download
failing with the "Too many redirects (max = 5)` error, effectively
preventing the user from installing a formula [from a third-party
tap].

Until we can come up with a more adaptive way of bounding this
`while` loop, I think we should simply raise the default to something
that's less likely to be encountered under normal circumstances
(e.g., 25).
2022-04-26 15:49:02 -04:00
Alexander Bayandin
c726385035
utils/curl: fix headers check for protected urls 2022-04-26 13:27:42 +01:00
Sam Ford
d6202384d7
Curl: Remove guard from certain parsing logic
The `#curl_http_content_headers_and_checksum` method previously
parsed responses from `curl` output even if `status.success?` wasn't
`true`. A recent commit of mine moved the parsing logic behind this
guard but it's now leading to a "...is not reachable" error when a URL
involves a large download that takes longer than 25 seconds to finish
and hits the timeout.

This commit resolves the issue for the time being by moving related
logic back to its previous location, where it isn't guarded by
`status.success?`.
2022-04-26 01:22:20 -04:00
Sam Ford
6bd2c831cd
Merge pull request #13181 from samford/livecheck/add-max-redirs-curl-arg
`Strategy`: Add `--max-redirs` to `DEFAULT_CURL_ARGS`
2022-04-25 14:25:36 -04:00
Sam Ford
3f7d9f82fc
#curl_download: default try_partial to false
When its `try_partial` argument is `true`, `#curl_download` makes a
`HEAD` request before downloading the file using `#curl`. Currently
`try_partial` defaults to `true`, so any `#curl_download` call that
doesn't explicitly specify `try_partial: false` will make a `HEAD`
request first. This can potentially involve several requests if the
URL redirects, so it can be a bit of unnecessary overhead when a
partial download isn't needed.

Partial downloads are generally only useful when we're working with
larger files, however there's currently only one place in brew where
`#curl_download` is used and this is the case:
`CurlDownloadStrategy`. The other `#curl_download` calls are fetching
smaller [text] files and don't need to support partial downloads.

This commit changes the default `try_partial` value to `false`,
making partial downloads opt-in rather than opt-out.

We want `try_partial` to continue to default to `true` in
`CurlDownloadStrategy` and there are various ways to accomplish this.
In this commit, I've chosen to update its `#initialize` method to
accept a `try_partial` argument that defaults to `true`, as this
value can also be used in classes that inherit from
`CurlDownloadStrategy` (e.g., `HomebrewCurlDownloadStrategy`). This
instance variable is passed to `#curl_download` in related methods,
effectively maintaining the previous `try_partial: true` value, while
also allowing this value to be overridden when necessary.

Other uses of `#curl_download` in brew are
`Formulary::FromUrlLoader#load_file` and
`Cask::CaskLoader::FromURILoader#load`, which did not provide a
`try_partial` argument but should have been using
`try_partial: false`. With the `try_partial: false` default in this
commit, these calls are now fine without a `try_partial` argument.

The only other use of `#curl_download` in brew is
`SPDX#download_latest_license_data!`. These calls were previously
using `try_partial: false` but we can now omit this argument with
the new `false` default (aligning with the above).
2022-04-22 14:23:08 -04:00
Sam Ford
2722fbe30e
#parse_curl_output: add max_iterations parameter
In cases where there may be more than five responses in `curl`
output to parse, we need to be able to control the `max_iterations`
of the `while` loop in `#parse_curl_output` to properly parse all
the responses.

For example, if we pass `--max-redirs 5` to `curl` and there are
exactly five redirections before the final response, the output would
contain a total of six responses and `#parse_curl_output` wouldn't
properly handle this (it would give a `Too many redirects` error).
`max_iterations` should be the maximum number of redirections + 1
(to account for any final response after the redirections), so we
need to be able to override this value when necessary.
2022-04-22 13:17:45 -04:00
Sam Ford
c5eeff941e
Curl: Update to use response parsing methods 2022-04-20 23:47:51 -04:00
Sam Ford
9171eb2e16
Curl: Add methods to parse response 2022-04-20 23:47:51 -04:00
Bo Anderson
17ee0eefb8
utils/github: fix errors with check suites without workflow runs 2022-04-12 13:42:14 +01:00
EricFromCanada
415f05ca31
bump: resume checking for TLS 1.3 support
macOS 12.3's shipping curl now supports TLS 1.3.
2022-04-11 22:59:33 -04:00
Michka Popoff
a5c29fff2d
utils/github.rb: convert pr to integer
Follow up adter #13124

I made the choice to convert the pr variable to an integer
at the very end and adjust the tests.

It would be maybe more consistent to work with an integer
everywhere, but this needs a more careful analysis and we
are in a hurry to fix the homberew-core upload CI

Fixes:
2022-04-11T20:19:34.1395885Z [31mError:[0m : Variable $pr of type Int! was provided invalid value
2022-04-11T20:19:34.1398279Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/utils/github/api.rb:261:in `open_graphql'
2022-04-11T20:19:34.1399774Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/utils/github.rb:310:in `get_workflow_run'
2022-04-11T20:19:34.1403699Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:418:in `block (4 levels) in pr_pull'
2022-04-11T20:19:34.1405233Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:417:in `each'
2022-04-11T20:19:34.1406723Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:417:in `block (3 levels) in pr_pull'
2022-04-11T20:19:34.1408112Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/lib/ruby/2.6.0/fileutils.rb:128:in `chdir'
2022-04-11T20:19:34.1408986Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/lib/ruby/2.6.0/fileutils.rb:128:in `cd'
2022-04-11T20:19:34.1409813Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:400:in `block (2 levels) in pr_pull'
2022-04-11T20:19:34.1410671Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
2022-04-11T20:19:34.1411495Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:399:in `block in pr_pull'
2022-04-11T20:19:34.1412250Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:388:in `each'
2022-04-11T20:19:34.1413056Z /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/dev-cmd/pr-pull.rb:388:in `pr_pull'
2022-04-11 22:38:42 +02:00
Bo Anderson
3e75b165ae
utils/github: rewrite get_workflow_run using GraphQL 2022-04-11 20:35:03 +01:00
Adrian Ho
f5f4d5b082 github_api: fix recommended PAT URL
Closes #13030.
2022-03-24 10:18:02 +08:00
Issy Long
84632598a0
utils/github: Add a branch_exists? method
- I wrote this as part of
  https://github.com/issyl0/homebrew-maintenance-utils/blob/main/cmd/find-invalid-head-branches.rb,
  as I needed to check if a branch exists on a repo, and thought I'd properly add
  it in case it's useful to others.
2022-03-05 21:29:19 +00:00
Niklas Higi
00f209e16e
Recommend interactive usage of fish_add_path
Since the `fish_add_path` command modifies a universal Fish variable
(which is automatically persisted to a file) it's unnecessary to run it
again every time a new shell is opened.
2022-02-05 16:29:09 +01:00
Carlo Cabrera
2b60a99d4a
Revert "shebang: raise error if no rewriting"
This is causing failures when attempting to rewrite shebangs during the
cleanup stage of `brew install`.

See, for example, Homebrew/homebrew-core#94323,
Homebrew/homebrew-core#94321.

This reverts commit 7e6be5eb4474ed9eaa4b8e9a5a45e3340186840c.
2022-02-02 20:44:03 +08:00
Branch Vincent
7e6be5eb44
shebang: raise error if no rewriting 2022-02-01 00:17:50 -05:00
Nanda H Krishna
a7271f8900
brew style --fix 2022-01-18 21:13:39 -05:00
Mike McQuaid
af6d995de8
dev-cmd/bump: add switch to open pull requests.
This enables the simplification of
https://github.com/Homebrew/actions/blob/master/bump-formulae/main.rb
and exposing this workflow to more Homebrew users.
2022-01-12 17:31:55 +00:00
Mike McQuaid
a9e348ce14
utils/pypi: ensure pipgrip is installed.
Rather than failing if it isn't installed: install it if needed.
2022-01-11 17:12:04 +00:00
Rylan Polster
feb93167ad
Rename and fix Formatter:wrap to Formatter.format_help_text 2022-01-08 23:13:08 -05:00
Mike McQuaid
b09f421027
repology: always use Homebrew curl.
This seems to be required even with TLSv1.3 support now.

Also, while we're here, improve the error handling/output.
2022-01-03 13:17:12 +00:00
Steve Peters
d53dab62c9
bump-revision: add --remove-bottle-block option
This removes a bottle block for the specified formulae
while bumping the revision.
2021-12-26 03:42:39 -08:00
Rylan Polster
2e4185a525
Fix brew typecheck 2021-12-24 21:15:21 -05:00
Rylan Polster
2e6b6ab3a2
Fix style 2021-12-24 21:15:21 -05:00
Bob Lail
31a831ae11 Bypass searching for open Issues when failing to install a formula without a tap
Given a formula with a broken build, if you install it locally with `brew install path/to/formula.rb`, when the build fails, Homebrew will attempt to [search for open issues on the tap](073c4177b5/Library/Homebrew/exceptions.rb (L489)); but in this case `formula.tap` is `nil` and `tap.full_name` would raise a `NoMethodError` yielding this output:

```
$ brew install ./erg.rb
Error: Failed to load cask: ./erg.rb
Cask 'erg' is unreadable: wrong constant name #<Class:0x00007fd89b246cd0>
Warning: Treating ./erg.rb as a formula.
==> Downloading https://github.com/square/erg/archive/v1.1.1.tar.gz
Already downloaded: /Users/lail/Library/Caches/Homebrew/downloads/54e3fce84302901d76d50b53aa7fe760cfcf81c9842a232d6b29e771de6ec9c5--erg-1.1.1.tar.gz
Warning: Cannot verify integrity of '54e3fce84302901d76d50b53aa7fe760cfcf81c9842a232d6b29e771de6ec9c5--erg-1.1.1.tar.gz'.
No checksum was provided for this resource.
For your reference, the checksum is:
  sha256 "8dbcff3dfd67b8f6e8f2dfd4f57cf818ce0cd6ce4b52566611e698fc8778507f"
==> go get github.com/square/erg
Last 15 lines from /Users/lail/Library/Logs/Homebrew/erg/01.go:
2021-12-02 16:45:31 +0000

go
get
github.com/square/erg

go: downloading github.com/square/erg v1.2.1
go: downloading vbom.ml/util v0.0.3
go: downloading vbom.ml/util/sortorder v1.0.2
go: downloading github.com/square/grange v0.0.0-20201015231752-48d66acdd125
go: downloading github.com/deckarep/golang-set v0.0.0-20170202203032-fc8930a5e645
go: downloading github.com/fvbommel/sortorder v1.0.1
go: downloading github.com/orcaman/concurrent-map v0.0.0-20160823150647-8bf1e9bacbf6
github.com/square/erg imports
	vbom.ml/util/sortorder: cannot find module providing package vbom.ml/util/sortorder

Do not report this issue to Homebrew/brew or Homebrew/core!

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:64:in `issues_for_formula': undefined method `full_name' for nil:NilClass (NoMethodError)
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:489:in `fetch_issues'
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:485:in `issues'
	from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:539:in `dump'
	from /usr/local/Homebrew/Library/Homebrew/brew.rb:155:in `rescue in <main>'
	from /usr/local/Homebrew/Library/Homebrew/brew.rb:143:in `<main>'
/usr/local/Homebrew/Library/Homebrew/formula.rb:2306:in `block in system': Failed executing: go get github.com/square/erg (BuildError)
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:2242:in `open'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:2242:in `system'
	from /Users/lail/Code/homebrew-formulas/erg.rb:13:in `install'
	from /usr/local/Homebrew/Library/Homebrew/build.rb:172:in `block (3 levels) in install'
	from /usr/local/Homebrew/Library/Homebrew/utils.rb:588:in `with_env'
	from /usr/local/Homebrew/Library/Homebrew/build.rb:134:in `block (2 levels) in install'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:1297:in `block in brew'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:2472:in `block (2 levels) in stage'
	from /usr/local/Homebrew/Library/Homebrew/utils.rb:588:in `with_env'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:2471:in `block in stage'
	from /usr/local/Homebrew/Library/Homebrew/resource.rb:126:in `block (2 levels) in unpack'
	from /usr/local/Homebrew/Library/Homebrew/download_strategy.rb:115:in `chdir'
	from /usr/local/Homebrew/Library/Homebrew/download_strategy.rb:115:in `chdir'
	from /usr/local/Homebrew/Library/Homebrew/download_strategy.rb:102:in `stage'
	from /usr/local/Homebrew/Library/Homebrew/resource.rb:122:in `block in unpack'
	from /usr/local/Homebrew/Library/Homebrew/mktemp.rb:63:in `block in run'
	from /usr/local/Homebrew/Library/Homebrew/mktemp.rb:63:in `chdir'
	from /usr/local/Homebrew/Library/Homebrew/mktemp.rb:63:in `run'
	from /usr/local/Homebrew/Library/Homebrew/resource.rb:208:in `mktemp'
	from /usr/local/Homebrew/Library/Homebrew/resource.rb:121:in `unpack'
	from /usr/local/Homebrew/Library/Homebrew/resource.rb:96:in `stage'
	from /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/lib/ruby/2.6.0/forwardable.rb:230:in `stage'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:2451:in `stage'
	from /usr/local/Homebrew/Library/Homebrew/formula.rb:1290:in `brew'
	from /usr/local/Homebrew/Library/Homebrew/build.rb:129:in `block in install'
	from /usr/local/Homebrew/Library/Homebrew/utils.rb:588:in `with_env'
	from /usr/local/Homebrew/Library/Homebrew/build.rb:124:in `install'
	from /usr/local/Homebrew/Library/Homebrew/build.rb:224:in `<main>'
```
2021-12-02 10:56:44 -06:00
Bo Anderson
c6ca375d5a
utils/ruby.sh: fix error with older Bash
Fixes #12472.
2021-12-02 02:14:11 +00:00
XuehaiPan
d1aac8857a tests/utils/git_spec: update tests for ensure_formula_installed! 2021-11-24 00:30:26 +08:00
XuehaiPan
3376479e95 utils: add method ensure_formula_installed! 2021-11-23 22:48:39 +08:00
Mike McQuaid
07f14c32e9
Merge pull request #12423 from FnControlOption/deps
deps: add `--graph` and `--dot` switches
2021-11-17 10:49:19 +00:00
fn ⌃ ⌥
a188215d69 deps: minor refactoring 2021-11-16 08:45:59 -08:00
Carlo Cabrera
105d1f9cfc
utils/github/actions: make file a mandatory argument
An annotation is pretty useless if you don't specify a file to place the
annotation on, so let's just require it.
2021-11-16 23:42:03 +08:00