brew-test-bot: support taps.

Closes Homebrew/homebrew#30540.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
Maurus Cuelenaere 2014-06-29 22:31:36 +02:00 committed by Mike McQuaid
parent f1cf62a4b5
commit e311583fe4

View File

@ -12,6 +12,7 @@
# --no-bottle: Run brew install without --build-bottle # --no-bottle: Run brew install without --build-bottle
# --HEAD: Run brew install with --HEAD # --HEAD: Run brew install with --HEAD
# --local: Ask Homebrew to write verbose logs under ./logs/ # --local: Ask Homebrew to write verbose logs under ./logs/
# --tap=<tap>: Use the git repository of the given tap
# #
# --ci-master: Shortcut for Homebrew master branch CI options. # --ci-master: Shortcut for Homebrew master branch CI options.
# --ci-pr: Shortcut for Homebrew pull request CI options. # --ci-pr: Shortcut for Homebrew pull request CI options.
@ -28,6 +29,14 @@ require 'rexml/cdata'
EMAIL_SUBJECT_FILE = "brew-test-bot.#{MacOS.cat}.email.txt" EMAIL_SUBJECT_FILE = "brew-test-bot.#{MacOS.cat}.email.txt"
def homebrew_git_repo tap=nil
if tap
HOMEBREW_LIBRARY/"Taps/#{tap}"
else
HOMEBREW_REPOSITORY
end
end
class Step class Step
attr_reader :command, :name, :status, :output, :time attr_reader :command, :name, :status, :output, :time
@ -38,7 +47,7 @@ class Step
@puts_output_on_success = options[:puts_output_on_success] @puts_output_on_success = options[:puts_output_on_success]
@name = command[1].delete("-") @name = command[1].delete("-")
@status = :running @status = :running
@repository = HOMEBREW_REPOSITORY @repository = options[:repository] || HOMEBREW_REPOSITORY
@time = 0 @time = 0
end end
@ -121,13 +130,21 @@ end
class Test class Test
attr_reader :log_root, :category, :name, :formulae, :steps attr_reader :log_root, :category, :name, :formulae, :steps
def initialize argument def initialize argument, tap=nil
@hash = nil @hash = nil
@url = nil @url = nil
@formulae = [] @formulae = []
@steps = []
@tap = tap
@repository = homebrew_git_repo @tap
@repository_requires_tapping = !@repository.directory?
url_match = argument.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX url_match = argument.match HOMEBREW_PULL_OR_COMMIT_URL_REGEX
# Tap repository if required, this is done before everything else
# because Formula parsing and/or git commit hash lookup depends on it.
test "brew", "tap", @tap if @tap && @repository_requires_tapping
begin begin
formula = Formulary.factory(argument) formula = Formulary.factory(argument)
rescue FormulaUnavailableError rescue FormulaUnavailableError
@ -145,7 +162,6 @@ class Test
end end
@category = __method__ @category = __method__
@steps = []
@brewbot_root = Pathname.pwd + "brewbot" @brewbot_root = Pathname.pwd + "brewbot"
FileUtils.mkdir_p @brewbot_root FileUtils.mkdir_p @brewbot_root
end end
@ -161,7 +177,7 @@ class Test
rd.close rd.close
STDERR.reopen("/dev/null") STDERR.reopen("/dev/null")
STDOUT.reopen(wr) STDOUT.reopen(wr)
Dir.chdir HOMEBREW_REPOSITORY Dir.chdir @repository
exec("git", *args) exec("git", *args)
end end
wr.close wr.close
@ -253,9 +269,15 @@ class Test
return unless diff_start_sha1 != diff_end_sha1 return unless diff_start_sha1 != diff_end_sha1
return if @url and not steps.last.passed? return if @url and not steps.last.passed?
if @tap
formula_path = %w[Formula HomebrewFormula].find { |dir| (@repository/dir).directory? } || ""
else
formula_path = "Library/Formula"
end
git( git(
"diff-tree", "-r", "--name-only", "--diff-filter=AM", "diff-tree", "-r", "--name-only", "--diff-filter=AM",
diff_start_sha1, diff_end_sha1, "--", "Library/Formula" diff_start_sha1, diff_end_sha1, "--", formula_path
).each_line do |line| ).each_line do |line|
@formulae << File.basename(line.chomp, ".rb") @formulae << File.basename(line.chomp, ".rb")
end end
@ -384,6 +406,7 @@ class Test
def cleanup_after def cleanup_after
@category = __method__ @category = __method__
checkout_args = [] checkout_args = []
if ARGV.include? '--cleanup' if ARGV.include? '--cleanup'
test "git", "clean", "--force", "-dx" test "git", "clean", "--force", "-dx"
@ -402,11 +425,14 @@ class Test
test "brew", "cleanup" test "brew", "cleanup"
end end
test "brew", "untap", @tap if @tap && @repository_requires_tapping
FileUtils.rm_rf @brewbot_root unless ARGV.include? "--keep-logs" FileUtils.rm_rf @brewbot_root unless ARGV.include? "--keep-logs"
end end
def test(*args) def test(*args)
options = Hash === args.last ? args.pop : {} options = Hash === args.last ? args.pop : {}
options[:repository] = @repository
step = Step.new self, args, options step = Step.new self, args, options
step.run step.run
steps << step steps << step
@ -438,6 +464,8 @@ class Test
end end
end end
tap = ARGV.value('tap')
if Pathname.pwd == HOMEBREW_PREFIX and ARGV.include? "--cleanup" if Pathname.pwd == HOMEBREW_PREFIX and ARGV.include? "--cleanup"
odie 'cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output.' odie 'cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output.'
end end
@ -476,6 +504,8 @@ if ARGV.include? '--ci-pr-upload' or ARGV.include? '--ci-testing-upload'
ENV["GIT_COMMITTER_NAME"] = "BrewTestBot" ENV["GIT_COMMITTER_NAME"] = "BrewTestBot"
ENV["GIT_COMMITTER_EMAIL"] = "brew-test-bot@googlegroups.com" ENV["GIT_COMMITTER_EMAIL"] = "brew-test-bot@googlegroups.com"
ENV["GIT_WORK_TREE"] = homebrew_git_repo tap
ENV["GIT_DIR"] = ENV["GIT_WORK_TREE"]/".git"
pr = ENV['UPSTREAM_PULL_REQUEST'] pr = ENV['UPSTREAM_PULL_REQUEST']
number = ENV['UPSTREAM_BUILD_NUMBER'] number = ENV['UPSTREAM_BUILD_NUMBER']
@ -514,12 +544,12 @@ tests = []
any_errors = false any_errors = false
if ARGV.named.empty? if ARGV.named.empty?
# With no arguments just build the most recent commit. # With no arguments just build the most recent commit.
test = Test.new('HEAD') test = Test.new('HEAD', tap)
any_errors = test.run any_errors = test.run
tests << test tests << test
else else
ARGV.named.each do |argument| ARGV.named.each do |argument|
test = Test.new(argument) test = Test.new(argument, tap)
any_errors = test.run or any_errors any_errors = test.run or any_errors
tests << test tests << test
end end