X-Git-Url: https://git.exim.org/buildfarm-server.git/blobdiff_plain/196ae12217eca5d957036b6e9e7dbd4f46356920..0118a8258eb871570d8039faa1e042c6a869baf9:/cgi-bin/show_log.pl diff --git a/cgi-bin/show_log.pl b/cgi-bin/show_log.pl index 58b6b0b..ab3d3cd 100755 --- a/cgi-bin/show_log.pl +++ b/cgi-bin/show_log.pl @@ -1,16 +1,26 @@ #!/usr/bin/perl +=comment + +Copyright (c) 2003-2010, Andrew Dunstan + +See accompanying License file for license details + +=cut + use strict; use DBI; use Template; use CGI; -use URI::Escape; -use vars qw($dbhost $dbname $dbuser $dbpass $dbport @log_file_names); +use vars qw($dbhost $dbname $dbuser $dbpass $dbport + $template_dir @log_file_names $local_git_clone); +use FindBin qw($RealBin); +require "$RealBin/../BuildFarmWeb.pl"; -require "$ENV{BFConfDir}/BuildFarmWeb.pl"; -#require "BuildFarmWeb.pl"; +my $template_opts = { INCLUDE_PATH => $template_dir, EVAL_PERL => 1}; +my $template = new Template($template_opts); die "no dbname" unless $dbname; die "no dbuser" unless $dbuser; @@ -22,357 +32,212 @@ $dsn .= ";port=$dbport" if $dbport; my $query = new CGI; my $system = $query->param('nm'); $system =~ s/[^a-zA-Z0-9_ -]//g; -my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ -]//g; +my $logdate = $query->param('dt'); $logdate =~ s/[^a-zA-Z0-9_ :-]//g; my $log = ""; my $conf = ""; -my ($stage,$changed_this_run,$changed_since_success,$sysinfo,$branch); +my ($stage,$changed_this_run,$changed_since_success,$sysinfo,$branch,$scmurl); my $scm; +my ($git_head_ref, $last_build_git_ref, $last_success_git_ref); +my ($stage_times, $run_time); use vars qw($info_row); if ($system && $logdate) { - my $db = DBI->connect($dsn,$dbuser,$dbpass); + my $db = DBI->connect($dsn,$dbuser,$dbpass,{pg_expand_array => 0}); die $DBI::errstr unless $db; - my $statement = <prepare($statement); $sth->execute($system,$logdate); my $row=$sth->fetchrow_arrayref; + $branch = $row->[5]; + $git_head_ref = $row->[9]; + $sth->finish; + my $last_build_row; + if ($git_head_ref) + { + $last_build_row = + $db->selectrow_hashref($last_build_statement,undef, + $system, $branch,$system,$branch,$logdate); + $last_build_git_ref = $last_build_row->{git_head_ref} + if $last_build_row; + + } + my $last_success_row; + if (ref $last_build_row && $last_build_row->{stage} ne 'OK') + { + $last_success_row = + $db->selectrow_hashref($last_success_statement,undef, + $system,$branch,$system,$branch,$logdate); + $last_success_git_ref = $last_success_row->{git_head_ref} + if $last_success_row; + } $log=$row->[0]; $conf=$row->[1] || "not recorded" ; $stage=$row->[2] || "unknown"; $changed_this_run = $row->[3]; $changed_since_success = $row->[4]; - $branch = $row->[5]; my $log_file_names = $row->[6]; $scm = $row->[7]; $scm ||= 'cvs'; # legacy scripts + $scmurl = $row->[8]; + $scmurl = undef unless $scmurl =~ /^http/; # slight sanity check + $scmurl = 'http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;h=' + if ($scmurl eq 'http://git.postgresql.org/git/postgresql.git'); $log_file_names =~ s/^\{(.*)\}$/$1/; @log_file_names=split(',',$log_file_names) if $log_file_names; - $sth->finish; - $statement = <prepare($statement); $sth->execute($system); $info_row=$sth->fetchrow_hashref; - # $sysinfo = join(" ",@$row); + + my $latest_personality = $db->selectrow_arrayref(q{ + select os_version, compiler_version + from personality + where effective_date < ? + and name = ? + order by effective_date desc limit 1 + }, undef, $logdate, $system); + if ($latest_personality) + { + $info_row->{os_version} = $latest_personality->[0]; + $info_row->{compiler_version} = $latest_personality->[1]; + } $sth->finish; + my $stage_times_query = q{ + select log_stage, stage_duration + from build_status_log + where sysname = ? and snapshot = ? + }; + $stage_times = + $db->selectall_hashref($stage_times_query,'log_stage',undef, + $system,$logdate); + $stage_times_query = q{ + select sum(stage_duration) + from build_status_log + where sysname = ? and snapshot = ? + }; + ($run_time) = $db->selectrow_array($stage_times_query,undef, + $system,$logdate); $db->disconnect; } -foreach my $chgd ($changed_this_run,$changed_since_success) -{ - my $cvsurl = 'http://anoncvs.postgresql.org/cvsweb.cgi'; - my $giturl = 'http://git.postgresql.org/gitweb?p=postgresql.git;a=commit;'; - my @lines = split(/!/,$chgd); - foreach (@lines) - { - if ($scm eq 'git') - { - s!(^\S+)(\s+)(\S+)!$1!; - } - elsif ($scm eq 'cvs') - { - next unless m!^pgsql/!; - s!(^\S+)(\s+)(\S+)!$1$2$3!; - } - } - $chgd = join("\n",@lines); - $chgd ||= 'not recorded'; - -} +my ($changed_this_run_logs, $changed_since_success_logs); +($changed_this_run, $changed_this_run_logs) = + process_changed($changed_this_run, + $git_head_ref,$last_build_git_ref); +($changed_since_success, $changed_since_success_logs) = + process_changed($changed_since_success, + $last_build_git_ref,$last_success_git_ref); $conf =~ s/\@/ [ a t ] /g; -map {s/&/&/g; s//>/g; s/\"/"/g;} ($log,$conf); -# map {s/!/\n/g} ($changed_this_run,$changed_since_success); - - -use POSIX qw(ceil); -my $lrfactor = 6; -my $logrows = ceil(scalar(@log_file_names)/$lrfactor); -my $logcells = $lrfactor * $logrows; - -my $heading_done; -my $urldt = uri_escape($logdate); - -my $cell = 0; - - print "Content-Type: text/html\n\n"; -if ($stage eq 'OK') -{ - print < - - - - PostgreSQL BuildFarm | Configuration summary for system "$system" - - - - -
- -
-

