Skip to content

Commit 0cd1e6c

Browse files
authored
Merge pull request #20024 from Homebrew/docs-livecheck-review
docs/Brew-Livecheck review
2 parents f3c7935 + 493f2aa commit 0cd1e6c

File tree

1 file changed

+46
-12
lines changed

1 file changed

+46
-12
lines changed

docs/Brew-Livecheck.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
---
2-
last_review_date: "1970-01-01"
2+
last_review_date: 2025-05-28
33
---
44

55
# `brew livecheck`
66

77
The `brew livecheck` command finds the newest version of a formula or cask's software by checking upstream. Livecheck has [strategies](https://rubydoc.brew.sh/Homebrew/Livecheck/Strategy) to identify versions from various sources, such as Git repositories, websites, etc.
88

9-
## Behavior
9+
## Behaviour
1010

1111
When livecheck isn't given instructions for how to check for upstream versions, it does the following by default:
1212

13-
1. For formulae: Collect the `stable`, `head`, and `homepage` URLs, in that order (resources simply use their `url`). For casks: Collect the `url` and `homepage` URLs, in that order.
13+
1. Collect a list of URLs to check.
14+
* For formulae: use their `stable`, `head`, and `homepage` URLs, in that order.
15+
* For formula resources: use their `url`.
16+
* For casks: use their `url` and `homepage` URLs, in that order.
1417
1. Determine if any strategies apply to the first URL. If not, try the next URL.
1518
1. If a strategy can be applied, use it to check for new versions.
1619
1. Return the newest version (or an error if versions could not be found at any available URLs).
1720

18-
It's sometimes necessary to override this default behavior to create a working check. If a source doesn't provide the newest version, we need to check a different one. If livecheck doesn't correctly match version text, we need to provide an appropriate regex or `strategy` block.
21+
It's sometimes necessary to override this default behaviour to create a working check. If a source doesn't provide the newest version, we need to check a different one. If livecheck doesn't correctly match version text, we need to provide an appropriate regex or `strategy` block.
1922

