Merge pull request #14262 from nandahkrishna/resource-livecheck-formula-latest

Enable use of latest formula version in resource `livecheck` URLs
This commit is contained in:
Nanda H Krishna 2022-12-20 01:02:37 -05:00 committed by GitHub
commit 30c3fc546f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 10 deletions

View File

@ -3278,6 +3278,7 @@ class Formula
def livecheck(&block) def livecheck(&block)
return @livecheck unless block return @livecheck unless block
include Homebrew::Livecheck::Constants
@livecheckable = true @livecheckable = true
@livecheck.instance_eval(&block) @livecheck.instance_eval(&block)
end end

View File

@ -1,6 +1,8 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "livecheck/constants"
# The {Livecheck} class implements the DSL methods used in a formula's, cask's # The {Livecheck} class implements the DSL methods used in a formula's, cask's
# or resource's `livecheck` block and stores related instance variables. Most # or resource's `livecheck` block and stores related instance variables. Most
# of these methods also return the related instance variable when no argument # of these methods also return the related instance variable when no argument

View File

@ -0,0 +1,14 @@
# typed: true
# frozen_string_literal: true
module Homebrew
module Livecheck
# The {Constants} module provides constants that are intended to be used
# in `livecheck` block values (e.g. `url`, `regex`).
module Constants
# A placeholder string used in resource `livecheck` block URLs that will
# be replaced with the latest version from the main formula check.
LATEST_VERSION = "<FORMULA_LATEST_VERSION>"
end
end
end

View File

@ -1,6 +1,7 @@
# typed: true # typed: true
# frozen_string_literal: true # frozen_string_literal: true
require "livecheck/constants"
require "livecheck/error" require "livecheck/error"
require "livecheck/livecheck_version" require "livecheck/livecheck_version"
require "livecheck/skip_conditions" require "livecheck/skip_conditions"
@ -295,6 +296,7 @@ module Homebrew
else else
res_version_info = resource_version( res_version_info = resource_version(
resource, resource,
latest.to_s,
json: json, json: json,
debug: debug, debug: debug,
quiet: quiet, quiet: quiet,
@ -837,6 +839,7 @@ module Homebrew
sig { sig {
params( params(
resource: Resource, resource: Resource,
formula_latest: String,
json: T::Boolean, json: T::Boolean,
debug: T::Boolean, debug: T::Boolean,
quiet: T::Boolean, quiet: T::Boolean,
@ -845,6 +848,7 @@ module Homebrew
} }
def resource_version( def resource_version(
resource, resource,
formula_latest,
json: false, json: false,
debug: false, debug: false,
quiet: false, quiet: false,
@ -874,12 +878,11 @@ module Homebrew
checked_urls = [] checked_urls = []
# rubocop:disable Metrics/BlockLength # rubocop:disable Metrics/BlockLength
urls.each_with_index do |original_url, i| urls.each_with_index do |original_url, i|
url = original_url.gsub(Constants::LATEST_VERSION, formula_latest)
# Only preprocess the URL when it's appropriate # Only preprocess the URL when it's appropriate
url = if STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL.include?(livecheck_strategy) url = preprocess_url(url) unless STRATEGY_SYMBOLS_TO_SKIP_PREPROCESS_URL.include?(livecheck_strategy)
original_url
else
preprocess_url(original_url)
end
next if checked_urls.include?(url) next if checked_urls.include?(url)
strategies = Strategy.from_url( strategies = Strategy.from_url(