Module: AnotherBrick::Bricklayer

Extended by:
Bricklayer
Included in:
Bricklayer
Defined in:
lib/another_brick/bricklayer.rb

Constant Summary collapse

SUCCESS =
%r{^dpkg-buildpackage: full upload; Debian-native package \(full source is included\)}
ERROR =
%r{^dpkg-buildpackage: error:}

Instance Method Summary collapse

Instance Method Details

#base_uriObject



79
80
81
# File 'lib/another_brick/bricklayer.rb', line 79

def base_uri
  "#{AnotherBrick.bricklayer_server}/%s/#{AnotherBrick.package_name}"
end

#build(tag, project) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/another_brick/bricklayer.rb', line 53

def build(tag, project)
  new_version = tag.split('_')[1]
  build       = nil
  done        = false

  AnotherBrick.bricklayer_tries.times do
    RestClient.get(build_uri) do |response|
      builds = JSON.parse(response)

      build = builds.find do |item|
        item["release"] == AnotherBrick.release && item["version"] == new_version
      end

      break if build

      sleep 3
    end
  end

  abort "build not found for tag #{tag}" unless build

  puts "build: #{build}" if AnotherBrick.verbose?

  build["build"]
end

#build_uriObject



89
90
91
92
93
# File 'lib/another_brick/bricklayer.rb', line 89

def build_uri
  (base_uri % "build").tap do |uri|
    puts "build_uri: #{uri}" if AnotherBrick.verbose?
  end
end

#log_uri(build) ⇒ Object



95
96
97
98
99
# File 'lib/another_brick/bricklayer.rb', line 95

def log_uri(build)
  ("#{base_uri % "log"}/#{build}").tap do |uri|
    puts "log_uri: #{uri}" if AnotherBrick.verbose?
  end
end

#project(tag) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/another_brick/bricklayer.rb', line 29

def project(tag)
  project = nil

  AnotherBrick.bricklayer_tries.times do
    RestClient.get(project_uri) do |response|
      project = JSON.parse(response)

      puts "project : #{project}" if AnotherBrick.verbose?

      break if project && project["last_tag_#{AnotherBrick.release}"] == tag

      project = nil

      sleep 3
    end
  end

  abort "tag not built" unless project

  puts "project: #{project}" if AnotherBrick.verbose?

  project
end

#project_uriObject



83
84
85
86
87
# File 'lib/another_brick/bricklayer.rb', line 83

def project_uri
  (base_uri % "project").tap do |uri|
    puts "project_uri: #{uri}" if AnotherBrick.verbose?
  end
end

#succeeded?(build) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/another_brick/bricklayer.rb', line 11

def succeeded?(build)
  result = ""

  AnotherBrick.bricklayer_tries.times do
    RestClient.get(log_uri(build)) do |response|
      result = response

      break if response =~ SUCCESS or response =~ ERROR

      sleep 3
    end
  end

  puts result if AnotherBrick.verbose?

  result =~ SUCCESS
end

#wait_build(tag) ⇒ Object



7
8
9
# File 'lib/another_brick/bricklayer.rb', line 7

def wait_build(tag)
  abort "build not succeeded" unless succeeded? build(tag, project(tag))
end