20-
This can be accomplished by adding a `livecheck` block to the formula/cask/resource. For more information on the available methods, please refer to the [`Livecheck` class documentation](https://rubydoc.brew.sh/Livecheck).
23+
This can be accomplished by adding a `livecheck` block to the formula/cask/resource. For more information on the available methods, please refer to the [`Livecheck` class](https://rubydoc.brew.sh/Livecheck) documentation.
2124

2225
## Creating a check
2326

@@ -47,9 +50,9 @@ The `livecheck` block regex restricts matches to a subset of the fetched content
4750

4851
* **Regexes should be made case insensitive, whenever possible**, by adding `i` at the end (e.g. `/.../i` or `%r{...}i`). This improves reliability, as the regex will handle changes in letter case without needing modifications.
4952

50-
* **Regexes should only use a capturing group around the version text**. For example, in `/href=.*?example-v?(\d+(?:\.\d+)+)(?:-src)?\.t/i`, we're only using a capturing group around the version test (matching a version like `1.2`, `1.2.3`, etc.) and we're using non-capturing groups elsewhere (e.g. `(?:-src)?`).
53+
* **Regexes should only use a capturing group around the version text**. For example, in `/href=.*?example-v?(\d+(?:\.\d+)+)(?:-src)?\.t/i`, we're only using a capturing group around the version text (matching a version like `1.2`, `1.2.3`, etc.) and we're using non-capturing groups elsewhere (e.g. `(?:-src)?`).
5154

52-
* **Anchor the start/end of the regex, to restrict the scope**. For example, on HTML pages we often match file names or version directories in `href` attribute URLs (e.g. `/href=.*?example[._-]v?(\d+(?:\.\d+)+)\.zip/i`). The general idea is that limiting scope will help exclude unwanted matches.
55+
* **Anchor the start/end of the regex to restrict its scope**. For example, on HTML pages we often match file names or version directories in `href` attribute URLs (e.g. `/href=.*?example[._-]v?(\d+(?:\.\d+)+)\.zip/i`). The general idea is that limiting scope will help exclude unwanted matches.
5356

5457
* **Avoid generic catchalls like `.*` or `.+`** in favor of something non-greedy and/or contextually appropriate. For example, to match characters within the bounds of an HTML attribute, use `[^"' >]+?`.
5558

@@ -112,9 +115,17 @@ end
112115

113116
The referenced formula/cask should be in the same tap, as a reference to a formula/cask from another tap will generate an error if the user doesn't already have it tapped.
114117

118+
A formula resource whose version stays in sync with its parent formula versioning can use the same check with `formula :parent`.
119+
120+
```ruby
121+
livecheck do
122+
formula :parent
123+
end
124+
```
125+
115126
### `POST` requests
116127

117-
Some checks require making a `POST` request and that can be accomplished by adding a `post_form` or `post_json` option to a `livecheck` block `url`.
128+
Some checks require making a `POST` request, which can be accomplished by adding a `post_form` or `post_json` option to a `livecheck` block `url`.
118129

119130
```ruby
120131
livecheck do
@@ -126,7 +137,7 @@ livecheck do
126137
end
127138
```
128139

129-
`post_form` is used for form data and `post_json` is used for JSON data. livecheck will encode the provided hash value to the appropriate format before making the request.
140+
`post_form` is used for form data and `post_json` is used for JSON data. Livecheck will encode the provided hash value to the appropriate format before making the request.
130141

131142
`POST` support only applies to strategies that use `Strategy::page_headers` or `::page_content` (directly or indirectly), so it does not apply to `ExtractPlist`, `Git`, `GithubLatest`, `GithubReleases`, etc.
132143

@@ -219,7 +230,7 @@ end
219230

220231
A `strategy` block for `GithubLatest` receives the parsed JSON data from the GitHub API for a repository's "latest" release, along with a regex. When a regex is not provided in a `livecheck` block, the strategy's default regex is passed into the `strategy` block instead.
221232

222-
By default, the strategy matches version text in the release's tag or title but a `strategy` block can be used to check any of the fields in the release JSON. The logic in the following `strategy` block is similar to the default behavior but only checks the release tag instead, for the sake of demonstration:
233+
By default, the strategy matches version text in the release's tag or title but a `strategy` block can be used to check any of the fields in the release JSON. The logic in the following `strategy` block is similar to the default behaviour but only checks the release tag instead, for the sake of demonstration:
223234

224235
```ruby
225236
livecheck do
@@ -240,7 +251,7 @@ You can find more information on the response JSON from this API endpoint in the
240251

241252
A `strategy` block for `GithubReleases` receives the parsed JSON data from the GitHub API for a repository's most recent releases, along with a regex. When a regex is not provided in a `livecheck` block, the strategy's default regex is passed into the `strategy` block instead.
242253

243-
By default, the strategy matches version text in each release's tag or title but a `strategy` block can be used to check any of the fields in the release JSON. The logic in the following `strategy` block is similar to the default behavior but only checks the release tag instead, for the sake of demonstration:
254+
By default, the strategy matches version text in each release's tag or title but a `strategy` block can be used to check any of the fields in the release JSON. The logic in the following `strategy` block is similar to the default behaviour but only checks the release tag instead, for the sake of demonstration:
244255

245256
```ruby
246257
livecheck do
@@ -343,7 +354,7 @@ A `strategy` block for `Sparkle` receives an `item` which has methods for the `v
343354
brew find-appcast '/path/to/application.app'
344355
```
345356

346-
The default pattern for the `Sparkle` strategy is to generate `"#{item.short_version},#{item.version}"` from `sparkle:shortVersionString` and `sparkle:version` if both are set. In the example below, the `url` also includes a download ID which is needed:
357+
The default pattern for the `Sparkle` strategy is to generate `"#{item.short_version},#{item.version}"` from `sparkle:shortVersionString` and `sparkle:version` if both are set. In the example below, the returned value also includes a needed download ID from the `url`:
347358

348359
```ruby
349360
livecheck do
@@ -363,6 +374,17 @@ livecheck do
363374
end
364375
```
365376

377+
If the value returned by `item` is not the most recent or not what's desired, passing `items` instead will allow iterating over all the items in the feed:
378+
379+
```ruby
380+
livecheck do
381+
url "https://www.example.com/example.xml"
382+
strategy :sparkle do |items|
383+
items.find { |item| item.channel.nil? }&.short_version
384+
end
385+
end
386+
```
387+
366388
#### `Xml` `strategy` block
367389

368390
A `strategy` block for `Xml` receives an `REXML::Document` object and, if provided, a regex. For example, if the XML contains a `versions` element with nested `version` elements and their inner text contains the version string, we could extract it using a regex as follows:
@@ -416,6 +438,18 @@ livecheck do
416438
end
417439
```
418440

441+
### `throttle`
442+
443+
For software with extremely frequent releases that don't all need to be published as formula/cask updates, livecheck can be set to reduce how many versions it surfaces by using `throttle`. In this example, only versions whose last component is divisible by 10 will be returned.
444+
445+
```ruby
446+
livecheck do
447+
url :stable
448+
regex(/^v?(\d+(?:\.\d+)+)$/i)
449+
throttle 10
450+
end
451+
```
452+
419453
### `skip`
420454

421455
Livecheck automatically skips some formulae/casks for a number of reasons (deprecated, disabled, etc.). However, on rare occasions we need to use a `livecheck` block to do a manual skip. The `skip` method takes a string containing a very brief reason for skipping.

0 commit comments

Comments
 (0)