You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Brew-Livecheck.md
+46-12Lines changed: 46 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,23 +1,26 @@
1
1
---
2
-
last_review_date: "1970-01-01"
2
+
last_review_date: 2025-05-28
3
3
---
4
4
5
5
# `brew livecheck`
6
6
7
7
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.
8
8
9
-
## Behavior
9
+
## Behaviour
10
10
11
11
When livecheck isn't given instructions for how to check for upstream versions, it does the following by default:
12
12
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.
14
17
1. Determine if any strategies apply to the first URL. If not, try the next URL.
15
18
1. If a strategy can be applied, use it to check for new versions.
16
19
1. Return the newest version (or an error if versions could not be found at any available URLs).
17
20
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.
19
22
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.
21
24
22
25
## Creating a check
23
26
@@ -47,9 +50,9 @@ The `livecheck` block regex restricts matches to a subset of the fetched content
47
50
48
51
***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.
49
52
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)?`).
51
54
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.
53
56
54
57
***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 `[^"' >]+?`.
55
58
@@ -112,9 +115,17 @@ end
112
115
113
116
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.
114
117
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
+
115
126
### `POST` requests
116
127
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`.
118
129
119
130
```ruby
120
131
livecheck do
@@ -126,7 +137,7 @@ livecheck do
126
137
end
127
138
```
128
139
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.
130
141
131
142
`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.
132
143
@@ -219,7 +230,7 @@ end
219
230
220
231
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.
221
232
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:
223
234
224
235
```ruby
225
236
livecheck do
@@ -240,7 +251,7 @@ You can find more information on the response JSON from this API endpoint in the
240
251
241
252
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.
242
253
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:
244
255
245
256
```ruby
246
257
livecheck do
@@ -343,7 +354,7 @@ A `strategy` block for `Sparkle` receives an `item` which has methods for the `v
343
354
brew find-appcast '/path/to/application.app'
344
355
```
345
356
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`:
347
358
348
359
```ruby
349
360
livecheck do
@@ -363,6 +374,17 @@ livecheck do
363
374
end
364
375
```
365
376
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:
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
416
438
end
417
439
```
418
440
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
+
419
453
### `skip`
420
454
421
455
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