Merge pull request #17798 from muescha/patch-3

Update Brew-Livecheck.md: add examples for modify version information
This commit is contained in:
Sam Ford 2024-07-18 12:43:16 -04:00 committed by GitHub
commit 61f5e2b698
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: