Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
41.43k stars 9.74k forks source link

Livecheck PageMatch strategy appears to be broken #11882

Closed cesarcoatl closed 3 years ago

cesarcoatl commented 3 years ago

brew config output

HOMEBREW_VERSION: 3.2.8-19-g8d2811e
ORIGIN: https://github.com/Homebrew/brew
HEAD: 8d2811ea71e0d121cb0b06e160ddb1680c081d68
Last commit: 4 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 5314b376a917de9bd4ed145e94f54ec0013706a7
Core tap last commit: 25 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_BAT: set
HOMEBREW_CASK_OPTS: []
HOMEBREW_CLEANUP_MAX_AGE_DAYS: 3
HOMEBREW_EDITOR: nano
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_GIT_EMAIL: thecesrom@gmail.com
HOMEBREW_GIT_NAME: César Román
HOMEBREW_MAKE_JOBS: 4
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
CPU: quad-core 64-bit ivybridge
Clang: 12.0.0 build 1200
Git: 2.33.0 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
CLT: 12.0.0.32.29
Xcode: N/A

brew doctor output

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and which additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew-provided
script of the same name. We found the following "config" scripts:
  /Users/thecesrom/.pyenv/shims/python2-config
  /Users/thecesrom/.pyenv/shims/python2.7-config
  /Users/thecesrom/.pyenv/shims/python3.9-config
  /Users/thecesrom/.pyenv/shims/python-config
  /Users/thecesrom/.pyenv/shims/python3-config

What were you trying to do (and why)?

I tried to run brew livecheck and some casks are failing. All of them are using the PageMatch strategy extracting certain fields.

My .brew_livecheck_watchlist file looks like this:

azure-data-studio
azure-data-studio-insiders
black
flake8
isort
pre-commit
pycharm-ce
pyenv
rectangle
tunnelbear
visual-studio-code
visual-studio-code-insiders

What happened (include all command output)?

$ brew livecheck
azure-data-studio : 1.31.1 ==> 1.32.0
Error: azure-data-studio-insiders: Unable to get versions
black : 21.7b0 ==> 21.7b0
flake8 : 3.9.2 ==> 3.9.2
isort : 5.9.3 ==> 5.9.3
pre-commit : 2.14.0 ==> 2.14.0
Error: pycharm-ce: Unable to get versions
pyenv : 2.0.4 ==> 2.0.4
rectangle : 0.48,53 ==> 0.48,53
tunnelbear : 4.1.6,1614795843 ==> 4.1.7,1628781930
visual-studio-code : 1.59.0 ==> 1.59.0
Error: visual-studio-code-insiders: Unable to get versions

I also found other casks using the same strategy:

$ brew livecheck --debug alfred clion steam unity azure-data-studio-insiders visual-studio-code-insiders

Cask:             alfred
Livecheckable?:   Yes

URL:              https://www.alfredapp.com/app/update4/general.xml
Strategy:         PageMatch
Error: alfred: Unable to get versions

----------

Cask:             azure-data-studio-insiders
Livecheckable?:   Yes

URL:              https://azuredatastudio-update.azurewebsites.net/api/update/darwin/insider/VERSION
Strategy:         PageMatch
Error: azure-data-studio-insiders: Unable to get versions

----------

Cask:             clion
Livecheckable?:   Yes

URL:              https://data.services.jetbrains.com/products/releases?code=CL&latest=true&type=release
Strategy:         PageMatch
Error: clion: Unable to get versions

----------

Cask:             steam
Livecheckable?:   Yes

URL:              https://store.steampowered.com/oldnews/?feed=steam_client
Strategy:         PageMatch
Error: steam: Unable to get versions

----------

Cask:             unity
Livecheckable?:   Yes

URL:              https://public-cdn.cloud.unity3d.com/hub/prod/releases-darwin.json
Strategy:         PageMatch
Error: unity: Unable to get versions

----------

Cask:             visual-studio-code-insiders
Livecheckable?:   Yes

URL:              https://update.code.visualstudio.com/api/update/darwin-universal/insider/VERSION
Strategy:         PageMatch
Error: visual-studio-code-insiders: Unable to get versions

What did you expect to happen?

I expected the command to succeed and check if the versions match or must be updated.

Step-by-step reproduction instructions (by running brew commands)

1. Run `brew livecheck alfred azure-data-studio-insiders`
2. Have command succeed checking version
MikeMcQuaid commented 3 years ago

CC @samford in case this relates to recent work

samford commented 3 years ago

I looked into this and it was introduced in 26821301e74b3b4a559877c97ce8af1b8da8f545 and relates to the added early return conditions in PageMatch#find_versions. I had tested this on homebrew/core without any issue but I only tested a few casks (not all of homebrew/cask).

The basic issue here is that PageMatch requires a regex to function but a number of livecheck blocks in casks (e.g., alfred) don't use #regex and inline the regex in the strategy block instead. I've warned against this in general and some newer homebrew/cask livecheck blocks correctly use #regex and pass the value into the strategy block but there are still a number of older PageMatch strategy blocks that don't. These are the ones that were broken by this change.

I'll open a PR to update the early return conditions to require url and either regex or a block, so the checks that are currently broken will work again. It wasn't my intention to break these checks and it was simply an oversight.

In the long run, a lot of the livecheck blocks in casks with simple strategy block like alfred should move the regex into a #regex call and pass it into the strategy block. This has always been the standard pattern in homebrew/core and it's starting to get picked up in homebrew/cask but there are still a lot of older strategy blocks that need to be updated.

That said, there are some cask strategy blocks where more than one regex is required to identify the full version and neither of the regexes can be viewed as the primary regex. Those are exceptional cases where we don't have any choice but to inline the regexes in the strategy block and the updated early return conditions will support that scenario. [One way to improve this situation would be to allow #regex to accept a regex array or maybe a hash with Regexp values, so we could establish all the used regexes this way. I'll have to look into something like this, as it would allow us to standardize on always using #regex and also allow us to surface all the used regexes in the debug and JSON output.]

samford commented 3 years ago

11888 has been merged, so this should be fixed after a brew update. Sorry for the temporary disruption!