Sha256: 2844da1a18346c58b05a9db3fc3886b336cb405bfc7485ed81a770114c181bcb

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

require 'heidi/build'
require 'heidi/builder'
require 'heidi/tester'
require 'time'

class Heidi
  class Integrator
    attr_reader :build, :project

    def initialize(project)
      @project = project
      @build   = Heidi::Build.new(project)
      @failed  = false
    end

    def failure
      @failed = true
      build.record(:failure)
    end

    def integrate
      start = Time.now
      build.lock
      build.load_hooks
      build.clean

      return failure if !run_hooks(:before)

      builder = Heidi::Builder.new(build)
      tester = Heidi::Tester.new(build)

      return failure if !builder.build!
      return failure if !tester.test!
      return failure if !run_hooks(:after)

      # record the new succesful
      build.record(:success)

      # create a tarball
      build.create_tar_ball

      build.log :info, ("Integration took: %.2fs" % (Time.now - start))
      return true

    rescue Exception => e
      $stderr.puts e.message
      $stderr.puts e.backtrace.join("\n")

      return $!

    ensure
      run_hooks(:failed) if @failed == true

      # always unlock the build root, no matter what
      build.unlock

      return @failed == true ? false : true

    end

    def run_hooks(where)
      return true if build.hooks[where].nil? || build.hooks[where].empty?

      hooks_failed = false
      build.hooks[where].each do |hook|
        res = hook.perform(build.build_root)

        if res.S?.to_i != 0
          build.log :error, "--- #{where} hook: #{hook.name} failed ---"
          build.log :error, res.err

          hooks_failed = true
          break

        else
          build.log :info, res.out
        end
      end

      return hooks_failed == true ? false : true
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
heidi-0.0.2 lib/heidi/integrator.rb
heidi-0.0.1 lib/heidi/integrator.rb