From f52ca0c5883c7612999883fca4ed4d1ad3a81359 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 3 Apr 2012 17:45:03 +0200 Subject: [PATCH] Add a redirect to the latest view result for which the underlying evaluation has finished completely This will be useful for the Nixpkgs channel mirror script: http://hydra.nixos.org/view/nixpkgs/unstable/latest-finished/channel is the channel containing the latest, consistent, tested set of builds. --- src/lib/Hydra/Controller/View.pm | 15 ++++++++++++++- src/lib/Hydra/Helper/Nix.pm | 10 ++++++++-- src/script/hydra-update-gc-roots | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/lib/Hydra/Controller/View.pm b/src/lib/Hydra/Controller/View.pm index 4f958f8e..89865b2c 100644 --- a/src/lib/Hydra/Controller/View.pm +++ b/src/lib/Hydra/Controller/View.pm @@ -140,7 +140,20 @@ sub latest : Chained('view') PathPart('latest') { # Redirect to the latest result in the view in which every build # is successful. my $latest = getLatestSuccessfulViewResult( - $c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs}); + $c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs}, 0); + error($c, "This view set has no successful results yet.") if !defined $latest; + $c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args)); +} + + +sub latest_finished : Chained('view') PathPart('latest-finished') { + my ($self, $c, @args) = @_; + + # Redirect to the latest result in the view in which every build + # is successful *and* where the jobset evaluation has finished + # completely. + my $latest = getLatestSuccessfulViewResult( + $c->stash->{project}, $c->stash->{primaryJob}, $c->stash->{jobs}, 1); error($c, "This view set has no successful results yet.") if !defined $latest; $c->res->redirect($c->uri_for($self->action_for("view_view"), $c->req->captures, $latest->id, @args)); } diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 9eb42759..2c64902b 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -222,10 +222,16 @@ sub getViewResult { sub getLatestSuccessfulViewResult { - my ($project, $primaryJob, $jobs) = @_; + my ($project, $primaryJob, $jobs, $finished) = @_; my $latest; foreach my $build (getPrimaryBuildsForView($project, $primaryJob)) { - return $build if getViewResult($build, $jobs)->{status} == 0; + my $result = getViewResult($build, $jobs); + next if $result->{status} != 0; + if ($finished) { + next unless defined $result->{eval}; + next if $result->{eval}->builds->search({ finished => 0 })->count > 0; + } + return $build; } return undef; } diff --git a/src/script/hydra-update-gc-roots b/src/script/hydra-update-gc-roots index 16aefb8c..a8c9de81 100755 --- a/src/script/hydra-update-gc-roots +++ b/src/script/hydra-update-gc-roots @@ -109,7 +109,7 @@ foreach my $project ($db->resultset('Projects')->search({}, { order_by => ["name my $jobs = [$view->viewjobs->all]; # Keep all builds belonging to the most recent successful view result. - my $latest = getLatestSuccessfulViewResult($project, $primaryJob, $jobs); + my $latest = getLatestSuccessfulViewResult($project, $primaryJob, $jobs, 0); if (defined $latest) { print STDERR " keeping latest successful view result ", $latest->id, " (", $latest->get_column('releasename'), ")\n"; my $result = getViewResult($latest, $jobs);