PostgreSQL Build Farm Log

- - - - - - - - - - - - - - - - - - -
System InformationFarm memberBranchOSCompilerArchitectureOwner
$system$branch$info_row->{operating_system} $info_row->{os_version}$info_row->{compiler} $info_row->{compiler_version}$info_row->{architecture}$info_row->{owner_email}
-EOHTML - - if ($info_row->{sys_notes}) - { - print < - - - - - - - - - - -
System NotesDateNotes
$info_row->{sys_notes_date}$info_row->{sys_notes}
-EOHTML - - } - -for my $logstage (@log_file_names) -{ - print "
\n" - unless $heading_done; - $heading_done = 1; - $cell++; - $logstage =~ s/\.log$//; - print "\n" if ($cell > 1 && $cell % $lrfactor == 1); - print "\n"; - print "\n" if ($cell % $lrfactor == 0); -} - -if ($cell) +$template->process('log.tt', + { + scm => $scm, + scmurl => $scmurl, + system => $system, + branch => $branch, + stage => $stage, + stage_times => $stage_times, + run_time => $run_time, + urldt => $logdate, + log_file_names => \@log_file_names, + conf => $conf, + log => $log, + changed_this_run => $changed_this_run, + changed_since_success => $changed_since_success, + changed_this_run_logs => $changed_this_run_logs, + changed_since_success_logs => $changed_since_success_logs, + info_row => $info_row, + git_head_ref => $git_head_ref, + last_build_git_ref => $last_build_git_ref, + last_success_git_ref => $last_success_git_ref, + + }); + +exit; + +########################################################## + +sub process_changed { - foreach my $rcell ($cell+1 .. $logcells) - { - print "\n" if ($rcell > 1 && $rcell % $lrfactor == 1); - print "\n"; - print "\n" if ($rcell % $lrfactor == 0); - } - print "
Stage Logs
$logstage
 
\n"; -} - -print < -

Configuration summary for system "$system"

-

Status 'OK' on snapshot taken $logdate

-
-$conf
-
-

Files changed this run

-
-$changed_this_run
-
-EOHTML -print <Log -
-$log
-
-EOHTML - print < -
-

-Hosting for the PostgreSQL Buildfarm is generously -provided by: -CommandPrompt, -The PostgreSQL Company -

-
- - -EOHTML -; - - exit; -} - -print < - - - - PostgreSQL BuildFarm | Log for system "$system" failure on snapshot taken $logdate - - - -
- -
-

