Class: Heidi::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/heidi/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(build) ⇒ Builder

Returns a new instance of Builder.



8
9
10
11
# File 'lib/heidi/builder.rb', line 8

def initialize(build)
  @build   = build
  @project = build.project
end

Instance Attribute Details

#buildObject (readonly)

Returns the value of attribute build.



6
7
8
# File 'lib/heidi/builder.rb', line 6

def build
  @build
end

#projectObject (readonly)

Returns the value of attribute project.



6
7
8
# File 'lib/heidi/builder.rb', line 6

def project
  @project
end

Instance Method Details

#build!Object



13
14
15
# File 'lib/heidi/builder.rb', line 13

def build!
  return self.setup_build_dir
end

#create_tar_ballObject



63
64
65
66
67
68
69
70
71
72
# File 'lib/heidi/builder.rb', line 63

def create_tar_ball
  shell = SimpleShell.new(build.root)
  shell.mv %W(build #{build.commit})
  tar = shell.tar %W(--exclude .git -cjf #{build.commit}.tar.bz2 #{build.commit})
  if tar.S?.to_i == 0
    shell.rm %W(-rf #{build.commit}/)
  else
    build.log(:error, "Creating tar-ball failed: #{tar.err}")
  end
end

#log(string) ⇒ Object



74
75
76
# File 'lib/heidi/builder.rb', line 74

def log(string)
  build.logs["builder.log"].raw(string)
end

#setup_build_dirObject



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/heidi/builder.rb', line 17

def setup_build_dir
  if build.locked? and !build.locked_build?
    build.log(:error, "The build was locked externaly")
    return false
  end

  if File.exists? build.build_root
    build.log(:info, "Removing previous build")
    build.shell.do "rm", "-r", build.build_root
  end

  build.log(:info, "Creating new clone")
  clone = build.shell.git %W(clone #{@project.cached_root} #{File.basename(build.build_root)})

  if !File.exists?(build.build_root) || clone.S?.to_i != 0
    build.log :error, "git clone failed: #{clone.err}"
    return false
  end

  if project.branch
    @git = Heidi::Git.new(build.build_root)

    branch = project.branch
    build.log(:info, "Switching to integration branch: #{branch}")
    res = @git.switch(branch)
    if res.nil?
      build.log(:info, "Creating integration branch from origin/#{branch}")
      @git.checkout(branch, "origin/#{branch}")
    end

    res = @git.switch(branch)
    if res.S?.to_i != 0
      build.log(:error, "switching to '#{branch}' failed: #{res.err}")
      return false
    end

  else
    build.log(:info, "Using master as the integration branch")

  end

  build.lock

  return true
end