test-bot: use Travis CI environment variables.

This commit is contained in:
Mike McQuaid 2015-09-15 17:32:28 +01:00
parent a25fc67813
commit e39cd2e9b2

View File

@ -17,6 +17,7 @@
# --tap=<tap>: Use the git repository of the given tap # --tap=<tap>: Use the git repository of the given tap
# --dry-run: Just print commands, don't run them. # --dry-run: Just print commands, don't run them.
# --fail-fast: Immediately exit on a failing step. # --fail-fast: Immediately exit on a failing step.
# --verbose: Print out all logs in realtime
# #
# --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.
@ -91,13 +92,31 @@ module Homebrew
def puts_command def puts_command
cmd = @command.join(" ") cmd = @command.join(" ")
print "#{Tty.blue}==>#{Tty.white} #{cmd}#{Tty.reset}" cmd_line = "#{Tty.blue}==>#{Tty.white} #{cmd}#{Tty.reset}"
if ENV["TRAVIS"]
@travis_timer_id = rand(2**32).to_s(16)
puts "travis_fold:start:#{@command.join(".")}"
puts "travis_time:start:#{@travis_timer_id}"
puts cmd_line
return
end
print cmd_line
tabs = (80 - "PASSED".length + 1 - cmd.length) / 8 tabs = (80 - "PASSED".length + 1 - cmd.length) / 8
tabs.times { print "\t" } tabs.times { print "\t" }
$stdout.flush $stdout.flush
end end
def puts_result def puts_result
if ENV["TRAVIS"]
cmd = @command.join(" ")
puts "#{Tty.send status_colour}==> #{cmd}: #{status_upcase}#{Tty.reset}"
travis_start_time = @start_time.to_i*1000000000
travis_end_time = @end_time.to_i*1000000000
travis_duration = travis_end_time - travis_start_time
puts "travis_fold:end:#{@command.join(".")}"
puts "travis_time:end:#{@travis_timer_id},start=#{travis_start_time},finish=#{travis_end_time},duration=#{travis_duration}"
return
end
puts " #{Tty.send status_colour}#{status_upcase}#{Tty.reset}" puts " #{Tty.send status_colour}#{status_upcase}#{Tty.reset}"
end end
@ -105,19 +124,25 @@ module Homebrew
@output && !@output.empty? @output && !@output.empty?
end end
def time
@end_time - @start_time
end
def run def run
@start_time = Time.now
puts_command puts_command
if ARGV.include? "--dry-run" if ARGV.include? "--dry-run"
puts @end_time = Time.now
@status = :passed @status = :passed
puts_result
return return
end end
verbose = ARGV.verbose? verbose = ARGV.verbose?
puts if verbose puts if verbose && !ENV["TRAVIS"]
@output = "" @output = ""
working_dir = Pathname.new(@command.first == "git" ? @repository : Dir.pwd) working_dir = Pathname.new(@command.first == "git" ? @repository : Dir.pwd)
start_time = Time.now
read, write = IO.pipe read, write = IO.pipe
begin begin
@ -138,7 +163,7 @@ module Homebrew
end end
Process.wait(pid) Process.wait(pid)
@time = Time.now - start_time @end_time = Time.now
@status = $?.success? ? :passed : :failed @status = $?.success? ? :passed : :failed
puts_result puts_result
@ -269,12 +294,17 @@ module Homebrew
@category = __method__ @category = __method__
@start_branch = current_branch @start_branch = current_branch
travis_pr = ENV["TRAVIS_PULL_REQUEST"] && ENV["TRAVIS_PULL_REQUEST"] != "false"
# Use Jenkins environment variables if present. # Use Jenkins environment variables if present.
if no_args? && ENV["GIT_PREVIOUS_COMMIT"] && ENV["GIT_COMMIT"] \ if no_args? && ENV["GIT_PREVIOUS_COMMIT"] && ENV["GIT_COMMIT"] \
&& !ENV["ghprbPullLink"] && !ENV["ghprbPullLink"]
diff_start_sha1 = shorten_revision ENV["GIT_PREVIOUS_COMMIT"] diff_start_sha1 = shorten_revision ENV["GIT_PREVIOUS_COMMIT"]
diff_end_sha1 = shorten_revision ENV["GIT_COMMIT"] diff_end_sha1 = shorten_revision ENV["GIT_COMMIT"]
brew_update brew_update
elsif ENV["TRAVIS_COMMIT_RANGE"]
diff_start_sha1, diff_end_sha1 = ENV["TRAVIS_COMMIT_RANGE"].split "..."
diff_end_sha1 = ENV["TRAVIS_COMMIT"] if travis_pr
elsif @hash elsif @hash
diff_start_sha1 = current_sha1 diff_start_sha1 = current_sha1
brew_update brew_update
@ -287,6 +317,9 @@ module Homebrew
if ENV["ghprbPullLink"] if ENV["ghprbPullLink"]
@url = ENV["ghprbPullLink"] @url = ENV["ghprbPullLink"]
@hash = nil @hash = nil
elsif travis_pr
@url = "https://github.com/#{ENV["TRAVIS_REPO_SLUG"]}/pull/#{ENV["TRAVIS_PULL_REQUEST"]}"
@hash = nil
end end
if no_args? if no_args?
@ -301,6 +334,9 @@ module Homebrew
diff_start_sha1 = "#{@hash}^" diff_start_sha1 = "#{@hash}^"
diff_end_sha1 = @hash diff_end_sha1 = @hash
@name = @hash @name = @hash
elsif ENV["TRAVIS_PULL_REQUEST"] && ENV["TRAVIS_PULL_REQUEST"] != "false"
@short_url = @url.gsub("https://github.com/", "")
@name = "#{@short_url}-#{diff_end_sha1}"
elsif @url elsif @url
diff_start_sha1 = current_sha1 diff_start_sha1 = current_sha1
test "git", "checkout", diff_start_sha1 test "git", "checkout", diff_start_sha1
@ -323,7 +359,7 @@ module Homebrew
FileUtils.mkdir_p @log_root FileUtils.mkdir_p @log_root
return unless diff_start_sha1 != diff_end_sha1 return unless diff_start_sha1 != diff_end_sha1
return if @url && !steps.last.passed? return if @url && steps.last && !steps.last.passed?
if @tap if @tap
formula_path = %w[Formula HomebrewFormula].find { |dir| (@repository/dir).directory? } || "" formula_path = %w[Formula HomebrewFormula].find { |dir| (@repository/dir).directory? } || ""
@ -369,7 +405,7 @@ module Homebrew
def setup def setup
@category = __method__ @category = __method__
return if ARGV.include? "--skip-setup" return if ARGV.include? "--skip-setup"
test "brew", "doctor" test "brew", "doctor" unless ENV["TRAVIS"]
test "brew", "--env" test "brew", "--env"
test "brew", "config" test "brew", "config"
end end
@ -610,7 +646,8 @@ module Homebrew
checkout_args << @start_branch checkout_args << @start_branch
if ARGV.include?("--cleanup") || @url || @hash if @start_branch && !@start_branch.empty? && \
(ARGV.include?("--cleanup") || @url || @hash)
test "git", "checkout", *checkout_args test "git", "checkout", *checkout_args
end end
@ -723,9 +760,11 @@ module Homebrew
ENV["HOMEBREW_DEVELOPER"] = "1" ENV["HOMEBREW_DEVELOPER"] = "1"
ENV["HOMEBREW_SANDBOX"] = "1" ENV["HOMEBREW_SANDBOX"] = "1"
ENV["HOMEBREW_NO_EMOJI"] = "1" ENV["HOMEBREW_NO_EMOJI"] = "1"
ARGV << "--verbose" if ENV["TRAVIS"]
if ARGV.include?("--ci-master") || ARGV.include?("--ci-pr") \ if ARGV.include?("--ci-master") || ARGV.include?("--ci-pr") \
|| ARGV.include?("--ci-testing") || ARGV.include?("--ci-testing")
ARGV << "--cleanup" if ENV["JENKINS_HOME"] || ENV["TRAVIS_COMMIT"] ARGV << "--cleanup" if ENV["JENKINS_HOME"] || ENV["TRAVIS"]
ARGV << "--junit" << "--local" ARGV << "--junit" << "--local"
end end
if ARGV.include? "--ci-master" if ARGV.include? "--ci-master"
@ -933,15 +972,19 @@ module Homebrew
end end
end end
if ARGV.include? "--email" failed_steps = []
failed_steps = [] tests.each do |test|
tests.each do |test| test.steps.each do |step|
test.steps.each do |step| next if step.passed?
next if step.passed? failed_steps << step.command_short
failed_steps << step.command_short
end
end end
end
if ENV["TRAVIS"] && !failed_steps.empty?
puts "#{Tty.red}==> #{cmd}: FAILED: #{MacOS.version}: #{failed_steps.join ", "}#{Tty.reset}"
end
if ARGV.include? "--email"
if failed_steps.empty? if failed_steps.empty?
email_subject = "" email_subject = ""
else else