This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathbuild_and_publish
executable file
·84 lines (65 loc) · 2.45 KB
/
build_and_publish
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
48
49
50
51
52
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
78
79
80
81
82
83
84
#!/usr/bin/env ruby
require 'mixlib/shellout'
require 'cinch'
require 'open-uri'
require 'chronic_duration'
require 'benchmark'
require 'logger'
# Wrapper for the build_and_publish rake task
# Assumes you have permission to packages.flapjack.io S3 bucket for writing
distro, distro_release, build_ref = ARGV
build_ref_clean = build_ref.sub(/\//, '.')
start_time = Time.now.utc
tstamp = start_time.strftime('%Y%m%dT%H%M%S')
unless distro && distro_release && build_ref
puts "Must be called with the following arguments:"
puts " build_and_publish DISTRO DISTRO_RELEASE BUILD_REF"
puts "eg:"
puts " build_and_publish ubuntu precise v1.2.0rc2"
exit 1
end
log_file = "flapjack_#{build_ref_clean}-#{tstamp}-#{distro}-#{distro_release}.log"
log = Logger.new(log_file)
log.info "Running build of #{build_ref} on #{distro} #{distro_release} at #{tstamp}"
rake = nil
build_duration = Benchmark.realtime do
rake = Mixlib::ShellOut.new("OFFICIAL_FLAPJACK_PACKAGE=true BUILD_REF=#{build_ref} DISTRO=#{distro} " +
"DISTRO_RELEASE=#{distro_release} FLAPJACK_COMPONENT=experimental " +
"bundle exec rake build_and_publish 2>&1", :timeout => 60 * 60 * 3)
rake.run_command
end
if rake.error?
log.info "Failure running `bundle exec rake build_and_publish`"
else
log.info "Success running `bundle exec rake build_and_publish`"
end
log.info "Command: #{rake.command}"
log.info "Output: "
log.info rake.stdout
duration_string = ChronicDuration.output(build_duration.round(0), :format => :short)
success_string = !rake.error? ? 'Successful' : 'Failed'
log.info "#{success_string} build of #{build_ref} on #{distro} " +
"#{distro_release} at #{Time.now.utc.iso8601}, duration: #{duration_string}"
log_dst = "packages.flapjack.io/build_logs/#{log_file}"
puts "#{success_string}. Uploading log to #{log_dst}"
log_upload = Mixlib::ShellOut.new("aws s3 cp #{log_file} s3://#{log_dst}")
log_upload.run_command
begin
log_url = open("http://is.gd/create.php?format=simple&url=http://#{log_dst}").first
rescue
log_url = "http://#{log_dst}"
end
message = "#{success_string} build of Flapjack #{build_ref} for #{distro} #{distro_release} package (experimental) in #{duration_string}, log: #{log_url}"
puts 'sending message to #flapjack: ' + message
bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.channels = ["#flapjack"]
c.nick = 'roberta'
end
on :connect do |connection|
Channel('#flapjack').send(message)
bot.quit
end
end
bot.start