PostgreSQL Build Farm Log

-

Details for system "$system" failure at stage $stage on snapshot taken $logdate

- - - - - - - - - - - - - - - - - - -
System InformationFarm memberBranchOSCompilerArchitectureOwner
$system$branch$info_row->{operating_system} $info_row->{os_version}$info_row->{compiler} $info_row->{compiler_version}$info_row->{architecture}$info_row->{owner_email}
-EOHTML - - if ($info_row->{sys_notes}) - { - print < - - - - - - - - - - -
System NotesDateNotes
$info_row->{sys_notes_date}$info_row->{sys_notes}
-EOHTML - } - -for my $logstage (@log_file_names) -{ - print "
\n" - unless $heading_done; - $heading_done = 1; - $cell++; - $logstage =~ s/\.log$//; - print "\n" if ($cell > 1 && $cell % $lrfactor == 1); - print "\n"; - print "\n" if ($cell % $lrfactor == 0); -} + my $chgd = shift; + my $git_to = shift; + my $git_from = shift; -if ($cell) -{ - foreach my $rcell ($cell+1 .. $logcells) + my @lines = split(/!/,$chgd); + my @changed_rows; + my %commits; + my @commit_logs; + my $gitcmd = "TZ=UTC GIT_DIR=$local_git_clone git log --date=local"; + foreach (@lines) { - print "\n" if ($rcell > 1 && $rcell % $lrfactor == 1); - print "\n"; - print "\n" if ($rcell % $lrfactor == 0); + next if ($scm eq 'cvs' and ! m!^(pgsql|master|REL\d_\d_STABLE)/!); + push(@changed_rows,[$1,$3]) if (m!(^\S+)(\s+)(\S+)!); + $commits{$3} = 1 if $scm eq 'git'; } - print "
Stage Logs
$logstage
 
\n"; + if ($git_from && $git_to) + { + my $format = 'commit %h %cd UTC%w(160,2,2)%s'; + my $gitlog = `$gitcmd --pretty=format:"$format" $git_from..$git_to 2>&1`; + @commit_logs = split(/(?=^commit)/m,$gitlog) + } + else + { + # normally we expect to have the git refs. this is just a fallback. + my $format = 'epoch: %at%ncommit %h %cd UTC%w(160,2,2)%s'; + foreach my $commit ( keys %commits ) + { + my $commitlog = + `$gitcmd -n 1 --pretty=format:"$format" $commit 2>&1`; + push(@commit_logs,$commitlog); + } + @commit_logs = reverse (sort @commit_logs); + s/epoch:.*\n// for (@commit_logs); + } + return (\@changed_rows,\@commit_logs); } - -print <Configuration summary -
-$conf
-
-

Files changed this run

-
-$changed_this_run
-
-

Files changed since last success

-
-$changed_since_success
-
-

Log

-
-$log
-
-
-
-

-Hosting for the PostgreSQL Buildfarm is generously -provided by: -CommandPrompt, -The PostgreSQL Company -

-
- - -EOHTML -; - - - -