Branch :
#!/usr/bin/env ruby
load "#{File.dirname(File.dirname(__FILE__))}/lib/rbpkg.rb"
$ARGS = ARGV
def shift
usage if $ARGS == []
arg = $ARGS[0]
$ARGS = $ARGS[1..] || []
arg
end
verbose_level = 2 # print command output
case $ARGS[0]
when "-v"
verbose_level = 3 # print all messages
shift
when "-q"
verbose_level = 1 # print commands
shift
when "-qq"
verbose_level = 0 # print nothing
shift
end
Rbpkg.init("rbpkg_ci_mux", verbose_level, Rbpkg.ci_log_dir, Rbpkg.ci_status_dir)
Rbpkg.ci_init
def usage()
STDERR.puts "Usage: #{File.basename($0)} REPO BRANCH COMMIT REMOTE ..."
exit 1
end
def pop_arg
case $ARGS[0]
when "--clean"
rbpkg_ci_mux_clean
when "-h"
usage
when "--help"
usage
when "--install"
rbpkg_ci_mux_install
when "--no-remote"
Rbpkg.ci_mux
Rbpkg::Log.ok_all
exit 0
when "--upgrade"
rbpkg_ci_mux_upgrade
end
end
def rbpkg_ci_mux
while pop_arg
true
end
repo = shift
branch = shift
commit = shift
hosts = $ARGS
Thread.report_on_exception = false
threads = []
hosts.each do |host|
threads << Thread.new do
Rbpkg.ci_remote(repo, branch, commit, host)
end
end
threads.each do |t|
t.join
end
Rbpkg.ci_mux
end
def rbpkg_ci_mux_clean
shift
cmd = "rm -rf #{sh_quote(Rbpkg.ci_dir)}"
verbose(1, cmd)
raise "command failed: #{cmd.inspect}" unless system(cmd)
Rbpkg.ci_init
hosts = $ARGS
hosts.each do |host|
cmd! "ssh #{sh_quote(host)} rbpkg/bin/rbpkg_ci --clean"
end
Rbpkg::Log.ok_all
exit 0
end
def rbpkg_ci_mux_install
shift
hosts = $ARGS
hosts.each do |host|
cmd! "ssh #{sh_quote(host)} git clone https://git.kmx.io/kmx.io/rbpkg.git"
end
Rbpkg::Log.ok_all
exit 0
end
def rbpkg_ci_mux_upgrade
Rbpkg.upgrade_self
shift
hosts = $ARGS
hosts.each do |host|
cmd! "ssh #{sh_quote(host)} rbpkg/bin/rbpkg upgrade"
end
Rbpkg::Log.ok_all
exit 0
end
begin
rbpkg_ci_mux
Rbpkg::Log.ok_all
rescue => error
verbose(-1, error.backtrace.reverse.join("\n"))
verbose(-1, "#{error.class.name}: #{error.message}")
exit 1
end