diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/jitterbug/Builder.pm | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 461945c..02c07bd 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -12,10 +12,11 @@ use Getopt::Long qw/:config no_ignore_case/; use File::Basename; use Git::Repository; use jitterbug::Schema; +use Cwd; #use Data::Dumper; local $| = 1; -use constant DEBUG => 0; +use constant DEBUG => $ENV{DEBUG} || 0; sub new { my $self = bless {} => shift; @@ -85,6 +86,7 @@ sub run_task { my $desc = JSON::decode_json( $task->commit->content ); my $conf = $self->{'conf'}; + my $buildconf = $conf->{'jitterbug'}{'build_process'}; my $project = $task->project; my $dt = DateTime->now(); @@ -98,11 +100,10 @@ sub run_task { $project->name, $task->commit->sha256, ); + my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; + mkdir $dir unless -d $dir; - my $build_dir = dir( - $conf->{'jitterbug'}{'build'}{'dir'}, - $project->name, - ); + my $build_dir = dir($dir, $project->name); debug("Removing $build_dir"); rmtree($build_dir, { error => \my $err } ); @@ -110,11 +111,46 @@ sub run_task { $self->sleep(1); # avoid race conditions + my $r; my $repo = $task->project->url . '.git'; - my $r = Git::Repository->create( clone => $repo => $build_dir ); + unless ($buildconf->{reuse_repo}) { + debug("Removing $build_dir"); + rmtree($build_dir, { error => \my $err } ); + warn @$err if @$err; + $r = Git::Repository->create( clone => $repo => $build_dir ); + } else { + # If this is the first time, the repo won't exist yet + debug("build_dir = $build_dir"); + if( -d $build_dir ){ + my $pwd = getcwd; + chdir $build_dir; + # TODO: Error Checking + debug("Cleaning git repo"); + system("git clean -dfx"); + debug("Fetching new commits into $repo"); + system("git fetch"); + debug("Checking out correct commit"); + system("git checkout " . $task->commit->sha256 ); + chdir $pwd; + $r = Git::Repository->new( work_tree => $build_dir ); + } else { + debug("Creating new repo"); + my $pwd = getcwd; + debug("pwd=$pwd"); + chdir $build_dir; + system("git clone $repo $build_dir"); + #$r = Git::Repository->create( clone => $repo => $build_dir ); + chdir $pwd; + } + } + $self->sleep(1); # avoid race conditions debug("Checking out " . $task->commit->sha256 . " from $repo into $build_dir\n"); - $r->run( 'checkout', $task->commit->sha256 ); + # $r->run( 'checkout', $task->commit->sha256 ); + my $pwd = getcwd; + chdir $build_dir; + system("git checkout " . $task->commit->sha256 ); + chdir $pwd; my $builder = $conf->{'jitterbug'}{'projects'}{$project->name}{'builder'} || $conf->{'jitterbug'}{'build_process'}{'builder'}; @@ -144,6 +180,8 @@ sub run_task { while (<$fh>){ $lines .= $_; } + # if $result is undefined, either there was a build failure + # or the test output is not from a TAP harness ($result) = $lines =~ /Result:\s(\w+)/; my ( $name, ) = basename($version); $name =~ s/\.txt//; |