add log diff to compare logs to previous builds
This commit is contained in:
parent
0bf03727f0
commit
998665aa0f
2
deps.nix
2
deps.nix
|
@ -20,6 +20,8 @@ with pkgs;
|
||||||
perlPackages.DBDSQLite
|
perlPackages.DBDSQLite
|
||||||
perlPackages.EmailSender
|
perlPackages.EmailSender
|
||||||
perlPackages.TextTable
|
perlPackages.TextTable
|
||||||
|
perlPackages.TextDiff
|
||||||
|
perlPackages.FileSlurp
|
||||||
perlPackages.NetTwitterLite
|
perlPackages.NetTwitterLite
|
||||||
perlPackages.PadWalker
|
perlPackages.PadWalker
|
||||||
perlPackages.DataDump
|
perlPackages.DataDump
|
||||||
|
|
|
@ -10,6 +10,8 @@ use Hydra::Controller::Project;
|
||||||
use JSON::Any;
|
use JSON::Any;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use Digest::SHA qw(sha256_hex);
|
use Digest::SHA qw(sha256_hex);
|
||||||
|
use Text::Diff;
|
||||||
|
use File::Slurp;
|
||||||
|
|
||||||
# !!! Rewrite this to use View::JSON.
|
# !!! Rewrite this to use View::JSON.
|
||||||
|
|
||||||
|
@ -213,7 +215,7 @@ sub scmdiff : Chained('api') PathPart('scmdiff') Args(0) {
|
||||||
if($type eq "hg") {
|
if($type eq "hg") {
|
||||||
my $clonePath = scmPath . "/" . sha256_hex($uri);
|
my $clonePath = scmPath . "/" . sha256_hex($uri);
|
||||||
die if ! -d $clonePath;
|
die if ! -d $clonePath;
|
||||||
$diff .= `(cd $clonePath ; hg log -r $rev1:$rev2)`;
|
$diff .= `(cd $clonePath ; hg log -r $rev1 -r $rev2 -b $branch)`;
|
||||||
$diff .= `(cd $clonePath ; hg diff -r $rev1:$rev2)`;
|
$diff .= `(cd $clonePath ; hg diff -r $rev1:$rev2)`;
|
||||||
} elsif ($type eq "git") {
|
} elsif ($type eq "git") {
|
||||||
my $clonePath = scmPath . "/" . sha256_hex($uri.$branch);
|
my $clonePath = scmPath . "/" . sha256_hex($uri.$branch);
|
||||||
|
@ -226,4 +228,37 @@ sub scmdiff : Chained('api') PathPart('scmdiff') Args(0) {
|
||||||
$c->forward('Hydra::View::Plain');
|
$c->forward('Hydra::View::Plain');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub readNormalizedLog {
|
||||||
|
my ($file) = @_;
|
||||||
|
my $res = read_file($file);
|
||||||
|
|
||||||
|
$res =~ s/\/nix\/store\/[a-z0-9]*-/\/nix\/store\/...-/g;
|
||||||
|
$res =~ s/nix-build-[a-z0-9]*-/nix-build-...-/g;
|
||||||
|
$res =~ s/[0-9]{2}:[0-9]{2}:[0-9]{2}/00:00:00/g;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub logdiff : Chained('api') PathPart('logdiff') Args(2) {
|
||||||
|
my ($self, $c, $buildid1, $buildid2) = @_;
|
||||||
|
|
||||||
|
my $diff = "";
|
||||||
|
|
||||||
|
my $build1 = getBuild($c, $buildid1);
|
||||||
|
notFound($c, "Build with ID $buildid1 doesn't exist.")
|
||||||
|
if !defined $build1;
|
||||||
|
my $build2 = getBuild($c, $buildid2);
|
||||||
|
notFound($c, "Build with ID $buildid2 doesn't exist.")
|
||||||
|
if !defined $build2;
|
||||||
|
|
||||||
|
if (-f $build1->resultInfo->logfile && -f $build2->resultInfo->logfile) {
|
||||||
|
my $logtext1 = readNormalizedLog($build1->resultInfo->logfile);
|
||||||
|
my $logtext2 = readNormalizedLog($build2->resultInfo->logfile);
|
||||||
|
$diff = diff \$logtext1, \$logtext2;
|
||||||
|
} else {
|
||||||
|
$c->response->status(404);
|
||||||
|
}
|
||||||
|
$c->stash->{'plain'} = { data => (scalar $diff) || " " };
|
||||||
|
$c->forward('Hydra::View::Plain');
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -151,6 +151,7 @@ sub robots_txt : Path('robots.txt') {
|
||||||
, uri_for('Root', 'status', [])
|
, uri_for('Root', 'status', [])
|
||||||
, uri_for('Root', 'all', [])
|
, uri_for('Root', 'all', [])
|
||||||
, uri_for('API', 'scmdiff', [])
|
, uri_for('API', 'scmdiff', [])
|
||||||
|
, uri_for('API', 'logdiff', [],"*", "*")
|
||||||
, uri_for('Project', 'all', ["*"])
|
, uri_for('Project', 'all', ["*"])
|
||||||
, channelUris('Root', ["*"])
|
, channelUris('Root', ["*"])
|
||||||
, channelUris('Project', ["*", "*"])
|
, channelUris('Project', ["*", "*"])
|
||||||
|
|
|
@ -184,15 +184,19 @@
|
||||||
[% INCLUDE renderBuildSteps type="Failed" %]
|
[% INCLUDE renderBuildSteps type="Failed" %]
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|
||||||
[% IF build.resultInfo.buildstatus != 0 && prevSuccessfulBuild %]
|
|
||||||
<h2>Changes</h2>
|
<h2>Changes</h2>
|
||||||
Changes compared to last successful build:<br/>
|
|
||||||
<br/>
|
<br/>
|
||||||
<table>
|
<table>
|
||||||
<thead>
|
<thead>
|
||||||
<th>Last successful build <tt>[% INCLUDE renderDateTime timestamp = prevSuccessfulBuild.timestamp %]</tt></th>
|
<th>Last successful build <tt>[% INCLUDE renderDateTime timestamp = prevSuccessfulBuild.timestamp %]</tt></th>
|
||||||
[% IF prevSuccessfulBuild && firstBrokenBuild && firstBrokenBuild.id != build.id %]<th>First broken build <tt>[% INCLUDE renderDateTime timestamp = firstBrokenBuild.timestamp %]</tt></th>[% END %]
|
[% IF prevSuccessfulBuild && firstBrokenBuild && firstBrokenBuild.id != build.id %]
|
||||||
<th>This build <tt>[% INCLUDE renderDateTime timestamp = build.timestamp %]</tt></th>
|
<th>First broken build <tt>[% INCLUDE renderDateTime timestamp = firstBrokenBuild.timestamp %]</tt><br/>
|
||||||
|
<tt>[ <a href="[% c.uri_for(c.controller('API').action_for('logdiff') prevSuccessfulBuild.id firstBrokenBuild.id ) %]">log diff</a> ]</tt>
|
||||||
|
</th>
|
||||||
|
[% END %]
|
||||||
|
<th>This build <tt>[% INCLUDE renderDateTime timestamp = build.timestamp %]</tt> <br/>
|
||||||
|
<tt>[ <a href="[% c.uri_for(c.controller('API').action_for('logdiff') prevSuccessfulBuild.id build.id) %]">log diff</a> ]</tt>
|
||||||
|
</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td valign="center">[% INCLUDE renderBuildStatusIcon build=prevSuccessfulBuild size=32 %] [% INCLUDE renderFullBuildLink build=prevSuccessfulBuild %]</td>
|
<td valign="center">[% INCLUDE renderBuildStatusIcon build=prevSuccessfulBuild size=32 %] [% INCLUDE renderFullBuildLink build=prevSuccessfulBuild %]</td>
|
||||||
|
@ -205,7 +209,6 @@
|
||||||
<td>[% INCLUDE renderInputDiff build1=prevSuccessfulBuild , build2=build %]</td>
|
<td>[% INCLUDE renderInputDiff build1=prevSuccessfulBuild , build2=build %]</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
[% END %]
|
|
||||||
|
|
||||||
[% IF build.resultInfo.errormsg && build.resultInfo.buildstatus != 5 %]
|
[% IF build.resultInfo.errormsg && build.resultInfo.buildstatus != 5 %]
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue