Sha256: 73f3dab41ac0477c9a5de7d36bd1803bee83103e733153ad1a6fa93992cdc8b1

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 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)
    end

    def build(commit)
      Integrity.logger.info "Building #{commit} (#{@branch}) of #{@build.project.name} in #{export_directory} using #{scm_name}"
      @scm.with_revision(commit) { 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.logger.info "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

3 entries across 3 versions & 1 rubygems

Version Path
foca-integrity-0.1.1 lib/integrity/builder.rb
foca-integrity-0.1.2 lib/integrity/builder.rb
foca-integrity-0.1.3 lib/integrity/builder.rb