brew-test-bot: support commits as arguments.

This commit is contained in:
Mike McQuaid 2012-11-25 12:47:36 +00:00
parent 427bc9d01c
commit 248276839e

View File

@ -108,18 +108,23 @@ class Test
end end
def initialize arg def initialize arg
begin @start_sha1 = nil
Formula.factory arg @url = nil
rescue FormulaUnavailableError @formulae = []
odie "#{arg} is not a pull request number or formula." unless arg.to_i > 0
@url = arg url_match = arg.match 'https:\/\/github.com\/\w+\/homebrew(-\w+)?\/(pull\/(\d+)|commit\/\w{4,40})'
@formulae = [] formula = Formula.factory arg rescue FormulaUnavailableError
else git("rev-parse --verify #{arg} &>/dev/null")
@url = nil if $?.success?
@start_sha1 = arg
elsif url_match
@url = url_match[0]
elsif formula
@formulae = [arg] @formulae = [arg]
else
odie "#{arg} is not a pull request URL, commit URL or formula name."
end end
@start_sha1 = nil
@category = __method__ @category = __method__
@steps = [] @steps = []
@core_changed = false @core_changed = false
@ -176,26 +181,29 @@ class Test
end end
@category = __method__ @category = __method__
if @url if @start_sha1
end_sha1 = @start_sha1
@start_sha1 = "#{@start_sha1}^"
@name = end_sha1
elsif @url
git 'am --abort 2>/dev/null' git 'am --abort 2>/dev/null'
test "brew update" if current_branch == "master" test "brew update" if current_branch == "master"
@start_sha1 = current_sha1 @start_sha1 = current_sha1
test "brew pull --clean #{@url}" test "brew pull --clean #{@url}"
end_sha1 = current_sha1 end_sha1 = current_sha1
return unless @url and @start_sha1 != end_sha1 and steps.last.status == :passed
@name = "#{@url}-#{end_sha1}"
else else
@start_sha1 = end_sha1 = current_sha1 @start_sha1 = end_sha1 = current_sha1
@name = "#{@formulae.first}-#{end_sha1}"
end end
name_prefix = @url ? @url : @formulae.first
@name = "#{name_prefix}-#{end_sha1}"
@log_root = @brewbot_root + @name @log_root = @brewbot_root + @name
FileUtils.mkdir_p @log_root if ARGV.include? "--log" or ARGV.include? "--html" FileUtils.mkdir_p @log_root if ARGV.include? "--log" or ARGV.include? "--html"
write_root_html :running write_root_html :running
return unless @url and @start_sha1 != end_sha1 and steps.last.status == :passed git("diff #{@start_sha1}..#{end_sha1} --name-status").each_line do |line|
git("diff #{@start_sha1}..#{end_sha1} --name-status`.each_line") do |line|
status, filename = line.split status, filename = line.split
# Don't try and do anything to removed files. # Don't try and do anything to removed files.
if (status == 'A' or status == 'M') if (status == 'A' or status == 'M')
@ -203,8 +211,9 @@ class Test
@formulae << File.basename(filename, '.rb') @formulae << File.basename(filename, '.rb')
end end
end end
if filename.include? '/Homebrew/' or filename.include? 'bin/brew' if filename.include? '/Homebrew/' or filename.include? '/ENV/' \
@homebrew_changed = true or filename.include? 'bin/brew'
@core_changed = true
end end
end end
end end
@ -231,6 +240,7 @@ class Test
def homebrew def homebrew
@category = __method__ @category = __method__
test "brew tests" test "brew tests"
test "brew readall"
end end
def cleanup def cleanup
@ -241,11 +251,9 @@ class Test
test "brew cleanup" test "brew cleanup"
test "git clean --force -dx" test "git clean --force -dx"
test "git gc" test "git gc"
else elsif not ARGV.include? "--skip-cleanup"
unless ARGV.include? "--skip-cleanup" git('diff --exit-code HEAD 2>/dev/null')
git('diff --exit-code HEAD 2>/dev/null') odie "Uncommitted changes, aborting." unless $?.success?
odie "Uncommitted changes, aborting." unless $?.success?
end
test "git reset --hard #{@start_sha1}" if @start_sha1 test "git reset --hard #{@start_sha1}" if @start_sha1
end end
end end
@ -282,9 +290,9 @@ class Test
end end
end end
def self.run url def self.run arg
test = new url test = new arg
test.cleanup test.cleanup unless ARGV.include? "--skip-cleanup"
test.download test.download
test.setup unless ARGV.include? "--skip-setup" test.setup unless ARGV.include? "--skip-setup"
test.formulae.each do |f| test.formulae.each do |f|
@ -297,10 +305,9 @@ class Test
end end
end end
if ARGV.empty? if ARGV.named.empty?
odie 'This command requires at least one argument containing a pull request number or formula.' # With no arguments just build the most recent commit.
end Test.run 'HEAD'
else
ARGV.named.each do|arg| ARGV.named.each { |arg| Test.run arg }
Test.run arg
end end