From 20ec075a12bd2e9ffd7b5db7a311bc667ce368f0 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 17:23:22 -0700 Subject: Remove dep on Git::Repository --- lib/jitterbug/Builder.pm | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 1f9bd3d..bb2e7b1 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -10,7 +10,6 @@ use File::Path qw/rmtree/; use Path::Class; use Getopt::Long qw/:config no_ignore_case/; use File::Basename; -use Git::Repository; use jitterbug::Schema; use Cwd; #use Data::Dumper; @@ -110,7 +109,7 @@ sub run_task { debug("Removing $build_dir"); rmtree($build_dir, { error => \my $err } ); warn @$err if @$err; - $r = Git::Repository->create( clone => $repo => $build_dir ); + system("git clone $repo $build_dir"); } else { # If this is the first time, the repo won't exist yet debug("build_dir = $build_dir"); -- cgit 1.4.1 From 2340f08919962775cd28d9613cbd7f2665bda61b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 21:14:54 -0700 Subject: Mess around with test data --- .gitignore | 1 + lib/jitterbug/Builder.pm | 2 +- t/data/hook_data.yml | 8 ++++---- t/data/testing.git/HEAD | 1 - t/data/testing.git/config | 4 ---- t/data/testing.git/description | 1 - t/data/testing.git/info/exclude | 6 ------ .../pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx | Bin 5188 -> 0 bytes .../pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack | Bin 12344 -> 0 bytes t/data/testing.git/packed-refs | 2 -- 10 files changed, 6 insertions(+), 19 deletions(-) delete mode 100644 t/data/testing.git/HEAD delete mode 100644 t/data/testing.git/config delete mode 100644 t/data/testing.git/description delete mode 100644 t/data/testing.git/info/exclude delete mode 100644 t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx delete mode 100644 t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack delete mode 100644 t/data/testing.git/packed-refs (limited to 'lib/jitterbug/Builder.pm') diff --git a/.gitignore b/.gitignore index 819baac..01c76da 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ Build jitterbug.db MYMETA.json t/data/jitterbug.db +t/tmp diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index bb2e7b1..01f7075 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -104,7 +104,7 @@ sub run_task { my $build_dir = dir($dir, $project->name); my $r; - my $repo = $task->project->url . '.git'; + my $repo = $task->project->url; unless ($buildconf->{reuse_repo}) { debug("Removing $build_dir"); rmtree($build_dir, { error => \my $err } ); diff --git a/t/data/hook_data.yml b/t/data/hook_data.yml index da5b78f..401f6c4 100644 --- a/t/data/hook_data.yml +++ b/t/data/hook_data.yml @@ -16,8 +16,8 @@ commits: removed: [] timestamp: 2010-09-23T08:04:42-07:00 - url: https://github.com/franckcuny/Dancer/commit/22116bcdb229c1514f3069aaaf9c87e9d5455409 -compare: https://github.com/franckcuny/Dancer/compare/db8d023...22116bc + url: https://github.com/franckcuny/testing/commit/22116bcdb229c1514f3069aaaf9c87e9d5455409 +compare: https://github.com/franckcuny/testing/compare/db8d023...22116bc forced: !!perl/scalar:JSON::XS::Boolean 0 pusher: email: franck@lumberjaph.net @@ -32,12 +32,12 @@ repository: has_issues: !!perl/scalar:JSON::XS::Boolean 0 has_wiki: !!perl/scalar:JSON::XS::Boolean 1 homepage: '' - name: Dancer + name: testing open_issues: 0 owner: email: franck@lumberjaph.net name: franckcuny private: !!perl/scalar:JSON::XS::Boolean 1 pushed_at: 2010/09/23 08:04:49 -0700 - url: ./t/data/testing.git + url: ./t/data/testing watchers: 1 diff --git a/t/data/testing.git/HEAD b/t/data/testing.git/HEAD deleted file mode 100644 index cb089cd..0000000 --- a/t/data/testing.git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/t/data/testing.git/config b/t/data/testing.git/config deleted file mode 100644 index 07d359d..0000000 --- a/t/data/testing.git/config +++ /dev/null @@ -1,4 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true diff --git a/t/data/testing.git/description b/t/data/testing.git/description deleted file mode 100644 index 498b267..0000000 --- a/t/data/testing.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/t/data/testing.git/info/exclude b/t/data/testing.git/info/exclude deleted file mode 100644 index a5196d1..0000000 --- a/t/data/testing.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx deleted file mode 100644 index f03f9d2..0000000 Binary files a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.idx and /dev/null differ diff --git a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack b/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack deleted file mode 100644 index 6d0725c..0000000 Binary files a/t/data/testing.git/objects/pack/pack-298dcfe572066343c474309f9e4bb06ea58d811d.pack and /dev/null differ diff --git a/t/data/testing.git/packed-refs b/t/data/testing.git/packed-refs deleted file mode 100644 index 4a1d788..0000000 --- a/t/data/testing.git/packed-refs +++ /dev/null @@ -1,2 +0,0 @@ -# pack-refs with: peeled -3ab75b9a29e09bf027f64250b44cab19b316c128 refs/heads/master -- cgit 1.4.1 From fe1f2bfe923e5941b8b988684015b31cba3969ba Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 22:22:07 -0700 Subject: Silence noisy checkout output --- lib/jitterbug/Builder.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 01f7075..256d3d5 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -122,7 +122,9 @@ sub run_task { debug("Fetching new commits into $repo"); system("git fetch"); debug("Checking out correct commit"); - system("git checkout " . $task->commit->sha256 ); + + # TODO: this may fail on non-unixy systems + system("git checkout " . $task->commit->sha256 . " &>/dev/null" ); chdir $pwd; } else { debug("Creating new repo"); -- cgit 1.4.1 From f4127b1235b585b5d82082fcfd820b68479ceba4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 22 May 2011 23:01:33 -0700 Subject: Add a test to verify we get the expected sha1 --- lib/jitterbug/Builder.pm | 7 ++++--- scripts/capsule.sh | 8 +++++++- t/008_git_clone.t | 12 +++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 256d3d5..eb9f924 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -124,7 +124,7 @@ sub run_task { debug("Checking out correct commit"); # TODO: this may fail on non-unixy systems - system("git checkout " . $task->commit->sha256 . " &>/dev/null" ); + system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); chdir $pwd; } else { debug("Creating new repo"); @@ -138,10 +138,11 @@ sub run_task { $self->sleep(1); # avoid race conditions debug("Checking out " . $task->commit->sha256 . " from $repo into $build_dir\n"); - # $r->run( 'checkout', $task->commit->sha256 ); my $pwd = getcwd; chdir $build_dir; - system("git checkout " . $task->commit->sha256 ); + + # TODO: this may fail on non-unixy systems + system("git checkout " . $task->commit->sha256 . "&>/dev/null"); chdir $pwd; my $builder = $conf->{'jitterbug'}{'projects'}{$project->name}{'builder'} diff --git a/scripts/capsule.sh b/scripts/capsule.sh index 9fca79e..e6a5036 100755 --- a/scripts/capsule.sh +++ b/scripts/capsule.sh @@ -47,7 +47,6 @@ function jitterbug_build () { fi } - echo "Creating report_path=$report_path" mkdir -p $report_path @@ -60,6 +59,9 @@ if [ $use_perlbrew ]; then theperl=$(perl -e 'print $^V') logfile="$report_path/perl-$theperl.txt" + mkdir -p $report_path + touch $logfile + echo ">perlbrew switch $theperl" perlbrew switch $theperl # TODO: check error condition @@ -69,5 +71,9 @@ if [ $use_perlbrew ]; then else theperl=$(perl -e 'print $^V') logfile="$report_path/perl-$theperl.txt" + + mkdir -p $report_path + touch $logfile + jitterbug_build fi diff --git a/t/008_git_clone.t b/t/008_git_clone.t index 6e33018..5a7f915 100644 --- a/t/008_git_clone.t +++ b/t/008_git_clone.t @@ -1,4 +1,4 @@ -use Test::More tests => 3; +use Test::More tests => 4; use Test::Exception; use strict; use warnings; @@ -49,11 +49,17 @@ if (can_run('git')){ my $gitrepo = "t/data/testing"; dircopy "$gitrepo/._git_", "$gitrepo/.git" unless -e "$gitrepo/.git"; - lives_ok sub { system("$^X scripts/post_to_hook.pl") }, 'post_to_hook.pl lives'; + lives_ok sub { system("$^X -Ilib scripts/post_to_hook.pl") }, 'post_to_hook.pl lives'; - lives_ok sub { system("$^X scripts/builder.pl -c t/data/test.yml -C") }, 'builder.pl lives'; + + lives_ok sub { # $ENV{DEBUG} = 1; + system("$^X -Ilib scripts/builder.pl -c t/data/test.yml -C") + }, 'builder.pl lives'; ok(-e "t/tmp/build/testing/.git", 'found a testing git repo'); + chdir "t/tmp/build/testing"; + chomp( my $sha1 = qx{git rev-parse HEAD} ); + is($sha1,"3ab75b9a29e09bf027f64250b44cab19b316c128", "got expected sha1 in repo"); } else { skip "Git not available, skipping tests", 3; } -- cgit 1.4.1 From 8443ce457031e90025650264983ce06a18dfe645 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 16:48:33 -0700 Subject: Factor out git logic to separate function --- lib/jitterbug/Builder.pm | 51 ++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index eb9f924..a70e560 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -80,30 +80,9 @@ sub sleep { sleep $interval; } -sub run_task { - my ($self,$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(); - $task->update({started_when => $dt}); - $desc->{'build'}{'start_time'} = $dt->epoch; - debug("Build Start"); +sub _prepare_git_repo { + my ($self, $task, $buildconf, $build_dir) = @_; - my $report_path = dir( - $conf->{'jitterbug'}{'reports'}{'dir'}, - $project->name, - $task->commit->sha256, - ); - my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; - mkdir $dir unless -d $dir; - - my $build_dir = dir($dir, $project->name); - - my $r; my $repo = $task->project->url; unless ($buildconf->{reuse_repo}) { debug("Removing $build_dir"); @@ -144,6 +123,32 @@ sub run_task { # TODO: this may fail on non-unixy systems system("git checkout " . $task->commit->sha256 . "&>/dev/null"); chdir $pwd; +} + +sub run_task { + my ($self,$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(); + $task->update({started_when => $dt}); + $desc->{'build'}{'start_time'} = $dt->epoch; + debug("Build Start"); + + my $report_path = dir( + $conf->{'jitterbug'}{'reports'}{'dir'}, + $project->name, + $task->commit->sha256, + ); + my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; + mkdir $dir unless -d $dir; + + my $build_dir = dir($dir, $project->name); + + $self->_prepare_git_repo($task, $buildconf, $build_dir); my $builder = $conf->{'jitterbug'}{'projects'}{$project->name}{'builder'} || $conf->{'jitterbug'}{'build_process'}{'builder'}; -- cgit 1.4.1 From 998b3daae7921b677b72f9bc74646bea864ce25f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 16:54:28 -0700 Subject: Factor out result parsing to another function --- lib/jitterbug/Builder.pm | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index a70e560..fe820c3 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -154,9 +154,7 @@ sub run_task { || $conf->{'jitterbug'}{'build_process'}{'builder'}; my $perlbrew = $conf->{'jitterbug'}{'options'}{'perlbrew'}; - my $email_on_pass = $conf->{'jitterbug'}{'options'}{'email_on_pass'}; - debug("email_on_pass = $email_on_pass"); debug("perlbrew = $perlbrew"); # If the project has custom builder variables, use those. Otherwise, use the global setting @@ -171,6 +169,23 @@ sub run_task { $desc->{'build'}{'end_time'} = time(); + $self->_parse_results($report_path, $conf, $task, $desc); + + $task->commit->update( { + content => JSON::encode_json($desc), + } ); + debug("Task completed for " . $task->commit->sha256 . "\n"); + + $task->delete(); + + debug("Task removed from " . $task->project->name . "\n"); +} + +sub _parse_results { + my ($self, $report_path, $conf, $task, $desc) = @_; + my $email_on_pass = $conf->{'jitterbug'}{'options'}{'email_on_pass'}; + debug("email_on_pass = $email_on_pass"); + my @versions = glob( $report_path . '/*' ); foreach my $version (@versions) { open my $fh, '<', $version; @@ -237,14 +252,4 @@ sub run_task { $desc->{'build'}{'version'}{$name} = $result; close $fh; } - - $task->commit->update( { - content => JSON::encode_json($desc), - } ); - debug("Task completed for " . $task->commit->sha256 . "\n"); - - $task->delete(); - - debug("Task removed from " . $task->project->name . "\n"); } - -- cgit 1.4.1 From 6a46d858d3485ac1100cde4b591dd1b578c9b5de Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 17:01:32 -0700 Subject: Factor out the actual build for each task into another function --- lib/jitterbug/Builder.pm | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index fe820c3..c69c675 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -125,24 +125,9 @@ sub _prepare_git_repo { chdir $pwd; } -sub run_task { - my ($self,$task) = @_; - - my $desc = JSON::decode_json( $task->commit->content ); - my $conf = $self->{'conf'}; +sub build_task { + my ($self, $conf, $project, $task, $report_path) = @_; my $buildconf = $conf->{'jitterbug'}{'build_process'}; - my $project = $task->project; - - my $dt = DateTime->now(); - $task->update({started_when => $dt}); - $desc->{'build'}{'start_time'} = $dt->epoch; - debug("Build Start"); - - my $report_path = dir( - $conf->{'jitterbug'}{'reports'}{'dir'}, - $project->name, - $task->commit->sha256, - ); my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; mkdir $dir unless -d $dir; @@ -166,6 +151,26 @@ sub run_task { debug("Going to run builder : $builder_command"); my $res = `$builder_command`; debug($res); +} + +sub run_task { + my ($self,$task) = @_; + + my $desc = JSON::decode_json( $task->commit->content ); + my $conf = $self->{'conf'}; + my $project = $task->project; + my $report_path = dir( + $conf->{'jitterbug'}{'reports'}{'dir'}, + $project->name, + $task->commit->sha256, + ); + + my $dt = DateTime->now(); + $task->update({started_when => $dt}); + $desc->{'build'}{'start_time'} = $dt->epoch; + debug("Build Start"); + + $self->build_task($conf, $project, $task, $report_path); $desc->{'build'}{'end_time'} = time(); -- cgit 1.4.1 From a2984e576811a035b568b5ff95a436199ea5dfb5 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 17:23:59 -0700 Subject: Factor out repo cloning --- lib/jitterbug/Builder.pm | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index c69c675..c168a66 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -80,15 +80,28 @@ sub sleep { sleep $interval; } +sub _clone_into { + my ($repo, $dir) = @_; + my $pwd = getcwd; + chdir $dir; + + debug("cloning $repo into $dir"); + system("git clone $repo $dir"); + + chdir $pwd; +} + sub _prepare_git_repo { - my ($self, $task, $buildconf, $build_dir) = @_; + my ($self, $task, $buildconf, $build_dir, $cached_repo_dir) = @_; my $repo = $task->project->url; unless ($buildconf->{reuse_repo}) { debug("Removing $build_dir"); rmtree($build_dir, { error => \my $err } ); warn @$err if @$err; - system("git clone $repo $build_dir"); + + _clone_into($repo, $build_dir); + } else { # If this is the first time, the repo won't exist yet debug("build_dir = $build_dir"); @@ -106,12 +119,7 @@ sub _prepare_git_repo { system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); chdir $pwd; } else { - debug("Creating new repo"); - my $pwd = getcwd; - debug("pwd=$pwd"); - chdir $build_dir; - system("git clone $repo $build_dir"); - chdir $pwd; + _clone_into($repo, $build_dir); } } $self->sleep(1); # avoid race conditions @@ -127,13 +135,18 @@ sub _prepare_git_repo { sub build_task { my ($self, $conf, $project, $task, $report_path) = @_; + my $buildconf = $conf->{'jitterbug'}{'build_process'}; - my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; + my $dir = $conf->{'jitterbug'}{'build'}{'dir'}; + mkdir $dir unless -d $dir; my $build_dir = dir($dir, $project->name); + my $cached_repo_dir = dir($dir, 'cached'); + + mkdir $cached_repo_dir unless -d $cached_repo_dir; - $self->_prepare_git_repo($task, $buildconf, $build_dir); + $self->_prepare_git_repo($task, $buildconf, $build_dir, $cached_repo_dir); my $builder = $conf->{'jitterbug'}{'projects'}{$project->name}{'builder'} || $conf->{'jitterbug'}{'build_process'}{'builder'}; @@ -151,6 +164,7 @@ sub build_task { debug("Going to run builder : $builder_command"); my $res = `$builder_command`; debug($res); + return $res; } sub run_task { -- cgit 1.4.1 From 2e70da0107303e88428d7ac58773cb0a06b5d5c3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 17:45:35 -0700 Subject: Refactor _parse_results and enable debugging in the git tests --- lib/jitterbug/Builder.pm | 10 +++++----- t/008_git_clone.t | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index c168a66..33efea2 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -234,15 +234,15 @@ sub _parse_results { 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); - debug("Running failure command: $failure_cmd"); - # does it look like a module name? if ($on_failure =~ /::/) { # we should do some error checking here eval "require $on_failure"; $on_failure->new($conf,$task,$output,'failure')->run; } else { + my $failure_cmd = sprintf("%s '%s' %s '%s' '%s' %s %s", $on_failure, $commiter, $task->project->name, $message, $output, $sha, $on_failure_cc_email); + debug("Running failure command: $failure_cmd"); + system($failure_cmd); } } elsif ($email_on_pass) { @@ -256,8 +256,6 @@ sub _parse_results { 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 =~ /::/) { @@ -265,6 +263,8 @@ sub _parse_results { eval "require $on_pass"; $on_pass->new($conf,$task,$output, 'pass')->run; } else { + 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"); system($pass_cmd); } } diff --git a/t/008_git_clone.t b/t/008_git_clone.t index 5a7f915..6733a14 100644 --- a/t/008_git_clone.t +++ b/t/008_git_clone.t @@ -52,7 +52,7 @@ if (can_run('git')){ lives_ok sub { system("$^X -Ilib scripts/post_to_hook.pl") }, 'post_to_hook.pl lives'; - lives_ok sub { # $ENV{DEBUG} = 1; + lives_ok sub { $ENV{DEBUG} = 1; system("$^X -Ilib scripts/builder.pl -c t/data/test.yml -C") }, 'builder.pl lives'; -- cgit 1.4.1 From c113da97a61813d5684eebb966f6fb9b8b3efeca Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 18:07:14 -0700 Subject: Refactor and alter git repo caching strategy Our previous strategy occasionally failed if a build got the cached git repo into an odd state (such as leaving a git lockfile), so now we clone a new repo for every build from our local cached copy. The only operations performed in the cached repo is a git fetch --prune --- lib/jitterbug/Builder.pm | 63 ++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 33efea2..5befade 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -95,42 +95,47 @@ sub _prepare_git_repo { my ($self, $task, $buildconf, $build_dir, $cached_repo_dir) = @_; my $repo = $task->project->url; - unless ($buildconf->{reuse_repo}) { - debug("Removing $build_dir"); - rmtree($build_dir, { error => \my $err } ); - warn @$err if @$err; + my $name = $task->project->name; - _clone_into($repo, $build_dir); + debug("Removing $build_dir"); + rmtree($build_dir, { error => \my $err } ); + warn @$err if @$err; + # If we aren't reusing/caching git repos, clone from remote into the build dir + unless ($buildconf->{reuse_repo}) { + _clone_into($repo, $build_dir); } else { - # If this is the first time, the repo won't exist yet + # We are caching git repos, so we clone a new repo from our local + # cached git repo, then checkout the correct sha1 + 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"); - - # TODO: this may fail on non-unixy systems - system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); - chdir $pwd; - } else { - _clone_into($repo, $build_dir); + unless ( -d $cached_repo_dir ) { + # If this is the first time, the repo won't exist yet + # Clone it into our cached repo directory + _clone_into($repo, $cached_repo_dir); } - } - $self->sleep(1); # avoid race conditions + my $pwd = getcwd; - debug("Checking out " . $task->commit->sha256 . " from $repo into $build_dir\n"); - my $pwd = getcwd; - chdir $build_dir; + chdir $cached_repo_dir; + # TODO: Error Checking - # TODO: this may fail on non-unixy systems - system("git checkout " . $task->commit->sha256 . "&>/dev/null"); - chdir $pwd; + debug("Fetching new commits into $repo"); + system("git fetch --prune"); + chdir $pwd; + + debug("Cloning from cached repo $cached_repo_dir into $build_dir"); + + _clone_into($cached_repo_dir, $build_dir); + chdir $build_dir; + + $self->sleep(1); # avoid race conditions + + # TODO: this may fail on non-unixy systems + debug("checking out " . $task->commit->sha256); + system("git checkout " . $task->commit->sha256 . "&>/dev/null" ); + + chdir $pwd; + } } sub build_task { -- cgit 1.4.1 From 915a1b86928015892b76156e5702a9a8032ce854 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 18:31:28 -0700 Subject: Attempt to fix cloning --- lib/jitterbug/Builder.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 5befade..7a06ecb 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -109,7 +109,7 @@ sub _prepare_git_repo { # cached git repo, then checkout the correct sha1 debug("build_dir = $build_dir"); - unless ( -d $cached_repo_dir ) { + unless ( -d catfile($cached_repo_dir,$name) ) { # If this is the first time, the repo won't exist yet # Clone it into our cached repo directory _clone_into($repo, $cached_repo_dir); @@ -119,7 +119,7 @@ sub _prepare_git_repo { chdir $cached_repo_dir; # TODO: Error Checking - debug("Fetching new commits into $repo"); + debug("Fetching new commits into $cached_repo_dir"); system("git fetch --prune"); chdir $pwd; -- cgit 1.4.1 From af2884967461e009186382329dcfd11c9d436c61 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 18:35:30 -0700 Subject: Import catfile --- lib/jitterbug/Builder.pm | 1 + 1 file changed, 1 insertion(+) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 7a06ecb..0413e4d 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -10,6 +10,7 @@ use File::Path qw/rmtree/; use Path::Class; use Getopt::Long qw/:config no_ignore_case/; use File::Basename; +use File::Spec::Functions; use jitterbug::Schema; use Cwd; #use Data::Dumper; -- cgit 1.4.1 From 25b912d55512f28cd7d839957df0d576a68bb6ea Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 18:53:11 -0700 Subject: Attempt to fix cloning again --- lib/jitterbug/Builder.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 0413e4d..1f66343 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -113,7 +113,7 @@ sub _prepare_git_repo { unless ( -d catfile($cached_repo_dir,$name) ) { # If this is the first time, the repo won't exist yet # Clone it into our cached repo directory - _clone_into($repo, $cached_repo_dir); + _clone_into($repo, catfile($cached_repo_dir, $name)); } my $pwd = getcwd; -- cgit 1.4.1 From 6db7e1a4e8e1689514171eeb0863e915e96ed508 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 19:21:36 -0700 Subject: Make sure the cached repo dir exists and clone from the correct cached dir --- lib/jitterbug/Builder.pm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 1f66343..6f882b4 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -110,6 +110,8 @@ sub _prepare_git_repo { # cached git repo, then checkout the correct sha1 debug("build_dir = $build_dir"); + mkdir $cached_repo_dir unless -d $cached_repo_dir; + unless ( -d catfile($cached_repo_dir,$name) ) { # If this is the first time, the repo won't exist yet # Clone it into our cached repo directory @@ -124,9 +126,9 @@ sub _prepare_git_repo { system("git fetch --prune"); chdir $pwd; - debug("Cloning from cached repo $cached_repo_dir into $build_dir"); + debug("Cloning from cached repo $cached_repo_dir/$name into $build_dir"); - _clone_into($cached_repo_dir, $build_dir); + _clone_into(catdir($cached_repo_dir,$name), $build_dir); chdir $build_dir; $self->sleep(1); # avoid race conditions -- cgit 1.4.1 From 6b15ad18f2297bd195a3878ce6170de53db20ce5 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 19:31:04 -0700 Subject: Call git fetch from the correct directory --- lib/jitterbug/Builder.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 6f882b4..0eeab30 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -111,23 +111,24 @@ sub _prepare_git_repo { debug("build_dir = $build_dir"); mkdir $cached_repo_dir unless -d $cached_repo_dir; + my $cached_repo = catfile($cached_repo_dir,$name) ); - unless ( -d catfile($cached_repo_dir,$name) ) { + unless ( -d $cached_repo ) { # If this is the first time, the repo won't exist yet # Clone it into our cached repo directory - _clone_into($repo, catfile($cached_repo_dir, $name)); + _clone_into($repo, $cached_repo); } my $pwd = getcwd; - chdir $cached_repo_dir; + chdir $cached_repo; # TODO: Error Checking - debug("Fetching new commits into $cached_repo_dir"); + debug("Fetching new commits into $cached_repo"); system("git fetch --prune"); - chdir $pwd; - debug("Cloning from cached repo $cached_repo_dir/$name into $build_dir"); + $self->sleep(1); # avoid race conditions + debug("Cloning from cached repo $cached_repo_dir/$name into $build_dir"); _clone_into(catdir($cached_repo_dir,$name), $build_dir); chdir $build_dir; -- cgit 1.4.1 From 66d50b4d29b2656005c8b46f6222ccdb1a802c72 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 23 May 2011 19:32:54 -0700 Subject: Fix syntax error --- lib/jitterbug/Builder.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/jitterbug/Builder.pm') diff --git a/lib/jitterbug/Builder.pm b/lib/jitterbug/Builder.pm index 0eeab30..ab96251 100644 --- a/lib/jitterbug/Builder.pm +++ b/lib/jitterbug/Builder.pm @@ -111,7 +111,7 @@ sub _prepare_git_repo { debug("build_dir = $build_dir"); mkdir $cached_repo_dir unless -d $cached_repo_dir; - my $cached_repo = catfile($cached_repo_dir,$name) ); + my $cached_repo = catfile($cached_repo_dir,$name); unless ( -d $cached_repo ) { # If this is the first time, the repo won't exist yet -- cgit 1.4.1