Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pr-pull: don't try to fetch artifacts for a pull request when the changed formulae don't use bottles #7326

Merged
merged 2 commits into from Apr 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 41 additions & 8 deletions Library/Homebrew/dev-cmd/pr-pull.rb
Expand Up @@ -67,19 +67,19 @@ def setup_git_environment!
end
end

def signoff!(pr, path: ".", dry_run: false)
def signoff!(pr, path: ".")
message = Utils.popen_read "git", "-C", path, "log", "-1", "--pretty=%B"
close_message = "Closes ##{pr}."
message += "\n#{close_message}" unless message.include? close_message
if dry_run
if Homebrew.args.dry_run?
puts "git commit --amend --signoff -m $message"
else
safe_system "git", "-C", path, "commit", "--amend", "--signoff", "--allow-empty", "-q", "-m", message
end
end

def cherry_pick_pr!(pr, path: ".", dry_run: false)
if dry_run
def cherry_pick_pr!(pr, path: ".")
if Homebrew.args.dry_run?
puts <<~EOS
git fetch --force origin +refs/pull/#{pr}/head
git merge-base HEAD FETCH_HEAD
Expand Down Expand Up @@ -114,6 +114,32 @@ def check_branch(path, ref)
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
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
# 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

Expand Down Expand Up @@ -144,19 +170,26 @@ def pr_pull
ohai "Fetching #{tap} pull request ##{pr}"
Dir.mktmpdir pr do |dir|
cd dir do
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)
cherry_pick_pr! pr, path: tap.path, dry_run: args.dry_run?
signoff! pr, path: tap.path, dry_run: args.dry_run? unless args.clean?

if args.dry_run?
if Homebrew.args.dry_run?
puts "brew bottle --merge --write #{Dir["*.json"].join " "}"
else
quiet_system "#{HOMEBREW_PREFIX}/bin/brew", "bottle", "--merge", "--write", *Dir["*.json"]
end

next if args.no_upload?

if args.dry_run?
if Homebrew.args.dry_run?
puts "Upload bottles described by these JSON files to Bintray:\n #{Dir["*.json"].join("\n ")}"
else
bintray.upload_bottle_json Dir["*.json"], publish_package: !args.no_publish?
Expand Down