diff options
-rw-r--r-- | MANIFEST | 1 | ||||
-rw-r--r-- | config.yml | 8 | ||||
-rw-r--r-- | lib/jitterbug/Builder.pm | 52 | ||||
-rw-r--r-- | lib/jitterbug/Emailer.pm | 44 | ||||
-rwxr-xr-x | scripts/build-pass.sh | 14 | ||||
-rwxr-xr-x | scripts/capsule.sh | 31 | ||||
-rw-r--r-- | t/005_builder.t | 27 | ||||
-rw-r--r-- | t/006_emailer.t | 4 | ||||
-rw-r--r-- | t/data/test.yml | 17 | ||||
-rw-r--r-- | t/lib/jitterbug/Test.pm | 13 |
10 files changed, 162 insertions, 49 deletions
diff --git a/MANIFEST b/MANIFEST index 268d204..0adea84 100644 --- a/MANIFEST +++ b/MANIFEST @@ -14,7 +14,6 @@ lib/jitterbug/Schema/Result/Project.pm lib/jitterbug/Schema/Result/Task.pm lib/jitterbug/Task.pm lib/jitterbug/WebService.pm -Makefile MANIFEST This list of files MANIFEST.SKIP public/404.html diff --git a/config.yml b/config.yml index bf9bd23..cb1e111 100644 --- a/config.yml +++ b/config.yml @@ -17,14 +17,22 @@ jitterbug: dir: /tmp/build build_process: builder: ./scripts/capsule.sh + builder_variables: on_failure: ./scripts/build-failed.sh on_failure_cc_email: alice@example.com on_failure_from_email: donotreply@example.com on_failure_subject_prefix: "[jitterbug] FAIL " on_failure_header: on_failure_footer: + on_pass: ./scripts/build-pass.sh + on_pass_cc_email: alice@example.com + on_pass_subject_prefix: "[jitterbug] PASS " + on_pass_from_email: donotreply@example.com + on_pass_header: + on_pass_footer: options: perlbrew: 1 + email_on_pass: 0 plugins: DBIC: diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 1f201e2..deb4c5b 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -116,9 +116,15 @@ sub run_task { my $builder = $conf->{'jitterbug'}{'build_process'}{'builder'}; - my $perlbrew = $conf->{'options'}{'perlbrew'} || 1; + my $perlbrew = $conf->{'jitterbug'}{'options'}{'perlbrew'}; + my $email_on_pass = $conf->{'jitterbug'}{'options'}{'email_on_pass'}; - my $builder_command = "$builder $build_dir $report_path $perlbrew"; + debug("email_on_pass = $email_on_pass"); + debug("perlbrew = $perlbrew"); + + my $builder_variables = $conf->{'jitterbug'}{'build_process'}{'builder_variables'}; + + my $builder_command = "$builder_variables $builder $build_dir $report_path $perlbrew"; debug("Going to run builder : $builder_command"); my $res = `$builder_command`; @@ -136,15 +142,21 @@ sub run_task { ($result) = $lines =~ /Result:\s(\w+)/; my ( $name, ) = basename($version); $name =~ s/\.txt//; + + debug("Result of test suite is $result"); + + # TODO: Unify this code + if ( !$result || ($result && $result !~ /PASS/ )) { + debug("Emailing FAIL report"); # mail author of the commit $result = "FAIL"; - my $message = $desc->{'message'}; - my $commiter = $desc->{'author'}{'email'}; - my $output = $lines; - my $sha = $desc->{'id'}; - my $on_failure = $conf->{'jitterbug'}{'build_process'}{'on_failure'}; - my $on_failure_cc_email = $conf->{'jitterbug'}{'build_process'}{'on_failure_email'}; + my $message = $desc->{'message'}; + my $commiter = $desc->{'author'}{'email'}; + my $output = $lines; + my $sha = $desc->{'id'}; + my $on_failure = $conf->{'jitterbug'}{'build_process'}{'on_failure'}; + my $on_failure_cc_email = $conf->{'jitterbug'}{'build_process'}{'on_failure_cc_email'}; $message =~ s/'/\\'/g; $commiter =~ s/'/\\'/g; $output =~ s/'/\\'/g; my $failure_cmd = sprintf("%s '%s' %s '%s' '%s' %s %s", $on_failure, $commiter, $task->project->name, $message, $output, $sha, $on_failure_cc_email); @@ -154,10 +166,32 @@ sub run_task { if ($on_failure =~ /::/) { # we should do some error checking here eval "require $on_failure"; - $on_failure->new($conf,$task,$output)->run; + $on_failure->new($conf,$task,$output,'failure')->run; } else { system($failure_cmd); } + } elsif ($email_on_pass) { + debug("Emailing PASS report"); + $result = "PASS"; + my $message = $desc->{'message'}; + my $commiter = $desc->{'author'}{'email'}; + my $output = $lines; + my $sha = $desc->{'id'}; + my $on_pass = $conf->{'jitterbug'}{'build_process'}{'on_pass'}; + my $on_pass_cc_email = $conf->{'jitterbug'}{'build_process'}{'on_pass_cc_email'}; + + $message =~ s/'/\\'/g; $commiter =~ s/'/\\'/g; $output =~ s/'/\\'/g; + my $pass_cmd = sprintf("%s '%s' %s '%s' '%s' %s %s", $on_pass, $commiter, $task->project->name, $message, $output, $sha, $on_pass_cc_email); + debug("Running pass command: $pass_cmd"); + + # does it look like a module name? + if ($on_pass =~ /::/) { + # we should do some error checking here + eval "require $on_pass"; + $on_pass->new($conf,$task,$output, 'pass')->run; + } else { + system($pass_cmd); + } } $desc->{'build'}{'version'}{$name} = $result; close $fh; diff --git a/lib/jitterbug/Emailer.pm b/lib/jitterbug/Emailer.pm index d21028f..d93ec79 100644 --- a/lib/jitterbug/Emailer.pm +++ b/lib/jitterbug/Emailer.pm @@ -7,11 +7,12 @@ use JSON; sub new { my $self = bless {} => shift; - my ($conf,$task,$tap_output) = @_; + my ($conf,$task,$tap_output,$status) = @_; # smelly - $self->{'conf'} = $conf; - $self->{'task'} = $task; + $self->{'conf'} = $conf; + $self->{'task'} = $task; $self->{'tap_output'} = $tap_output; + $self->{'status'} = $status; return $self; } @@ -32,38 +33,39 @@ BODY } sub run { - my $self = shift; - my $task = $self->{'task'}; - my $buildconf = $self->{'conf'}->{'jitterbug'}{'build_process'}; - my $project = $task->project->name; - my $tap = $self->{'tap_output'}; - my $sha1 = $task->commit->sha256; - my $shortsha1 = substr($sha1, 0, 8); - my $desc = JSON::decode_json( $task->commit->content ); - my $email = $desc->{'author'}{'email'}; - my $message = $desc->{'message'}; - my $header = $buildconf->{'on_failure_header'}; - my $footer = $buildconf->{'on_failure_footer'}; - my $body = _make_body($header,$message, $tap, $footer); - my $summary = ''; + my $self = shift; + my $task = $self->{'task'}; + my $status = $self->{'status'}; + my $buildconf = $self->{'conf'}->{'jitterbug'}{'build_process'}; + my $project = $task->project->name; + my $tap = $self->{'tap_output'}; + my $sha1 = $task->commit->sha256; + my $shortsha1 = substr($sha1, 0, 8); + my $desc = JSON::decode_json( $task->commit->content ); + my $email = $desc->{'author'}{'email'}; + my $message = $desc->{'message'}; + my $header = $buildconf->{"on_${status}_header"}; + my $footer = $buildconf->{"on_${status}_footer"}; + my $body = _make_body($header,$message, $tap, $footer); + my $summary = ''; if ( $tap =~ m/^(Test Summary Report.*)/ms ) { $summary = $1; } - # Expand placeholders in our failure email + # Expand placeholders in our email $body =~ s/%%PROJECT%%/$project/g; $body =~ s/%%SHA1%%/$sha1/g; $body =~ s/%%SUMMARY%%/$summary/g; - my $stuff = Email::Stuff->from($buildconf->{'on_failure_from_email'}) + my $stuff = Email::Stuff->from($buildconf->{"on_${status}_from_email"}) # bug in Email::Stuff brakes chaining if $email is empty ->to($email || " ") - ->cc($buildconf->{'on_failure_cc_email'}) + ->cc($buildconf->{"on_${status}_cc_email"}) ->text_body($body) ->subject( - $buildconf->{'on_failure_subject_prefix'} . "$project @ $shortsha1 $message" + $buildconf->{"on_${status}_subject_prefix"} . "$project @ $shortsha1 $message" ); # Should we attach a build log for convenience? # ->attach(io('dead_bunbun_faked.gif')->all, diff --git a/scripts/build-pass.sh b/scripts/build-pass.sh new file mode 100755 index 0000000..9f6f2b8 --- /dev/null +++ b/scripts/build-pass.sh @@ -0,0 +1,14 @@ +COMMITER=$1 +PROJECT=$2 +MESSAGE=$3 +OUTPUT=$4 +SHA=$5 +CC_EMAIL=$6 + +echo " +Message: +$MESSAGE + +Test Output: +$OUTPUT +" | mail -c "$CC_EMAIL" -s "[jitterbug] PASS $PROJECT @ $SHA" $COMMITER diff --git a/scripts/capsule.sh b/scripts/capsule.sh index abc632d..30c3877 100755 --- a/scripts/capsule.sh +++ b/scripts/capsule.sh @@ -2,23 +2,29 @@ # first arg: build_dir # second arg: report path +# third arg: should we use perlbrew? + +# this is getting smelly +builddir=$1 +report_path=$2 +perlbrew=$3 function jitterbug_build () { if [ -f 'dist.ini' ]; then echo "Found dist.ini, using Dist::Zilla" - dzil authordeps | cpanm - cpanm --installdeps . + dzil authordeps | cpanm >> $logfile 2>&1 + cpanm --installdeps . >> $logfile 2>&1 HARNESS_VERBOSE=1 dzil test >> $logfile 2>&1 elif [ -f 'Build.PL' ]; then echo "Found Build.PL, using Build.PL" - perl Build.PL + perl Build.PL >> $logfile 2>&1 # ./Build installdeps is not available in older Module::Build's - cpanm --installdeps . + cpanm --installdeps . >> $logfile 2>&1 HARNESS_VERBOSE=1 ./Build test --verbose >> $logfile 2>&1 elif [ -f 'Makefile.PL' ]; then echo "Found Makefile.PL" - perl Makefile.PL - cpanm --installdeps . + perl Makefile.PL >> $logfile 2>&1 + cpanm --installdeps . >> $logfile 2>&1 HARNESS_VERBOSE=1 make test >> $logfile 2>&1 elif [ -f 'setup.pir' ]; then echo "Found setup.pir" @@ -28,16 +34,17 @@ function jitterbug_build () { HARNESS_VERBOSE=1 parrot-nqp setup.nqp test >> $logfile 2>&1 elif [ -f 'Configure.pl' ]; then echo "Found Configure.pl" - perl Configure.pl - cpanm --installdeps . + perl Configure.pl >> $logfile 2>&1 + cpanm --installdeps . >> $logfile 2>&1 HARNESS_VERBOSE=1 make test >> $logfile 2>&1 + elif [ -f 'Makefile' ]; then + echo "Found a Makefile" + make test >> $logfile 2>&1 + elif [ -f 'Rakefile' ]; then + rake test >> $logfile 2>&1 fi } -# this is getting smelly -builddir=$1 -report_path=$2 -perlbrew=$3 echo "Creating report_path=$report_path" mkdir -p $report_path diff --git a/t/005_builder.t b/t/005_builder.t index 84e13ef..c1b92d7 100644 --- a/t/005_builder.t +++ b/t/005_builder.t @@ -4,6 +4,8 @@ use warnings; use Test::Most tests => 9; use Data::Dumper; +use lib 't/lib'; +use jitterbug::Test; use jitterbug::Builder; { @@ -32,6 +34,7 @@ use jitterbug::Builder; is($b->{'configfile'}, 't/data/test.yml'); is($b->run, 0, '->run returns 0 in cron mode'); + cmp_deeply($b->{'conf'}, { 'engines' => { 'xslate' => { @@ -44,7 +47,7 @@ use jitterbug::Builder; 'DBIC' => { 'schema' => { 'connect_info' => [ - 'dbi:SQLite:dbname=jitterbug.db' + 'dbi:SQLite:dbname=t/data/jitterbug.db' ], 'pckg' => 'jitterbug::Schema', 'skip_automake' => '1' @@ -54,7 +57,19 @@ use jitterbug::Builder; 'jitterbug' => { 'build_process' => { 'on_failure' => './scripts/build-failed.sh', - 'builder' => './scripts/capsule.sh' + 'builder' => './scripts/capsule.sh', + 'builder_variables' => 'STUFF=BLAH', + 'on_pass_header' => undef, + 'on_failure_subject_prefix' => '[jitterbug] FAIL ', + 'on_failure_from_email' => 'donotreply@example.com', + 'on_failure_footer' => undef, + 'on_failure_header' => undef, + 'on_pass_footer' => undef, + 'on_pass_cc_email' => 'alice@example.com', + 'on_pass_from_email' => 'donotreply@example.com', + 'on_failure_cc_email' => 'alice@example.com', + 'on_pass' => './scripts/build-pass.sh', + 'on_pass_subject_prefix' => '[jitterbug] PASS ' }, 'builder' => {}, 'reports' => { @@ -62,13 +77,19 @@ use jitterbug::Builder; }, 'build' => { 'dir' => '/tmp/build' - } + }, + 'options' => { + 'email_on_pass' => '0', + 'perlbrew' => '1' + }, + }, 'template' => 'xslate', 'appname' => 'jitterbug', 'layout' => 'main', 'logger' => 'file', 'builds_per_feed' => '5' + }); diff --git a/t/006_emailer.t b/t/006_emailer.t index 44dd328..297644c 100644 --- a/t/006_emailer.t +++ b/t/006_emailer.t @@ -33,7 +33,7 @@ sub setup { { my ($conf, $commit, $project, $task) = setup(); my $tap = "THIS IS TAP"; - my $e = jitterbug::Emailer->new($conf, $task, $tap); + my $e = jitterbug::Emailer->new($conf, $task, $tap, 'failure'); isa_ok($e,'jitterbug::Emailer'); can_ok($e,qw/new run/); @@ -89,7 +89,7 @@ Failed 1/11 test programs. 1/2498 subtests failed. Files=11, Tests=2498, 3 wallclock secs ( 0.20 usr 0.04 sys + 2.99 cusr 0.18 csys = 3.41 CPU) Result: FAIL TAP - my $e = jitterbug::Emailer->new($conf, $task, $tap); + my $e = jitterbug::Emailer->new($conf, $task, $tap, 'failure'); $e->run; my $email = $e->{'last_email_sent'}{'email'}; my $body = <<EMAIL; diff --git a/t/data/test.yml b/t/data/test.yml index e4144c3..897b734 100644 --- a/t/data/test.yml +++ b/t/data/test.yml @@ -17,7 +17,22 @@ jitterbug: dir: /tmp/build build_process: builder: ./scripts/capsule.sh + builder_variables: STUFF=BLAH on_failure: ./scripts/build-failed.sh + on_failure_cc_email: alice@example.com + on_failure_from_email: donotreply@example.com + on_failure_subject_prefix: "[jitterbug] FAIL " + on_failure_header: + on_failure_footer: + on_pass: ./scripts/build-pass.sh + on_pass_cc_email: alice@example.com + on_pass_subject_prefix: "[jitterbug] PASS " + on_pass_from_email: donotreply@example.com + on_pass_header: + on_pass_footer: + options: + perlbrew: 1 + email_on_pass: 0 plugins: DBIC: @@ -25,6 +40,6 @@ plugins: skip_automake: 1 pckg: "jitterbug::Schema" connect_info: - - dbi:SQLite:dbname=jitterbug.db + - dbi:SQLite:dbname=t/data/jitterbug.db diff --git a/t/lib/jitterbug/Test.pm b/t/lib/jitterbug/Test.pm new file mode 100644 index 0000000..36ee769 --- /dev/null +++ b/t/lib/jitterbug/Test.pm @@ -0,0 +1,13 @@ +package jitterbug::Test; +use strict; +use warnings; +use FindBin qw($Bin); + +BEGIN{ + qx{$^X -Ilib $Bin/../scripts/deploy_schema $Bin/data/test.yml} + unless -r qq{$Bin/data/jitterbug.db}; +}; + +1; + + |