test-bot: make ci-upload a standalone method

This commit is contained in:
Xu Cheng 2015-09-18 20:28:36 +08:00
parent 70d31838c6
commit 8228993624

View File

@ -735,51 +735,9 @@ module Homebrew
exec "brew", "update"
end
def test_bot
def test_ci_upload
tap = resolve_test_tap
repository = Homebrew.homebrew_git_repo tap
if Pathname.pwd == HOMEBREW_PREFIX && ARGV.include?("--cleanup")
odie "cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output."
end
if ARGV.include? "--email"
File.open EMAIL_SUBJECT_FILE, "w" do |file|
# The file should be written at the end but in case we don't get to that
# point ensure that we have something valid.
file.write "#{MacOS.version}: internal error."
end
end
ENV["HOMEBREW_DEVELOPER"] = "1"
ENV["HOMEBREW_SANDBOX"] = "1"
ENV["HOMEBREW_NO_EMOJI"] = "1"
ARGV << "--verbose" if ENV["TRAVIS"]
if ARGV.include?("--ci-master") || ARGV.include?("--ci-pr") \
|| ARGV.include?("--ci-testing")
ARGV << "--cleanup" if ENV["JENKINS_HOME"] || ENV["TRAVIS"]
ARGV << "--junit" << "--local"
end
if ARGV.include? "--ci-master"
ARGV << "--no-bottle" << "--email"
end
if ARGV.include? "--local"
ENV["HOMEBREW_HOME"] = ENV["HOME"] = "#{Dir.pwd}/home"
mkdir_p ENV["HOME"]
ENV["HOMEBREW_LOGS"] = "#{Dir.pwd}/logs"
end
test_bot_ci_reset_and_update if ARGV.include? "--ci-reset-and-update"
# Tap repository if required, this is done before everything else
# because Formula parsing and/or git commit hash lookup depends on it.
if tap && !tap.installed?
safe_system "brew", "tap", tap.name
end
if ARGV.include? "--ci-upload"
jenkins = ENV["JENKINS_HOME"]
job = ENV["UPSTREAM_JOB_NAME"]
id = ENV["UPSTREAM_BUILD_ID"]
@ -804,16 +762,16 @@ module Homebrew
return if bottles.empty?
FileUtils.cp bottles, Dir.pwd, :verbose => true
ENV["GIT_COMMITTER_NAME"] = "BrewTestBot"
ENV["GIT_COMMITTER_EMAIL"] = "brew-test-bot@googlegroups.com"
ENV["GIT_WORK_TREE"] = repository
ENV["GIT_AUTHOR_NAME"] = ENV["GIT_COMMITTER_NAME"] = "BrewTestBot"
ENV["GIT_AUTHOR_EMAIL"] = ENV["GIT_COMMITTER_EMAIL"] = "brew-test-bot@googlegroups.com"
ENV["GIT_WORK_TREE"] = Homebrew.homebrew_git_repo(tap)
ENV["GIT_DIR"] = "#{ENV["GIT_WORK_TREE"]}/.git"
pr = ENV["UPSTREAM_PULL_REQUEST"]
number = ENV["UPSTREAM_BUILD_NUMBER"]
system "git am --abort 2>/dev/null"
system "git rebase --abort 2>/dev/null"
quiet_system "git", "am", "--abort"
quiet_system "git", "rebase", "--abort"
safe_system "git", "checkout", "-f", "master"
safe_system "git", "reset", "--hard", "origin/master"
safe_system "brew", "update"
@ -827,8 +785,6 @@ module Homebrew
safe_system "brew", "pull", "--clean", pull_pr
end
ENV["GIT_AUTHOR_NAME"] = ENV["GIT_COMMITTER_NAME"]
ENV["GIT_AUTHOR_EMAIL"] = ENV["GIT_COMMITTER_EMAIL"]
bottle_args = ["--merge", "--write", *Dir["*.bottle.rb"]]
bottle_args << "--tap=#{tap}" if tap
bottle_args << "--keep-old" if ARGV.include? "--keep-old"
@ -878,7 +834,52 @@ module Homebrew
safe_system "git", "tag", "--force", tag
safe_system "git", "push", "--force", remote, "refs/tags/#{tag}"
return
end
def test_bot
tap = resolve_test_tap
# Tap repository if required, this is done before everything else
# because Formula parsing and/or git commit hash lookup depends on it.
if tap && !tap.installed?
safe_system "brew", "tap", tap.name
end
if Pathname.pwd == HOMEBREW_PREFIX && ARGV.include?("--cleanup")
odie "cannot use --cleanup from HOMEBREW_PREFIX as it will delete all output."
end
if ARGV.include? "--email"
File.open EMAIL_SUBJECT_FILE, "w" do |file|
# The file should be written at the end but in case we don't get to that
# point ensure that we have something valid.
file.write "#{MacOS.version}: internal error."
end
end
ENV["HOMEBREW_DEVELOPER"] = "1"
ENV["HOMEBREW_SANDBOX"] = "1"
ENV["HOMEBREW_NO_EMOJI"] = "1"
ARGV << "--verbose" if ENV["TRAVIS"]
if ARGV.include?("--ci-master") || ARGV.include?("--ci-pr") \
|| ARGV.include?("--ci-testing")
ARGV << "--cleanup" if ENV["JENKINS_HOME"] || ENV["TRAVIS"]
ARGV << "--junit" << "--local"
end
if ARGV.include? "--ci-master"
ARGV << "--no-bottle" << "--email"
end
if ARGV.include? "--local"
ENV["HOMEBREW_HOME"] = ENV["HOME"] = "#{Dir.pwd}/home"
mkdir_p ENV["HOME"]
ENV["HOMEBREW_LOGS"] = "#{Dir.pwd}/logs"
end
if ARGV.include? "--ci-reset-and-update"
return test_bot_ci_reset_and_update
elsif ARGV.include? "--ci-upload"
return test_ci_upload
end
tests = []