@@ -346,12 +346,17 @@ def run
346
346
install_dependencies : args . install_dependencies? ,
347
347
silent : args . quiet? ,
348
348
ignore_non_pypi_packages : true
349
+
350
+ update_matching_version_resources! formula ,
351
+ version : new_formula_version . to_s
349
352
end
350
353
351
354
run_audit ( formula , alias_rename , old_contents )
352
355
353
356
pr_message = "Created with `brew bump-formula-pr`."
354
- if resources_checked . nil? && formula . resources . any? { |resource | !resource . name . start_with? ( "homebrew-" ) }
357
+ if resources_checked . nil? && formula . resources . any? do |resource |
358
+ resource . livecheck . formula != :parent && !resource . name . start_with? ( "homebrew-" )
359
+ end
355
360
pr_message += <<~EOS
356
361
357
362
@@ -441,19 +446,85 @@ def update_url(old_url, old_version, new_version)
441
446
end
442
447
443
448
sig {
444
- params ( formula : Formula , new_version : T . nilable ( String ) , url : String ,
449
+ params ( formula_or_resource : T . any ( Formula , Resource ) , new_version : T . nilable ( String ) , url : String ,
445
450
specs : String ) . returns ( T ::Array [ T . untyped ] )
446
451
}
447
- def fetch_resource_and_forced_version ( formula , new_version , url , **specs )
452
+ def fetch_resource_and_forced_version ( formula_or_resource , new_version , url , **specs )
448
453
resource = Resource . new
449
454
resource . url ( url , **specs )
450
- resource . owner = Resource . new ( formula . name )
455
+ resource . owner = if formula_or_resource . is_a? ( Formula )
456
+ Resource . new ( formula_or_resource . name )
457
+ else
458
+ Resource . new ( formula_or_resource . owner . name )
459
+ end
451
460
forced_version = new_version && new_version != resource . version . to_s
452
461
resource . version ( new_version ) if forced_version
453
462
odie "Couldn't identify version, specify it using `--version=`." if resource . version . blank?
454
463
[ resource . fetch , forced_version ]
455
464
end
456
465
466
+ sig {
467
+ params (
468
+ formula : Formula ,
469
+ version : String ,
470
+ ) . void
471
+ }
472
+ def update_matching_version_resources! ( formula , version :)
473
+ formula . resources . select { |r | r . livecheck . formula == :parent } . each do |resource |
474
+ new_url = update_url ( resource . url , resource . version . to_s , version )
475
+
476
+ if new_url == resource . url
477
+ opoo <<~EOS
478
+ You need to bump resource "#{ resource . name } " manually since the new URL
479
+ and old URL are both:
480
+ #{ new_url }
481
+ EOS
482
+ next
483
+ end
484
+
485
+ new_mirrors = resource . mirrors . map do |mirror |
486
+ update_url ( mirror , resource . version . to_s , version )
487
+ end
488
+ resource_path , forced_version = fetch_resource_and_forced_version ( resource , version , new_url )
489
+ Utils ::Tar . validate_file ( resource_path )
490
+ new_hash = resource_path . sha256
491
+
492
+ inreplace_regex = /
493
+ [ ]+resource\ "#{ resource . name } "\ do\s +
494
+ url\ .*\s +
495
+ (mirror\ .*\s +)*
496
+ sha256\ .*\s +
497
+ (version\ .*\s +)?
498
+ (\# .*\s +)*
499
+ livecheck\ do\s +
500
+ formula\ :parent\s +
501
+ end\s +
502
+ ((\# .*\s +)*
503
+ patch\ (.*\ )?do\s +
504
+ url\ .*\s +
505
+ sha256\ .*\s +
506
+ end\s +)*
507
+ end\s
508
+ /x
509
+
510
+ leading_spaces = T . must ( formula . path . read . match ( /^([ ]+)resource "#{ resource . name } "/ ) ) . captures . first
511
+ new_resource_block = <<~EOS
512
+ #{ leading_spaces } resource "#{ resource . name } " do
513
+ #{ leading_spaces } url "#{ new_url } "#{ new_mirrors . map { |m | "\n #{ leading_spaces } mirror \" #{ m } \" " } . join }
514
+ #{ leading_spaces } sha256 "#{ new_hash } "
515
+ #{ forced_version ? "#{ leading_spaces } version \" #{ version } \" \n " : "" }
516
+ #{ leading_spaces } livecheck do
517
+ #{ leading_spaces } formula :parent
518
+ #{ leading_spaces } end
519
+ #{ leading_spaces } end
520
+ EOS
521
+
522
+ Utils ::Inreplace . inreplace formula . path do |s |
523
+ s . sub! inreplace_regex , new_resource_block
524
+ end
525
+ end
526
+ end
527
+
457
528
sig { params ( formula : Formula , contents : T . nilable ( String ) ) . returns ( Version ) }
458
529
def formula_version ( formula , contents = nil )
459
530
spec = :stable
0 commit comments