From f575eecabcc39edff8865aeb231918e2a87a30e0 Mon Sep 17 00:00:00 2001 From: Jonathan Chang Date: Sat, 11 Apr 2020 19:27:34 +1000 Subject: [PATCH] pr-pull: don't try to fetch unneeded artifacts --- Library/Homebrew/dev-cmd/pr-pull.rb | 35 ++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index 8da3b1fd1d..e8b12d9030 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -114,6 +114,32 @@ module Homebrew opoo "Current branch is #{branch}: do you need to pull inside #{ref}?" end + def formulae_need_bottles?(tap, original_commit) + return if Homebrew.args.dry_run? + + if Homebrew::EnvConfig.disable_load_formula? + opoo "Can't check if updated bottles are necessary as formula loading is disabled!" + return + end + + Utils.popen_read("git", "-C", tap.path, "diff-tree", + "-r", "--name-only", "--diff-filter=AM", + original_commit, "HEAD", "--", tap.formula_dir) + .lines.each do |line| + next unless line.end_with? ".rb\n" + + name = "#{tap.name}/#{File.basename(line.chomp, ".rb")}" + begin + f = Formula[name] + rescue Exception # rubocop:disable Lint/RescueException + # Make sure we catch syntax errors. + next + end + return true if !f.bottle_unneeded? && !f.bottle_disabled? + end + nil + end + def pr_pull pr_pull_args.parse @@ -144,10 +170,17 @@ module Homebrew ohai "Fetching #{tap} pull request ##{pr}" Dir.mktmpdir pr do |dir| cd dir do - GitHub.fetch_artifact(user, repo, pr, dir, workflow_id: workflow, artifact_name: artifact) + original_commit = Utils.popen_read("git", "-C", tap.path, "rev-parse", "HEAD").chomp cherry_pick_pr! pr, path: tap.path signoff! pr, path: tap.path unless args.clean? + unless formulae_need_bottles? tap, original_commit + ohai "Skipping artifacts for ##{pr} as the formulae don't need bottles" + next + end + + GitHub.fetch_artifact(user, repo, pr, dir, workflow_id: workflow, artifact_name: artifact) + if Homebrew.args.dry_run? puts "brew bottle --merge --write #{Dir["*.json"].join " "}" else