aboutsummaryrefslogtreecommitdiff
blob: bbe0b2354032a9e65ee607561cc804b4fbd42196 (plain)
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
def run_ci(volume_container, ci_image, ci_type, num_of_packages)
	packages = generate_package_list(ci_type, num_of_packages)

	packages.peach(8) do |package|
		package = package.split(' ')
		identifier = package[0]
		current_target = package[1]
		next_target = package[2]

		if ci_type == 'build'
			cmd = %W[/ruby-tinderbox/tinder.sh #{identifier} #{current_target} #{next_target}]
		elsif ci_type == 'repoman'
			cmd = %W[/ruby-tinderbox/repoman.sh #{identifier} #{current_target} #{next_target}]
		end
		ci_container = Docker::Container.create(
			Cmd: cmd,
			Image: ci_image.id
		)
		ci_container.start(VolumesFrom: volume_container.id)
		ci_container.wait(36_000)

		tar = Tempfile.new('tar')
		File.open(tar, 'w') do |file|
			ci_container.copy('/ruby-tinderbox/ci-logs') do |chunk|
				file.write(chunk)
			end
		end
		Archive::Tar::Minitar.unpack(tar, File.dirname(File.expand_path(File.dirname(__FILE__))))
		tar.close
		tar.unlink

		ci_container.delete
	end
end

def generate_package_list(ci_type, num_of_packages)
	packages = []
	Package.each do |package|
		packages << package[:identifier]
	end

	if num_of_packages == 'all'
		packages = packages
	elsif num_of_packages == 'untested' and ci_type == 'repoman'
		packages = packages
	elsif num_of_packages == 'untested' and ci_type == 'build'
		packages = []
		Package.each do |package|
			next if package.build.count > 0
			next if "#{package[:category]}/#{package[:name]}" == 'virtual/rubygems'
			next if "#{package[:category]}/#{package[:name]}" == 'dev-ruby/rake'
			next if "#{package[:category]}/#{package[:name]}" == 'dev-ruby/rspec'
			next if "#{package[:category]}/#{package[:name]}" == 'dev-ruby/rspec-core'
			next if "#{package[:category]}/#{package[:name]}" == 'dev-ruby/rdoc'

			packages << package[:identifier]
			Package.where(Sequel.like(
				:dependencies,
				"#{package[:category]}/#{package[:name]} %",
				"% #{package[:category]}/#{package[:name]} %",
				"% #{package[:category]}/#{package[:name]}"
			)).each do |rdep|
				packages << rdep[:identifier]
			end
		end
	elsif num_of_packages.is_a?(Integer)
		packages = packages.sample(num_of_packages)
	else
		puts 'ERROR: Invalid value for NUM_OF_PACKAGES'
		puts ci_type
		puts num_of_packages
		exit
	end

	packages_with_targets = []
	packages.uniq.each do |package|
		package = Package.where(identifier: package).first

		target = 'unknown'
		target = package[:r19_target] unless package[:r19_target] == 'nil'
		target = package[:r20_target] unless package[:r20_target] == 'nil'
		target = package[:r21_target] unless package[:r21_target] == 'nil'
		target = package[:r22_target] unless package[:r22_target] == 'nil'

		next_target = 'unknown'
		next_target = 'ruby20' if target == 'ruby19'
		next_target = 'ruby21' if target == 'ruby20'
		next_target = 'ruby22' if target == 'ruby21'

		packages_with_targets << "#{package[:identifier]} #{target} #{next_target}"
	end

	packages_with_targets
end

def update_build
	Dir.glob('ci-logs/*/*/builds/*') do |build|
		begin
			build_array = build.split('/')
			sha1 = build_array[1]
			timestamp = build_array[4]
			target = build_array[2].sub('_target', '')

			result = File.read("#{build}/result")
			emerge_info = File.read("#{build}/emerge-info") if File.exist?("#{build}/emerge-info")
			emerge_pqv = File.read("#{build}/emerge-pqv") if File.exist?("#{build}/emerge-pqv")
			build_log = File.read("#{build}/build.log") if File.exist?("#{build}/build.log")
			gem_list = File.read("#{build}/gem-list") if File.exist?("#{build}/gem-list")

			package = Package.where(sha1: sha1).first
			unless package.nil?
				package.add_build(
					Build.find_or_create(
						timestamp: timestamp,
						target: target,
						result: result,
						emerge_info: emerge_info,
						emerge_pqv: emerge_pqv,
						build_log: build_log,
						gem_list: gem_list
					)
				)
			end
		rescue => e
			puts "ERROR: #{e}"
			next
		end
	end
end

def update_repoman
	Dir.glob('ci-logs/*/*/repomans/*') do |repoman|
		begin
			repoman_array = repoman.split('/')
			sha1 = repoman_array[1]
			timestamp = repoman_array[4]
			target = repoman_array[2].sub('_target', '')

			log = File.read("#{repoman}/repoman_log")

			result = 'unknown'
			if log.include?('If everyone were like you, I\'d be out of business!')
				result = 'passed'
			elsif log.include?('You\'re only giving me a partial QA payment?')
				result = 'partial'
			elsif log.include?('Make your QA payment on time and you\'ll never see the likes of me.')
				result = 'failed'
			end

			Package.where(sha1: sha1).first.add_repoman(
				Repoman.find_or_create(
					timestamp: timestamp,
					target: target,
					result: result,
					log: log
				)
			)
		rescue => e
			puts "ERROR: #{e}"
			next
		end
	end
end

def clear_build
	Build.map(&:delete)
end

def clear_repoman
	Repoman.map(&:delete)
end