class Perkins::Runner
Attributes
branch[RW]
include Process
build_time[R]
command[RW]
include Process
config[RW]
include Process
current_build[R]
duration[R]
repo[RW]
include Process
report[RW]
include Process
response[R]
sha[RW]
include Process
status[R]
Public Instance Methods
config_command_with_empty_value?(result, process_status)
click to toggle source
# File lib/perkins/runner.rb, line 124 def config_command_with_empty_value?(result, process_status) process_status.exitstatus.to_i == 1 && result.empty? end
exec(cmd)
click to toggle source
# File lib/perkins/runner.rb, line 10 def exec(cmd) result = run_script(cmd) @response = result.join("") if result.last.chomp.include?("with 0") @status = true elsif result.last.chomp.include?("with 1") @status = false else puts "status result not found!!" @status = false end #puts result #process_status = $? #if successful_command?(process_status) || config_command_with_empty_value?(result,process_status) # @response = result # @status = true # return result #else # @response = result # @status = false #end end
get_builds()
click to toggle source
# File lib/perkins/runner.rb, line 155 def get_builds repo.build_reports end
git_update(branch)
click to toggle source
# File lib/perkins/runner.rb, line 132 def git_update(branch) puts "fetch repo & reset to sha #{sha}".green repo.git.fetch() repo.git.reset_hard(sha) end
pipe_command(cmd)
click to toggle source
# File lib/perkins/runner.rb, line 48 def pipe_command(cmd) output = [] r, io = IO.pipe pid = fork do @process = system(cmd, out: io, err: :out) end io.close r.each_line{|l| puts l.yellow output << l #puts "CURRENT DIR: #{Dir.pwd} !!!!!" #puts "CURRENT GIT DIR: #{repo.git.dir.path} !!!!!" #puts "#{repo.download_name} !!!!!!!" #updates each time, this should trigger event to interface to refresh @current_report.update_column(:response, output.join("")) } #Process.waitpid(p1) #this is to get the $ exitstatus output end
run(sha)
click to toggle source
# File lib/perkins/runner.rb, line 68 def run(sha) self.sha = sha start_build self.repo.virtual_sha = "-#{@current_report.id}-#{self.sha}" #it actually clone repo and instantiates git data repo.load_git script = Perkins::Build::script(config, repo) sh = script.compile repo.git.chdir do #puts "CURRENT DIR: #{Dir.pwd} !!!!!" #puts "CURRENT GIT DIR: #{repo.git.dir.path} !!!!!" git_update(sha) set_build_stats do puts "perform build".green self.exec(sh) end end #store_report stop_build end
run_script(source)
click to toggle source
# File lib/perkins/runner.rb, line 35 def run_script(source) script = File.expand_path( "~/.perkins/.build/#{repo.name}/travis-build-#{sha}" #<< stages.join('-') ) FileUtils.mkdir_p(File.dirname(script)) File.open(script, 'w') { |f| f.write(source) } FileUtils.chmod(0755, script) Bundler.with_clean_env{ pipe_command("#{script} 2>&1") #`bash #{script} 2>&1`.chomp } end
running?()
click to toggle source
# File lib/perkins/runner.rb, line 116 def running? @running end
set_build_stats(&block)
click to toggle source
# File lib/perkins/runner.rb, line 107 def set_build_stats(&block) up = Time.now #call the command itself block.call down = Time.now @build_time = down @duration = down - up end
start_build()
click to toggle source
# File lib/perkins/runner.rb, line 91 def start_build @running = true store_report @current_report.start! @repo.update_column(:build_status, "started") end
stop_build()
click to toggle source
# File lib/perkins/runner.rb, line 98 def stop_build @running = false @current_report.stop! @current_report.update_attributes(self.to_report) @repo.update_column(:build_status, "stopped") end
store_report()
click to toggle source
# File lib/perkins/runner.rb, line 151 def store_report @current_report = Perkins::BuildReport.find(report) end
successful_command?(process_status)
click to toggle source
# File lib/perkins/runner.rb, line 120 def successful_command?(process_status) process_status.exitstatus.to_i == 0 end
to_report()
click to toggle source
TODO: add a serialized commit in order to avoid Perkins::Commit
initialization in every instantiation
# File lib/perkins/runner.rb, line 140 def to_report { build_time: self.build_time, duration: self.duration, response: self.response, status: self.status, sha: self.sha, branch: self.branch } end
working_dir()
click to toggle source
# File lib/perkins/runner.rb, line 128 def working_dir repo.git.dir.path end