Changeset 2732
- Timestamp:
- 10/25/05 19:56:10 (3 years ago)
- Files:
-
- plugins/continuous_builder/lib/continuous_builder.rb (modified) (2 diffs)
- plugins/continuous_builder/tasks/test_build.rake (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/continuous_builder/lib/continuous_builder.rb
r2729 r2732 1 1 module ContinuousBuilder 2 2 class Build 3 attr_reader :status, :output, :success, :options 4 5 def self.run 6 Build.new.run 7 end 8 3 attr_reader :output, :success, :checkout, :status 4 9 5 def initialize(options = {}) 10 @options = options 6 @options = options 7 8 @status = Status.new(@options[:application_root] + "/log/last_build.log") 9 10 @checkout = Checkout.new(options) 11 @checkout.update! 11 12 end 12 13 13 14 def run 14 update if @status.nil? 15 make if @success.nil? 15 previous_status = @status.recall 16 17 run_status = if checkout.has_changes? 18 if status = make 19 @status.keep(:succesful) 20 previous_status == :failed ? :revived : :succesful 21 else 22 @status.keep(:failed) 23 previous_status == :failed ? :broken : :failed 24 end 25 else 26 :unchanged 27 end 28 29 $stderr << "run: #{run_status.inspect}" 30 31 run_status 16 32 end 17 33 18 def revision 34 private 35 def make 36 @output = `cd #{@options[:application_root]} && RAILS_ENV=test #{@options[:env_command]} rake #{@options[:task_name]}` 37 make_successful? 38 end 39 40 def make_successful? 41 $?.exitstatus == 0 42 end 43 end 44 45 class Checkout 46 def initialize(path, options = {}) 47 @path, @options = path, options 48 end 49 50 def update! 51 @status = execute("svn update") 52 end 53 54 def has_changes? 55 @status =~ /[A-Z]\s+[\w\/]+/ 56 end 57 58 def current_revision 19 59 info['Revision'].to_i 20 60 end … … 24 64 end 25 65 26 def commit_message27 `#{options[:env_command]} svn log #{RAILS_ROOT} -rHEAD -v`66 def last_commit_message 67 execute("svn log", " -rHEAD -v") 28 68 end 29 69 30 def author70 def last_author 31 71 info['Last Changed Author'] 32 72 end 33 34 def tests_ok? 35 run if @success.nil? 36 @success == true 37 end 38 39 def has_changes? 40 update if @status.nil? 41 @status =~ /[A-Z]\s+[\w\/]+/ 42 end 43 73 44 74 private 45 def update46 @ status = `#{options[:env_command]} svn update #{RAILS_ROOT}`75 def info 76 @info ||= YAML.load(execute("svn info")) 47 77 end 48 49 def info 50 @info ||= YAML.load(`#{options[:env_command]} svn info #{RAILS_ROOT}`) 51 end 52 53 def make 54 @output, @success = `cd #{RAILS_ROOT} && RAILS_ENV=test #{options[:env_command]} rake #{options[:task_name]}`, ($?.exitstatus == 0) 78 79 def execute(command, parameters = nil) 80 `#{@options[:env_command]} #{command} #{@options[:application_root]} #{parameters}` 55 81 end 56 82 end 57 83 84 class Status 85 def initialize(path) 86 @path = path 87 end 88 89 def keep(status) 90 File.open(@path, "w+", 0777) { |file| file.write(status.to_s) } 91 end 92 93 def recall 94 value = File.exists?(@path) ? File.read(@path) : false 95 value.blank? ? false : value.to_sym 96 end 97 end 98 58 99 class Notifier < ActionMailer::Base 59 def failure(build, application, email_to, email_from, sent_at = Time.now) 60 @subject = "[#{application}] Build Failure (##{build.revision})" 61 @body = [ "#{build.author} broke the build!", build.commit_message, build.output ].join("\n\n") 62 @recipients, @from, @sent_on = email_to, email_from, sent_at 100 def failure(build, options, sent_at = Time.now) 101 @subject = "[#{options[:application_name]}] Build broken by #{build.checkout.last_author} (##{build.checkout.current_revision})" 102 @body = [ build.checkout.last_commit_message, build.output ].join("\n\n") 103 104 @recipients, @from, @sent_on = options[:recipients], options[:sender], sent_at 105 end 106 107 def broken(build, options, sent_at = Time.now) 108 @subject = "[#{options[:application_name]}] Build still broken (##{build.checkout.current_revision})" 109 @body = [ 110 "#{build.checkout.last_author} did not manage to fix the build with this checkin", 111 build.checkout.last_commit_message, 112 build.output 113 ].join("\n\n") 114 115 @recipients, @from, @sent_on = options[:recipients], options[:sender], sent_at 116 end 117 118 def revival(build, options, sent_at = Time.now) 119 @subject = "[#{options[:application_name]}] Build fixed by #{build.checkout.last_author} (##{build.checkout.current_revision})" 120 @body = [ build.checkout.last_commit_message ].join("\n\n") 121 122 @recipients, @from, @sent_on = options[:recipients], options[:sender], sent_at 63 123 end 64 124 end plugins/continuous_builder/tasks/test_build.rake
r2729 r2732 4 4 5 5 build = ContinuousBuilder::Build.new( 6 :task_name => ENV['RAKE_TASK'] || '', 7 :env_command => ENV['ENV_COMMAND'] || "/usr/bin/env" 6 :task_name => ENV['RAKE_TASK'] || '', 7 :env_command => ENV['ENV_COMMAND'] || "/usr/bin/env", 8 :application_root => RAILS_ROOT 8 9 ) 9 10 if build.has_changes? && !build.tests_ok? 11 ContinuousBuilder::Notifier.deliver_failure( 12 build, ENV['NAME'], ENV['EMAIL_TO'], ENV['EMAIL_FROM'] || "'Continuous Builder' <cb@example.com>" 13 ) 10 11 notice_options = { 12 :application_name => ENV['NAME'], 13 :recipients => ENV['RECIPIENTS'], 14 :sender => ENV['SENDER'] || "'Continuous Builder' <cb@example.com>" 15 } 16 17 case build.run 18 when :failed 19 ContinuousBuilder::Notifier.deliver_failure(build, notice_options) 20 when :revived 21 ContinuousBuilder::Notifier.deliver_revival(build, notice_options) 22 when :broken 23 ContinuousBuilder::Notifier.deliver_broken(build, notice_options) 24 when :unchanged, :succesful 25 # Smile, be happy, it's all good 14 26 end 15 27 end