Class: Perkins::Runner
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#build_time ⇒ Object
readonly
Returns the value of attribute build_time.
-
#command ⇒ Object
Returns the value of attribute command.
-
#config ⇒ Object
Returns the value of attribute config.
-
#current_build ⇒ Object
readonly
Returns the value of attribute current_build.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#repo ⇒ Object
Returns the value of attribute repo.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#sha ⇒ Object
Returns the value of attribute sha.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #config_command_with_empty_value?(result, process_status) ⇒ Boolean
- #exec(cmd) ⇒ Object
- #get_builds ⇒ Object
- #git_update(branch) ⇒ Object
- #run(sha) ⇒ Object
- #run_script(source) ⇒ Object
- #running? ⇒ Boolean
- #set_build_stats(&block) ⇒ Object
- #start_build ⇒ Object
- #stop_build ⇒ Object
- #store_report ⇒ Object
- #successful_command?(process_status) ⇒ Boolean
-
#to_report ⇒ Object
TODO: add a serialized commit in order to avoid Perkins::Commit initialization in every instantiation.
- #working_dir ⇒ Object
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
5 6 7 |
# File 'lib/perkins/runner.rb', line 5 def branch @branch end |
#build_time ⇒ Object (readonly)
Returns the value of attribute build_time.
6 7 8 |
# File 'lib/perkins/runner.rb', line 6 def build_time @build_time end |
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/perkins/runner.rb', line 5 def command @command end |
#config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/perkins/runner.rb', line 5 def config @config end |
#current_build ⇒ Object (readonly)
Returns the value of attribute current_build.
6 7 8 |
# File 'lib/perkins/runner.rb', line 6 def current_build @current_build end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
6 7 8 |
# File 'lib/perkins/runner.rb', line 6 def duration @duration end |
#repo ⇒ Object
Returns the value of attribute repo.
5 6 7 |
# File 'lib/perkins/runner.rb', line 5 def repo @repo end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
6 7 8 |
# File 'lib/perkins/runner.rb', line 6 def response @response end |
#sha ⇒ Object
Returns the value of attribute sha.
5 6 7 |
# File 'lib/perkins/runner.rb', line 5 def sha @sha end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/perkins/runner.rb', line 6 def status @status end |
Instance Method Details
#config_command_with_empty_value?(result, process_status) ⇒ Boolean
78 79 80 |
# File 'lib/perkins/runner.rb', line 78 def config_command_with_empty_value?(result, process_status) process_status.exitstatus.to_i == 1 && result.empty? end |
#exec(cmd) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/perkins/runner.rb', line 8 def exec(cmd) result = run_script(cmd) 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 ⇒ Object
110 111 112 |
# File 'lib/perkins/runner.rb', line 110 def get_builds repo.build_reports end |
#git_update(branch) ⇒ Object
86 87 88 89 90 |
# File 'lib/perkins/runner.rb', line 86 def git_update(branch) puts "fetch repo & reset to sha #{sha}".green repo.git.fetch() repo.git.reset_hard(sha) end |
#run(sha) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/perkins/runner.rb', line 35 def run(sha) self.sha = sha start_build script = Perkins::Build::script(config, repo) sh = script.compile repo.git.chdir do git_update(sha) set_build_stats do puts "perform build".green self.exec(sh) end end store_report stop_build end |
#run_script(source) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/perkins/runner.rb', line 23 def run_script(source) script = File.( "~/.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{ `bash #{script} 2>&1`.chomp } end |
#running? ⇒ Boolean
70 71 72 |
# File 'lib/perkins/runner.rb', line 70 def running? @running end |
#set_build_stats(&block) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/perkins/runner.rb', line 61 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 ⇒ Object
51 52 53 54 |
# File 'lib/perkins/runner.rb', line 51 def start_build @running = true @repo.update_column(:build_status, "started") end |
#stop_build ⇒ Object
56 57 58 59 |
# File 'lib/perkins/runner.rb', line 56 def stop_build @running = false @repo.update_column(:build_status, "stopped") end |
#store_report ⇒ Object
105 106 107 108 |
# File 'lib/perkins/runner.rb', line 105 def store_report r = Perkins::BuildReport.new(self.to_report) repo.build_reports << r end |
#successful_command?(process_status) ⇒ Boolean
74 75 76 |
# File 'lib/perkins/runner.rb', line 74 def successful_command?(process_status) process_status.exitstatus.to_i == 0 end |
#to_report ⇒ Object
TODO: add a serialized commit in order to avoid Perkins::Commit initialization in every instantiation
94 95 96 97 98 99 100 101 102 103 |
# File 'lib/perkins/runner.rb', line 94 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 ⇒ Object
82 83 84 |
# File 'lib/perkins/runner.rb', line 82 def working_dir repo.git.dir.path end |