-
Notifications
You must be signed in to change notification settings - Fork 8
/
builds.php
326 lines (285 loc) · 7.29 KB
/
builds.php
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/**
* Nightly builds page is built dynamically by reading the contents
* of the /builds directory
*/
/**
* Parsing directories in sorted order using provided callback function
*/
class SortingIterator extends ArrayIterator {
public function __construct( Traversable $iterator, $callback ) {
parent::__construct( iterator_to_array( $iterator ) );
$this->uasort( $callback );
}
}
/**
* Retrieves the list of builds from the specified path.
* List will be sorted by branch name ASC and time DESC, (using the zip file's
* timestamp as reference).
* @param string $p_path
* @param array|null $p_builds
* @param array|null $p_logfile
* @return bool false in case of errors
*/
function get_builds_list(string $p_path, ?array &$p_builds, ?array &$p_logfile ): bool
{
# Error handling in case the path does not exist
if( !is_dir( $p_path ) ) {
print_error( "Path '$p_path' not found" );
return false;
}
# Loop over parent directories (channels)
$t_iter_builds = new SortingIterator(
new FileSystemIterator( $p_path ),
'strcmp'
);
$p_path = '/' . basename( $p_path ) . '/';
$p_builds = array();
/** @var SplFileInfo $t_file */
foreach( $t_iter_builds as $t_file ) {
if( $t_file->isDir() ) {
continue;
}
$t_file_url = $p_path . $t_file->getFilename();
# Link to log file if present
if( $t_file->getExtension() == 'log' ) {
$p_logfile = array(
'file' => $t_file_url,
'time' => $t_file->getMTime()
);
} else {
# Break down filename into components
$t_result = preg_match(
'/^mantisbt-(.*-?.*)-(master.*?)-(.*)\.(.*)\.?(digests|asc)?$/U',
$t_file->getFileName(),
$t_match
);
if( $t_result != 1 ) {
continue;
}
$t_sha = $t_match[3];
$t_ext = $t_match[4];
# Build details
$p_builds[$t_sha]['branch'] = $t_match[2];
$p_builds[$t_sha]['version'] = $t_match[1];
# Digest and zip/tarball file names
if( isset( $t_match[5] ) ) {
$p_builds[$t_sha][$t_ext][$t_match[5]] = $t_file_url;
} else {
$t_time = $t_file->getMTime();
$p_builds[$t_sha][$t_ext]['file'] = $t_file_url;
$p_builds[$t_sha][$t_ext]['time'] = $t_time;
# Build reference time (for sorting) is the most recent file's timestamp
$p_builds[$t_sha]['time'] = max(
$p_builds[$t_sha]['time'] ?? 0,
$t_time
);
}
}
}
if( !$p_builds ) {
print_error( "No builds found.");
return false;
}
# Sort list by version DESC with master first, timestamp DESC
uasort( $p_builds,
function( $a, $b ) {
$t_result = -version_compare( $a['version'], $b['version'] );
if ($t_result == 0) {
return -( $a['time'] <=> $b['time'] );
}
return $t_result;
}
);
return true;
}
/**
* Prints timestamp in YYYY-MM-DD HH:mm:ss format
* @param int $p_time
* @return string
*/
function print_timestamp( int $p_time ): string
{
return date( 'Y-m-d H:i:s', $p_time );
}
/**
* Return download links and timestamp for the file
* @param string $p_type
* @param array|null $p_file
* @return string formatted markup with
*/
function print_file_details( string $p_type, ?array $p_file ): string
{
if( is_null( $p_file ) || !isset( $p_file['file'] ) ) {
return '
<td class="table-cell center">Unavailable</td>';
} else {
$t_digest = [];
if( isset( $p_file['asc'] ) ) {
$t_digest[] = '<a href="' . $p_file['asc']
. '" title="ASCII-armored signature file">signature</a>';
}
if( isset( $p_file['digests'] ) ) {
$t_digest[] = '<a href="' . $p_file['digests']
. '" title="Checksums">digests</a>';
}
if( $t_digest ) {
$t_digest = implode( ', ', $t_digest );
} else {
$t_digest = 'no signature or digests';
}
/** @noinspection HtmlUnknownTarget */
return sprintf( '
<td class="table-cell center">
<a href="%s"><img src="images/zip.gif" alt="%s"> Download</a>
(%s)
<br />
%s
</td>',
$p_file['file'], $p_type,
$t_digest,
print_timestamp( $p_file['time'] )
);
}
}
/**
* Prints the Travis-CI status icon for the given branch
* @param string $p_branch Branch name
* @return string
*/
function print_travis_status( string $p_branch ): string
{
return sprintf( '
<a href="https://app.travis-ci.com/mantisbt/mantisbt/branches">
<img src="https://app.travis-ci.com/mantisbt/mantisbt.svg?branch=%s"
alt="Build status"
/>
</a>',
$p_branch
);
}
/**
* Prints the table with the builds
* @param array $p_builds
*/
function print_builds_list( array $p_builds ) {
global $g_bugs_url;
# printf formats
$t_fmt_sha_link = '
<a href="' . $g_bugs_url . 'plugin.php?page=Source/search&revision=%1$s">%1$s</a>';
$t_fmt_branch = '
<td rowspan="%d" class="table-cell">
%s
<br />%s
</td>';
$t_fmt_build_row = '
<tr class="table-row">%s
<td class="table-cell center">%s
</td>
%s
%s
</tr>' . "\n";
# Count number of builds available for each branch
$t_build_count = [];
foreach( $p_builds as $t_build ) {
$t_branch = $t_build['branch'];
if( isset( $t_build_count[$t_branch] ) ) {
$t_build_count[$t_branch]++;
} else {
$t_build_count[$t_branch] = 1;
}
}
# Table header
echo ' <!-- Downloads table -->
<table class="table" style="padding: 2px;">
<thead class="table-header">
<tr class="table-row">
<th class="table-cell" style="text-align: left;">Branch (Release)</th>
<th class="table-cell">Commit</th>
<th class="table-cell">Tarballs</th>
<th class="table-cell">Zipballs</th>
</tr>
</thead>
<tbody>';
# Table body
$t_branch = null;
foreach( $p_builds as $t_sha => $t_build ) {
if( $t_branch != $t_build['branch'] ) {
$t_branch = $t_build['branch'];
$t_current = sprintf(
$t_fmt_branch,
$t_build_count[$t_branch],
sprintf(
'%1$s<br />(%2$s)',
$t_build['branch'],
$t_build['version']
),
print_travis_status( $t_branch )
);
} else {
$t_current = '';
}
printf(
$t_fmt_build_row,
$t_current,
sprintf( $t_fmt_sha_link, $t_sha),
print_file_details( 'tarball', $t_build['tar.gz'] ?? null),
print_file_details( 'zipball', $t_build['zip'] ?? null)
);
}
echo '
</tbody>
</table>
<br />';
}
/**
* Main body
*/
# Page header
$t_sub_title = "Nightly Builds";
include( "top.php" );
# Root of builds - try in current dir and one level above if not found
$t_dir = 'builds';
$t_path_root = rtrim( $_SERVER['DOCUMENT_ROOT'], DIRECTORY_SEPARATOR ) . DIRECTORY_SEPARATOR;
$t_path = realpath( $t_path_root . $t_dir );
if( false === $t_path ) {
$t_path = realpath( dirname( $t_path_root ) . DIRECTORY_SEPARATOR . $t_dir );
}
if( false === $t_path ) {
$t_path = $t_dir;
}
?>
<div class="row show-grid clear-both">
<div class="col-sm-7 col-md-8">
<h1>Nightly Builds Downloads</h1>
</div>
</div>
<br>
<?php
if( get_builds_list( $t_path, $t_builds, $t_logfile ) ) {
print_builds_list( $t_builds );
?>
<div>
<p>
<i class="icon-key"></i>
<i class="icon-hashtag"></i>
Use these
<a href="https://github.com/mantisbt/mantisbt/blob/master/KEYS.md">PGP keys</a>
to verify the downloaded files' integrity, using the corresponding signature.
</p>
<?php
if( $t_logfile ) {
?>
<p>
View the Nightly Builds script's
<a href="<?php echo $t_logfile['file']; ?>">Log File</a>
(<?php echo print_timestamp( $t_logfile['time'] ); ?>).
</p>
<?php
}
?>
<p>All times on this page are <?php echo date('T (\U\TCP)') ?>.</p>
</div>
<?php
}
include( "bot.php" );