Sha256: f94fedd0dd0734260bc6a80020f03ca14d8489da18fc1038c23146552a9344ed

Contents?: true

Size: 1.89 KB

Versions: 5

Compression:

Stored size: 1.89 KB

Contents

# Figure out the root path of this app. The default method will assume that 
# its the same as the location of the running Rakefile
ROOT = File.expand_path(FileUtils.pwd) + '/'

# Standard settings, you can override each of them using the environment 
# e.g. rake cia EMAIL_TO=your@email.com 
#
RAKE_TASK   = ENV['RAKE_TASK']  || ''
EMAIL_TO    = ENV['EMAIL_TO']   || 'tobi@leetsoft.com'
EMAIL_FROM  = ENV['EMAIL_FROM'] || 'CIA <cia@jadedpixel.com>' 

# Get last segment of application's path and treat it as name. 
NAME        = ENV['NAME'] || ROOT.scan(/(\w+)\/$/).flatten.first.capitalize 


class Build
  attr_reader :status, :output, :success

  def self.run
    Build.new.run
  end
  
  def run 
    update if @status.nil?    
    make if @success.nil?
  end
  
  def revision
    info['Revision'].to_i
  end
  
  def url
    info['URL']
  end
  
  def commit_message
    `svn log #{ROOT} -rHEAD`
  end
  
  def author
    info['Last Changed Author']
  end

  def tests_ok?
    run if @success.nil?
    @success == true
  end
  
  def has_changes?
    update if @status.nil?    
    @status =~ /[A-Z]\s+[\w\/]+/
  end

  private

  def update
    @status = `svn update #{ROOT}`
  end
  
  def info
    @info ||= YAML.load(`svn info #{ROOT}`)
  end
    
  def make
    @output, @success = `cd #{ROOT} && rake #{RAKE_TASK}`, ($?.exitstatus == 0)
  end
end

task :cia do
  build = Build.new
  
  if build.has_changes? and not build.tests_ok? 

    require_gem 'actionmailer'

    ActionMailer::Base.delivery_method = :sendmail

    class Notifier < ActionMailer::Base
      def failure(build, sent_at = Time.now)
        @subject    = "[#{NAME}] Build Failure (##{build.revision})"
        @recipients, @from, @sent_on = EMAIL_TO, EMAIL_FROM, sent_at
        @body       = ["#{build.author} broke the build!", build.commit_message, build.output].join("\n\n")
      end
    end
    
    Notifier.deliver_failure(build)

  end 
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
activemerchant-1.0.0 lib/tasks/cia.rb
activemerchant-1.0.2 lib/tasks/cia.rb
activemerchant-1.1.0 lib/tasks/cia.rb
activemerchant-1.0.3 lib/tasks/cia.rb
activemerchant-1.0.1 lib/tasks/cia.rb