forked from integrity/integrity
/
builder.rb
47 lines (40 loc) · 1.2 KB
/
builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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.split("::").last
end
def run_build_script
IO.popen "(cd #{@scm.working_directory} && #{build_script}) 2>&1", "r" do |pipe|
@build.output = pipe.read
end
@build.successful = $?.success?
end
end
end