Merge pull request #13998 from EricFromCanada/bump-cask-pr-additions

bump-cask-pr: handle additional use cases
This commit is contained in:
Eric Knibbe 2022-10-14 12:00:56 -04:00 committed by GitHub
commit f0f84750bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 43 deletions

View File

@ -87,6 +87,7 @@ module Cask
:discontinued?, :discontinued?,
:livecheck, :livecheck,
:livecheckable?, :livecheckable?,
:on_system_blocks_exist?,
*ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key), *ORDINARY_ARTIFACT_CLASSES.map(&:dsl_key),
*ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key), *ACTIVATABLE_ARTIFACT_CLASSES.map(&:dsl_key),
*ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] }, *ARTIFACT_BLOCK_CLASSES.flat_map { |klass| [klass.dsl_key, klass.uninstall_dsl_key] },

View File

@ -78,14 +78,14 @@ module Homebrew
odie "This cask's tap is not a Git repository!" unless cask.tap.git? odie "This cask's tap is not a Git repository!" unless cask.tap.git?
new_version = args.version new_version = args.version
new_version = :latest if ["latest", ":latest"].include?(new_version) new_version = :latest if ["latest", ":latest"].include? new_version
new_version = Cask::DSL::Version.new(new_version) if new_version.present? new_version = Cask::DSL::Version.new(new_version) if new_version.present?
new_base_url = args.url new_base_url = args.url
new_hash = args.sha256 new_hash = args.sha256
new_hash = :no_check if ["no_check", ":no_check"].include? new_hash new_hash = :no_check if ["no_check", ":no_check"].include? new_hash
if new_version.nil? && new_base_url.nil? && new_hash.nil? if new_version.nil? && new_base_url.nil? && new_hash.nil?
raise UsageError, "No --version=/--url=/--sha256= argument specified!" raise UsageError, "No `--version=`, `--url=` or `--sha256=` argument specified!"
end end
old_version = cask.version old_version = cask.version
@ -104,25 +104,14 @@ module Homebrew
/version\s+#{old_version_regex}/m, /version\s+#{old_version_regex}/m,
"version #{new_version.latest? ? ":latest" : "\"#{new_version}\""}", "version #{new_version.latest? ? ":latest" : "\"#{new_version}\""}",
] ]
if new_version.latest? || new_hash == :no_check
opoo "Ignoring specified `--sha256=` argument." if new_hash.is_a? String
replacement_pairs << [/"#{old_hash}"/, ":no_check"] if old_hash != :no_check
elsif old_hash != :no_check
if new_hash.nil? || cask.languages.present?
if new_hash.present? && cask.languages.present?
opoo "Multiple hash replacements required; ignoring specified `--sha256=` argument."
end end
if new_base_url.present?
m = /^ +url "(.+?)"\n/m.match(old_contents)
odie "Could not find old URL in cask!" if m.nil?
old_base_url = m.captures.first
replacement_pairs << [
/#{Regexp.escape(old_base_url)}/,
new_base_url,
]
end
if new_version.present?
if new_version.latest?
opoo "Ignoring specified `--sha256=` argument." if new_hash.present?
replacement_pairs << [old_hash, ":no_check"]
elsif old_hash != :no_check && (new_hash.nil? || cask.languages.present?)
tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, tmp_contents = Utils::Inreplace.inreplace_pairs(cask.sourcefile_path,
replacement_pairs.uniq.compact, replacement_pairs.uniq.compact,
read_only_run: true, read_only_run: true,
@ -156,8 +145,24 @@ module Homebrew
Homebrew::SimulateSystem.clear Homebrew::SimulateSystem.clear
end end
elsif new_hash.present?
opoo "Cask contains multiple hashes; only updating hash for current arch." if cask.on_system_blocks_exist?
replacement_pairs << [old_hash.to_s, new_hash]
end end
end end
end
if new_base_url.present?
m = /^ +url "(.+?)"\n/m.match(old_contents)
odie "Could not find old URL in cask!" if m.nil?
old_base_url = m.captures.first
replacement_pairs << [
/#{Regexp.escape(old_base_url)}/,
new_base_url,
]
end
Utils::Inreplace.inreplace_pairs(cask.sourcefile_path, Utils::Inreplace.inreplace_pairs(cask.sourcefile_path,
replacement_pairs.uniq.compact, replacement_pairs.uniq.compact,