summaryrefslogtreecommitdiffstats
path: root/autobuild/results.php
blob: 9172a57f1a71ddb1094b19e6c4938882f7689836 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<html>
<head>
<?php

function parse_package($rpm) {
	if (preg_match("/(.*)-([^-]*-[^-]*mga)[1-9].src.rpm/", $rpm, $matches)) {
	    return Array('package' => $matches[1], 'version' => $matches[2]);
	} else {
	    return false;
	}
}

$runs = Array();
$handle = opendir('cauldron/x86_64/core/');
while (false !== ($entry = readdir($handle))) {
	if (preg_match("/^....-..-..$/", $entry, $matches)) {
		array_push($runs, $matches[0]);
	}
}
closedir($handle);
sort($runs);

$latest = readlink("cauldron/x86_64/core/latest");
$run = $_GET['run'];
if (!$run) {
	$run = $latest;
}

foreach ($runs as $r) {
	if ($r==$run) {
		break;
	}
	$prev = $r;
}

$packages = Array();
if ($handle = opendir('/distrib/bootstrap/distrib/cauldron/SRPMS/core/release/')) {
	while (false !== ($entry = readdir($handle))) {
		if ($parsed = parse_package($entry)) {
			$packages[$parsed['package']] = $entry;
		}
	}
	closedir($handle);
}

$prev_failure = Array();
if ($prev) {
	$base_dir = "cauldron/x86_64/core/$prev";
	$status_name = "$base_dir/status.core.log";
	$status_file = fopen($status_name, "r");
	while (!feof($status_file)) {
		$line = fgets($status_file);
		if (preg_match("/^(.*): (.*)$/", $line, $matches)) {
			$rpm = parse_package($matches[1]);
			$status = $matches[2];
			if ($status != "ok" && $status != "unknown" && $status != "not_on_this_arch") {
				$prev_failure[$rpm['package']] = 1;
			}
		}
	}
	fclose($status_file);
}

$success = Array();
$failure = Array();
$fixed = Array();
$removed = Array();
$broken = Array();

$base_dir = "cauldron/x86_64/core/$run";


$status_name = "$base_dir/status.core.log";
if (!file_exists($status_name)) {
	echo "Invalid run";
	exit;
}

$start_time = 0;
if (file_exists("$base_dir/VERSION")) {
#Mageia 5 Devel-i586-Download 20140311 15:50
#Mageia 5 Devel-x86_64-Download 20140311 15:50
	$version = file_get_contents("$base_dir/VERSION");
	preg_match('/ (\d{8} \d{2}:\d{2})$/', $version, $matches);
	$start_time = strtotime($matches[1]);
}
$status_file = fopen($status_name, "r");
while (!feof($status_file)) {
	$line = fgets($status_file);
	if (preg_match("/^(.*): (.*)$/", $line, $matches)) {
		$rpm = $matches[1];
		$status = $matches[2];
		if ($start_time == 0) {
			$build_stat = stat("$base_dir/$rpm");
			if ($build_stat['mtime']) {
				$start_time = $build_stat['mtime'];
			}
		}
		if ($status == "ok") {
			array_push($success, $rpm);
		} elseif ($status != "unknown" && $status != "not_on_this_arch"){
			$failure[$rpm] = $status;
			$parsed = parse_package($rpm);
			$package = $parsed['package'];
			if(!$prev_failure[$package]) {
				$broken[$rpm] = 1;
			}
			if(!$packages[$package]) {
				$removed[$rpm] = 1;
			} else {
				$build_stat = stat("$base_dir/$rpm");
				$pkg_stat = stat('/distrib/bootstrap/distrib/cauldron/SRPMS/core/release/'.$packages[$package]);
				if (file_exists("$base_dir/$rpm") && $pkg_stat['mtime'] > $start_time) {
					$fixed[$rpm] = 1;
				}
			}
		}
	}
}
fclose($status_file);

sort($success);
ksort($failure);

$nb_failed = count($failure);
$nb_success = count($success);
$nb_fixed = count($fixed);
$nb_removed = count($removed);
$nb_tried = $nb_failed + $nb_success;
$succes_percent = round($nb_success*1000/$nb_tried)/10;
$estimated_percent = round(($nb_success+$nb_fixed)*1000/($nb_tried-$nb_removed))/10;

echo "<title>$succes_percent% Success</title>\n";
?>
<style>
.collapse-arrow:before {
    content: '▼';
}
.collapse-arrow {
    text-decoration: none;
}
 
.expand-arrow:before {
    content: '►';
}
.expand-arrow {
    text-decoration: none;
}
</style>
<script language='javascript'>
function toggle(titleid, contentid){
    document.getElementById(titleid).classList.toggle('expand-arrow');
    document.getElementById(titleid).classList.toggle('collapse-arrow');
    var e = document.getElementById(contentid);
    if(e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}
</script>
<meta charset="utf-8">
</head>
<body>
<div style='position:absolute;right:0;top:0;'>
<?php
echo "<form><select name='run' onChange='document.location.href=\"".$_SERVER["PHP_SELF"]."?run=\"+this.form.run.value'>";
foreach ($runs as $r) {
	$in_progress = ($r > $latest) ? ' (in progress)' : '';
	$selected = ($r == $run) ? ' selected' : '';
	echo "<option value='$r'$selected>$r$in_progress</option>";
}
echo "</select></form></div>\n";
echo "<h1>$succes_percent% Success</h1>\n";
echo "$nb_fixed packages have been fixed since this run and $nb_removed have been removed.<br/> If no new package was broken, success rate next time should be $estimated_percent%.<br/>\n";
echo "<div style='float:left;'><h1>Failed builds ($nb_failed/$nb_tried)</h1><ul style='list-style:none;'>";

foreach ($failure as $rpm => $error) {
	$parsed = parse_package($rpm);
	$history_link = '<a href="history.php?package='.$parsed['package'].'">[h]</a>';
	$status_html = "";
	if ($fixed[$rpm]) {
		$status_html = " <img src='icons/state-fixed.png' title='Fixed!' />";
	} elseif ($removed[$rpm]) {
		$status_html = " <img src='icons/state-removed.png' title='Removed' />";
	} elseif ($broken[$rpm]) {
		$status_html = " <img src='icons/state-new.png' title='New!' />";
	}
	$error_html = $error;
	if (file_exists("icons/error-$error.png")) {
		$error_html = "<img src='icons/error-$error.png' title='$error'/>";
	}
	if (file_exists("$base_dir/$rpm/")) {
		echo "<li>$error_html <a href='$base_dir/$rpm/'>$rpm</a> $status_html $history_link</li>\n";
	} else {
		echo "<li>$error_html $rpm $status_html $history_link</li>\n";
	}
}
?>
</ul></div>
<div style='float:right; width:50%'><h1><a class='expand-arrow' id='success-title' href='javascript:toggle("success-title","success-list");'>
<?php echo "Successful builds ($nb_success/$nb_tried)" ?>
</a></h1>
<div id="success-list" style="display:none"><ul>
<?php
foreach ($success as $rpm) {
	$parsed = parse_package($rpm);
	$history_link = '<a href="history.php?package='.$parsed['package'].'">[h]</a>';
	if (file_exists("$base_dir/$rpm/")) {
		echo "<li><a href='$base_dir/$rpm/'>$rpm</a> $history_link</li>\n";
	} else {
		echo "<li>$rpm $history_link</li>\n";
	}
}

?>
</ul></div></div>
</body>
</html>