build-buddy 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/build-buddy +33 -31
- data/lib/build_buddy.rb +2 -2
- data/lib/build_buddy/build_data.rb +21 -0
- data/lib/build_buddy/builder.rb +6 -2
- data/lib/build_buddy/config.rb +8 -1
- data/lib/build_buddy/server.rb +18 -18
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42ef29e6a888d9a89ced4aa309d964810eb39727
|
4
|
+
data.tar.gz: 9042302dd8276aa3f0cb4e6b6d56f5bb8d32a869
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec95fce9bc150e5d93210959c58d8840ceefe1b8ef4ef4b99e18a7de742e091ee142a016aa25428040779895740f9ba21476e7cc3bbbd7613cb85f17c182a293
|
7
|
+
data.tar.gz: 1e64657ef0e400bac314eb75a1fcab1d1b60ba3a18cc5a0d7e53568b6b80c6ba3ddafb39b34f1573ae8ae10ba5f6012c13230e11fe3387a2eff6d1723c754ca7
|
data/bin/build-buddy
CHANGED
@@ -8,46 +8,48 @@ require 'celluloid/supervision/container'
|
|
8
8
|
require 'methadone'
|
9
9
|
require 'build_buddy'
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
module BuildBuddy
|
12
|
+
class Tool
|
13
|
+
include Methadone::Main
|
14
|
+
include Methadone::CLILogging
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
main do |config_name|
|
17
|
+
config_file_name = config_name
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
if File.extname(config_file_name) != '.bbconfig'
|
20
|
+
config_file_name += '.bbconfig'
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
+
load config_file_name
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
config_path = File.dirname(config_file_name)
|
26
|
+
Config.pull_request_build_script = File.expand_path(Config.pull_request_build_script, config_path)
|
27
|
+
Config.master_build_script = File.expand_path(Config.master_build_script, config_path)
|
28
|
+
Config.release_build_script = File.expand_path(Config.release_build_script, config_path)
|
29
|
+
Config.build_log_dir = File.expand_path(Config.build_log_dir, config_path)
|
29
30
|
|
30
|
-
|
31
|
+
build_log_dir = BuildBuddy::Config.build_log_dir
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
33
|
+
unless Dir.exist?(build_log_dir)
|
34
|
+
Dir.mkdir(build_log_dir)
|
35
|
+
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
Slack.configure do |config|
|
38
|
+
config.token = Config.slack_api_token
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
Celluloid.logger = Reel::Logger.logger
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
Builder.supervise as: :builder
|
44
|
+
Server.supervise as: :server
|
44
45
|
|
45
|
-
|
46
|
-
|
46
|
+
sleep
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
49
|
+
version BuildBuddy::VERSION
|
50
|
+
description 'Build Buddy'
|
51
|
+
arg :config_name, :required
|
51
52
|
|
52
|
-
|
53
|
-
end
|
53
|
+
go!
|
54
|
+
end
|
55
|
+
end
|
data/lib/build_buddy.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module BuildBuddy
|
2
|
+
class BuildData
|
3
|
+
attr_accessor :build_type # one of :master, :release or :pull_request
|
4
|
+
attr_accessor :repo_full_name
|
5
|
+
attr_accessor :build_version
|
6
|
+
attr_accessor :repo_full_name
|
7
|
+
attr_accessor :repo_sha
|
8
|
+
attr_accessor :termination_type
|
9
|
+
attr_accessor :exit_code
|
10
|
+
attr_accessor :start_time
|
11
|
+
attr_accessor :end_time
|
12
|
+
attr_accessor :build_log_filename
|
13
|
+
|
14
|
+
def initialize(build_type, args)
|
15
|
+
@build_type = build_type
|
16
|
+
@repo_full_name = args[:repo_full_name]
|
17
|
+
@repo_sha = args[:repo_sha]
|
18
|
+
@build_version = args[:build_version]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/build_buddy/builder.rb
CHANGED
@@ -46,8 +46,10 @@ module BuildBuddy
|
|
46
46
|
raise "Unknown build type"
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
49
|
+
@build_data.start_time = Time.now.utc
|
50
|
+
build_log_filename = File.join(Config.build_log_dir,
|
51
|
+
"build_#{build_data.build_type.to_s}_#{build_data.start_time.strftime('%Y%m%d_%H%M%S')}.log")
|
52
|
+
@build_data.build_log_filename = build_log_filename
|
51
53
|
|
52
54
|
Bundler.with_clean_env do
|
53
55
|
@pid = Process.spawn(env, command, :pgroup => true, [:out, :err] => build_log_filename)
|
@@ -64,6 +66,7 @@ module BuildBuddy
|
|
64
66
|
end
|
65
67
|
|
66
68
|
def process_done(status)
|
69
|
+
@build_data.end_time = Time.now.utc
|
67
70
|
@build_data.termination_type = (status.signaled? ? :killed : :exited)
|
68
71
|
@build_data.exit_code = (status.exited? ? status.exitstatus : -1)
|
69
72
|
info "Process #{status.pid} #{@build_data.termination_type == :killed ? 'was terminated' : "exited (#{@build_data.exit_code})"}"
|
@@ -76,6 +79,7 @@ module BuildBuddy
|
|
76
79
|
if @gid
|
77
80
|
info "Killing gid #{@gid}"
|
78
81
|
Process.kill(:SIGABRT, -@gid)
|
82
|
+
@gid = nil
|
79
83
|
end
|
80
84
|
end
|
81
85
|
end
|
data/lib/build_buddy/config.rb
CHANGED
@@ -2,6 +2,8 @@ module BuildBuddy
|
|
2
2
|
module Config
|
3
3
|
extend self
|
4
4
|
|
5
|
+
attr_accessor :github_webhook_port
|
6
|
+
attr_accessor :github_webhook_path
|
5
7
|
attr_accessor :github_webhook_secret_token
|
6
8
|
attr_accessor :github_webhook_repo_full_name
|
7
9
|
attr_accessor :github_api_token
|
@@ -14,10 +16,15 @@ module BuildBuddy
|
|
14
16
|
attr_accessor :pull_request_build_script
|
15
17
|
attr_accessor :master_build_script
|
16
18
|
attr_accessor :release_build_script
|
17
|
-
|
19
|
+
attr_accessor :valid_release_versions
|
20
|
+
attr_accessor :kill_build_after_mins
|
21
|
+
end
|
18
22
|
|
19
23
|
class << self
|
20
24
|
def configure
|
25
|
+
Config.github_webhook_port = 4567
|
26
|
+
Config.github_webhook_path = '/webhook'
|
27
|
+
Config.kill_build_after_mins = 30
|
21
28
|
block_given? ? yield(Config) : Config
|
22
29
|
end
|
23
30
|
|
data/lib/build_buddy/server.rb
CHANGED
@@ -3,7 +3,6 @@ require 'celluloid/current'
|
|
3
3
|
require 'reel'
|
4
4
|
require 'slack-ruby-client'
|
5
5
|
require 'json'
|
6
|
-
require 'ostruct'
|
7
6
|
require 'octokit'
|
8
7
|
require 'thread'
|
9
8
|
require 'timers'
|
@@ -14,7 +13,7 @@ module BuildBuddy
|
|
14
13
|
class Server < Reel::Server::HTTP
|
15
14
|
include Celluloid::Internals::Logger
|
16
15
|
|
17
|
-
def initialize(host = "127.0.0.1", port =
|
16
|
+
def initialize(host = "127.0.0.1", port = Config.github_webhook_port)
|
18
17
|
super(host, port, &method(:on_connection))
|
19
18
|
@gh_client ||= Octokit::Client.new(:access_token => Config.github_api_token)
|
20
19
|
@rt_client = Slack::RealTime::Client.new
|
@@ -106,23 +105,24 @@ module BuildBuddy
|
|
106
105
|
case message
|
107
106
|
when /master/i
|
108
107
|
response = "OK, I've queued a build of the `master` branch."
|
109
|
-
queue_a_build(
|
110
|
-
:build_type => :master,
|
108
|
+
queue_a_build(BuildData.new(:master,
|
111
109
|
:repo_full_name => Config.github_webhook_repo_full_name))
|
112
110
|
when /(?<version>v\d+\.\d+)/
|
113
111
|
version = $~[:version]
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
112
|
+
if Config.valid_release_versions.include?(version)
|
113
|
+
response = "OK, I've queued a build of `#{version}` branch."
|
114
|
+
queue_a_build(BuildData.new(:release,
|
115
|
+
:build_version => version,
|
116
|
+
:repo_full_name => Config.github_webhook_repo_full_name))
|
117
|
+
else
|
118
|
+
response = "I'm sorry, I cannot build the #{version} release branch"
|
119
|
+
end
|
119
120
|
when /stop/i
|
120
121
|
build_data = @active_build
|
121
122
|
if build_data.nil?
|
122
123
|
response = "There is no build running to stop"
|
123
124
|
else
|
124
|
-
|
125
|
-
response = "OK, I'm trying to *stop* the currently running build..."
|
125
|
+
response = "OK, I killed the currently running build..."
|
126
126
|
Celluloid::Actor[:builder].async.stop_build
|
127
127
|
end
|
128
128
|
else
|
@@ -178,7 +178,7 @@ module BuildBuddy
|
|
178
178
|
case request.method
|
179
179
|
when 'POST'
|
180
180
|
case request.path
|
181
|
-
when
|
181
|
+
when Config.github_webhook_path
|
182
182
|
case request.headers["X-GitHub-Event"]
|
183
183
|
when 'pull_request'
|
184
184
|
payload_text = request.body.to_s
|
@@ -188,12 +188,11 @@ module BuildBuddy
|
|
188
188
|
else
|
189
189
|
payload = JSON.parse(payload_text)
|
190
190
|
pull_request = payload['pull_request']
|
191
|
-
build_data =
|
192
|
-
:build_type => :pull_request,
|
191
|
+
build_data = BuildData.new(:pull_request,
|
193
192
|
:pull_request => pull_request['number'],
|
194
193
|
:repo_sha => pull_request['head']['sha'],
|
195
194
|
:repo_full_name => pull_request['base']['repo']['full_name'])
|
196
|
-
info "Got pull request #{build_data
|
195
|
+
info "Got pull request #{build_data.pull_request} from GitHub"
|
197
196
|
queue_a_build(build_data)
|
198
197
|
request.respond 200
|
199
198
|
end
|
@@ -235,7 +234,6 @@ module BuildBuddy
|
|
235
234
|
if @build_queue.length > 0
|
236
235
|
build_data = @build_queue.pop()
|
237
236
|
@active_build = build_data
|
238
|
-
# TODO: Add timing information into the build_data
|
239
237
|
if build_data.build_type == :pull_request
|
240
238
|
@gh_client.create_status(
|
241
239
|
build_data.repo_full_name, build_data.repo_sha, 'pending',
|
@@ -243,7 +241,6 @@ module BuildBuddy
|
|
243
241
|
end
|
244
242
|
Celluloid::Actor[:builder].async.start_build(build_data)
|
245
243
|
elsif @done_queue.length > 0
|
246
|
-
# TODO: Should pop everything in the done queue
|
247
244
|
build_data = @done_queue.pop
|
248
245
|
term_msg = (build_data.termination_type == :killed ? "was stopped" : "completed")
|
249
246
|
if build_data.termination_type == :exited
|
@@ -279,7 +276,10 @@ module BuildBuddy
|
|
279
276
|
info "Build timer stopped"
|
280
277
|
end
|
281
278
|
else
|
282
|
-
#
|
279
|
+
# Make sure that the build has not run too long and kill if necessary
|
280
|
+
if Time.now.utc - @active_build.start_time > Config.kill_build_after_mins * 60
|
281
|
+
Celluloid::Actor[:builder].async.stop_build()
|
282
|
+
end
|
283
283
|
end
|
284
284
|
end
|
285
285
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: build-buddy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Lyon-smith
|
@@ -173,6 +173,7 @@ extra_rdoc_files: []
|
|
173
173
|
files:
|
174
174
|
- bin/build-buddy
|
175
175
|
- lib/build_buddy.rb
|
176
|
+
- lib/build_buddy/build_data.rb
|
176
177
|
- lib/build_buddy/builder.rb
|
177
178
|
- lib/build_buddy/config.rb
|
178
179
|
- lib/build_buddy/server.rb
|