mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #17798 from muescha/patch-3
Update Brew-Livecheck.md: add examples for modify version information
This commit is contained in:
commit
61f5e2b698
@ -268,6 +268,34 @@ livecheck do
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If you need to modify the version, you can access the YAML hash in the `strategy` block like so:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
livecheck do
|
||||||
|
url "https://example.org/my-app/latest-mac.yml"
|
||||||
|
strategy :electron_builder do |yaml|
|
||||||
|
yaml["version"]&.gsub(/\D/, "")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
Similarly, you can work with the `files` array like this:
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
livecheck do
|
||||||
|
url "https://example.org/my-app/latest-mac.yml"
|
||||||
|
regex(/MyApp[._-]v?(\d+(?:\.\d+)+)-(\h+)\.dmg/i)
|
||||||
|
strategy :electron_builder do |yaml, regex|
|
||||||
|
yaml["files"]&.map do |file|
|
||||||
|
match = file["url"]&.match(regex)
|
||||||
|
next if match.blank?
|
||||||
|
|
||||||
|
"#{match[1]},#{match[2]}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
#### `Json` `strategy` block
|
#### `Json` `strategy` block
|
||||||
|
|
||||||
A `strategy` block for `Json` receives parsed JSON data and, if provided, a regex. For example, if we have an object containing an array of objects with a `version` string, we can select only the members that match the regex and isolate the relevant version text as follows:
|
A `strategy` block for `Json` receives parsed JSON data and, if provided, a regex. For example, if we have an object containing an array of objects with a `version` string, we can select only the members that match the regex and isolate the relevant version text as follows:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user