Skip to content
Permalink
Browse files

Added CI rendering (part 1)

  • Loading branch information...
derickr committed Mar 21, 2019
1 parent 8de8c5a commit 723d76cec252770f636cadfcd603afd95fe640b7
Showing with 247 additions and 0 deletions.
  1. +199 −0 html/ci-items.php
  2. +27 −0 html/ci.php
  3. +21 −0 html/core.css
@@ -0,0 +1,199 @@
<?php
class ci
{
static function showRunInfo( string $runId )
{
$m = new \MongoDB\Driver\Manager( "mongodb+srv://ci-reader:{$_ENV['CIREADPASSWORD']}@xdebugci-qftmo.mongodb.net/test?retryWrites=true" );
$query = new \MongoDB\Driver\Query( [ '_id' => $runId ] );
$result = $m->executeQuery( 'ci.run', $query );
$result = iterator_to_array( $result );
if ( count( $result ) != 1 )
{
echo <<<ENDERR
<h2 class='error'>There is no CI run with ID '$runId'</h2>
ENDERR;
return;
}
$r = $result[0];
/* Header */
$time = (new \DateTime( "@{$r->ts}" ))->format( 'Y-m-d<\b\r/>H:i:s' );
echo <<<ENDHEAD
<h2>CI Run '$runId'</h2>
<table class='ci'>
<tr class='version'>
<th>PHP {$r->cfg->config}</th><th>Xdebug: <a href='https://github.com/xdebug/xdebug/commit/{$r->ref}'>{$r->abbrev}</a></th><th><div class='time'>{$time}</div></th>
</tr>
</table>
ENDHEAD;
if ( $r->buildSuccess == false )
{
$log = htmlspecialchars( $r->buildLog );
echo <<<ENDFAIL
<h2 class='bf'>Build Failure</h2>
<pre class='log'>
{$log}
</pre>
ENDFAIL;
return;
}
echo <<<ENDSUCCESS
<h2 class='success'>Build Success</h2>
<table class='ci'>
<tr class='version'>
<th>Tests</th><th>Errors</th><th>Failures</th><th>Skipped</th><th>Time</th>
</tr>
<tr>
<td>{$r->stats->tests}</td><td>{$r->stats->errors}</td><td>{$r->stats->failures}</td><td>{$r->stats->skip}</td><td><div class='time'>{$r->stats->time} s</div></th>
</tr>
</table>
ENDSUCCESS;
if ( $r->stats->errors == 0 && $r->stats->failures == 0 )
{
echo <<<TESTSUCCESS
<h2 class='success'>Test Success</h2>
TESTSUCCESS;
return;
}
echo <<<TESTFAILURE
<h2 class='err'>Test Failure</h2>
TESTFAILURE;
foreach( $r->failures as $f )
{
$log = htmlspecialchars( $f->reason );
echo <<<ENDFAILURE
<table class='ci'>
<tr class='version'>
<th>File: <a href='https://github.com/xdebug/xdebug/blob/{$r->ref}/tests/{$f->file}.phpt'>tests/{$f->file}.phpt</a></th>
</tr>
<tr>
<td>{$f->desc}</td>
</tr>
<tr>
<td><pre class='log'>{$log}</pre></td>
</tr>
</table>
ENDFAILURE;
}
}
static function showMatrix()
{
$m = new \MongoDB\Driver\Manager( "mongodb+srv://ci-reader:{$_ENV['CIREADPASSWORD']}@xdebugci-qftmo.mongodb.net/test?retryWrites=true" );
$query = new \MongoDB\Driver\Command( [
'aggregate' => 'run',
'pipeline' => [
[ '$group' => [ '_id' => '$run', 'docs' => [ '$push' => '$$ROOT' ] ] ],
[ '$sort' => [ '_id' => -1 ] ],
[ '$limit' => 10 ],
],
'cursor' => (object) [],
] );
$phpVersions = [];
$abbrevs = [];
$runs = [];
foreach ( $m->executeCommand( 'ci', $query ) as $result )
{
$runs[$result->_id] = $result->docs;
}
/* Figure out which versions we have */
foreach ( $runs as $run => $info )
{
foreach ( $info as $key => $version )
{
$phpVersions[ $version->cfg->config ] = true;
$latestAbbrev = trim( $version->abbrev );
$abbrevs[ $latestAbbrev ] = $version;
$matrix[ trim( $latestAbbrev ) ][ trim( $version->cfg->config ) ] = $version;
}
}
$phpVersions = array_keys( $phpVersions );
uksort( $abbrevs, function( $aIndex, $bIndex ) use ( $abbrevs ) {
return $abbrevs[$aIndex]->ts <=> $abbrevs[$bIndex]->ts;
} );
$abbrevs = array_reverse( $abbrevs );
uksort( $phpVersions, function($aIndex, $bIndex) use ( $phpVersions ) {
$a = $phpVersions[ $aIndex ];
$b = $phpVersions[ $bIndex ];
preg_match( '@([^-]+)(-(32bit|zts))?$@', $a, $aMatch );
preg_match( '@([^-]+)(-(32bit|zts))?$@', $b, $bMatch );
$c = version_compare( $aMatch[1], $bMatch[1] );
if ( $c != 0 )
{
return -$c;
}
return - strcmp( $aMatch[3], $bMatch[3] );
} );
$phpVersions = array_values( $phpVersions );
echo "<table class='ci'>\n\t<tr class='version'><th></th>\n";
foreach ( $abbrevs as $abbrev => $version )
{
$time = (new \DateTime( "@{$version->ts}" ))->format( 'Y-m-d<\b\r/>H:i:s' );
if ( preg_match('@(.*)-g([0-9a-f]+)$@', $abbrev, $m) )
{
echo "\t\t<th><div><a href='https://github.com/xdebug/xdebug/commit/{$m[2]}'>{$m[1]}</a><br/><div class='time'>{$time}</div></th>\n";
continue;
}
echo "\t\t<th><div><a href='https://github.com/xdebug/xdebug/commit/{$version->ref}'>{$abbrev}</a><br/><div class='time'>{$time}</div></th>\n";
}
echo "\t</tr>\n";
foreach ( $phpVersions as $version )
{
echo "\t\t<tr><th>{$version}</div></th>\n";
foreach ( $abbrevs as $abbrev => $ref )
{
if ( !isset( $matrix[$abbrev][$version] ) )
{
echo "<td class='missing'></td>\n";
continue;
}
$v = $matrix[$abbrev][$version];
if ( $v->buildSuccess != true )
{
echo "<td class='bf'><a href='/ci.php?r={$v->_id}'>✖</a></td>\n";
continue;
}
if ( $v->stats->errors != 0 || $v->stats->failures != 0 )
{
echo "<td class='err'><a href='/ci.php?r={$v->_id}'>✖</a></td>\n";
continue;
}
echo "<td class='success'><a href='/ci.php?r={$v->_id}'>✔</a></td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
}
}
@@ -0,0 +1,27 @@
<?php $title = "Xdebug - Debugger and Profiler Tool for PHP"; include "include/header.php"; ?>
<tr>
<td>&nbsp;</td>
<td><span class="serif">

<!-- MAIN FEATURE START -->

<span class="sans"><a href='/ci.php'>XDEBUG CI</a></span><br />
<br/><br/>
<?php
include 'ci-items.php';
if ( isset( $_GET['r'] ) )
{
ci::showRunInfo( (string) $_GET['r'] );
}
else
{
ci::showMatrix();
}
?>
<!-- MAIN FEATURE END -->

</td>
<td>&nbsp;</td>
</tr>
<?php include "include/footer.php"; ?>
@@ -14,6 +14,27 @@ body { font-family: sans-serif; }
th.ctr { text-align: center; padding-left: 10px; padding-right: 10px; vertical-align: top; }
td.ctr { text-align: center; padding-left: 10px; padding-right: 10px; vertical-align: top; }

table.ci { width: 100%; border-collapse: collapse; }
table.ci tr.version th { white-space: nowrap; padding: 0; text-align: center; }
table.ci tr.version th div.time { font-size: 66%; line-height: 1em; font-weight: normal; }
table.ci tr th { border: 1px solid black; padding-left: 0.5em;}
table.ci tr td { text-align: center; border: 1px solid black; font-size: 1.5em; padding: 0.25em; }
table.ci tr td.bf { color: #c1e; background-color: #eee; }
table.ci tr td.bf a { color: #c1e; background-color: #eee; text-decoration: none; }
table.ci tr td.bf a:hover { background-color: #ddd; }
table.ci tr td.err { color: #e44; background-color: #eee; }
table.ci tr td.err a { color: #e44; background-color: #eee; text-decoration: none; }
table.ci tr td.err a:hover { background-color: #ddd; }
table.ci tr td.missing { color: #ccc; }
table.ci tr td.success { color: #0b0; background-color: #eee; }
table.ci tr td.success a { color: #0b0; background-color: #eee; text-decoration: none; }
table.ci tr td.success a:hover { background-color: #ddd; }
table.ci tr td pre.log { font-size: 0.66em; text-align: left; }
h2.bf { color: #c1e; }
h2.err { color: #e44; }
h2.success { color: #0b0; }
pre.log { white-space: pre-wrap; }

#flickr { margin: 20px; }

tt { font-family: monospace; background-color: #eaffeb; }

0 comments on commit 723d76c

Please sign in to comment.
You can’t perform that action at this time.