Sha256: 3d2d253051a57b014a78c916f54b077a522d263d9368ac700af58f776b676274

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

require 'fileutils'

module Integrity
  class Builder
    attr_reader :build_script

    def initialize(project)
      @uri = project.uri
      @build_script = project.command
      @branch = project.branch
      @scm = SCM.new(@uri, @branch, export_directory)
      @build = Build.new(:project => project)
      @project = project
    end

    def build(commit)
      Integrity.log "Building #{commit} (#{@branch}) of #{@build.project.name} in #{export_directory} using #{scm_name}"
      @scm.with_revision(commit) { 
        @project.update_attributes(:shortened_current_commit_msg => @scm.commit_metadata(commit)[:message][0..40])
        @project.update_attributes(:current_commit_identifier => @scm.commit_identifier(commit)[0..6])
        
        run_build_script
      }
      @build
    ensure
      @build.commit_identifier = @scm.commit_identifier(commit)
      @build.commit_metadata = @scm.commit_metadata(commit)
      @build.save
    end

    def delete_code
      FileUtils.rm_r export_directory
    rescue Errno::ENOENT
      nil
    end

    private
      def export_directory
        Integrity.config[:export_directory] / "#{SCM.working_tree_path(@uri)}-#{@branch}"
      end

      def scm_name
        @scm.name
      end

      def run_build_script
        Integrity.log "Running `#{build_script}` in #{@scm.working_directory}"

        IO.popen "(cd #{@scm.working_directory} && #{build_script}) 2>&1", "r" do |pipe|
          @build.output = pipe.read
        end
        @build.successful = $?.success?
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bantic-integrity-0.1.4.3 lib/integrity/builder.rb
bantic-integrity-0.1.4.4 lib/integrity/builder.rb