each release set.
IN272KZWHENW2TCR3LWQ6OZAEESJL5S7AEL3GYLJTWHJUDE6HADAC DR4F6YUTVOY2PEWA3OLS5TVQ5L5GWVFAK3EJDNKWIEVB5NTB52QAC OIUIYIV223PEQ47UPM5FKE24OTYCCZRHS2UON4XSEKQWRVZWJCIAC ZNFDFJHGXHSUP3NT5BZSGZPUFYMXCNTJRLSVD6PYF3N6O6ONAWRAC 4X6NS66QDWR4S4ZZFKN2QOJQII5ZYIMTDYRHK25N6NJSROVLHJ6QC LQ5QEDVVHVGX67NJZQ46HOSY336VCLN63L3DT6QNSDV6ARVARITAC J5UVLXOK6EDIL5I7VKWH4V2QDS4DPD7FHRK6XBWSXFRQS4JKXFZQC FHF6IZJQPUQHY5QWQYRPZVDBRLHREWRHGNKVQDT7F3GQKKLZXJKQC JFZNAYJXKCMXYHGCLTRH7Q6TOFGJ4BT6332GONCWVYRLNMDDG3KAC G6HJY2V4CSSZF6BPIMRMRAJYRKPLTCBUFTJWZWK3BSNT235CZQ6QC TMP2FRIWXSSLCWOODKHRCVVCF26O7IXGB5KERZNOL5P5L26SHKMQC 2AIIYGI54TEFYBCGWMUA7JG2DMJXBKMYUZ7CG6ETIXF4ENNP74CQC AFTXA575C6JTVLVXTYJUKQGPLBO3NFORLO5XDSPHNL44HXLRH4TAC 2GK5DOU7ODF4WBSN3QTD3WIO52VTL2LOAXKGCDEMMAQPTEO4A4HAC WZ3AEJ67LOG5L335AAC2BDLIJPIU4VSCGBMATBHDZC26ECRS5A6AC my $query = "1 = 1";foreach my $attr (@attrs) {$attr =~ /^([\w-]+)=([\w-]*)$/ or die "invalid attribute in release set: $attr";my $name = $1;my $value = $2;# !!! Yes, this is horribly injection-prone... (though# name/value are filtered above). Should use SQL::Abstract,# but it can't deal with subqueries. At least we should use# placeholders.$query .= " and (select count(*) from buildinputs where build = $id and name = '$name' and value = '$value') = 1";}return $query;}
# The timestamp of the release is the highest timestamp of all# constitutent builds.my $timestamp = 0;foreach my $job (@{$c->stash->{jobs}}) {my $thisBuild;if ($job->isprimary) {$thisBuild = $primaryBuild;} else {# Find a build of this job that had the primary build# as input. If there are multiple, prefer successful# ones, and then oldest. !!! order_by buildstatus is hacky($thisBuild) = $primaryBuild->dependentBuilds->search({ attrname => $job->job, finished => 1 },{ join => 'resultInfo', rows => 1, order_by => ["buildstatus", "timestamp"], where => \ attrsToSQL($job->attrs, "build.id")});}if ($job->mayfail != 1) {if (!defined $thisBuild) {$status = 2 if $status == 0; # = unfinished} elsif ($thisBuild->resultInfo->buildstatus != 0) {$status = 1; # = failed}}$timestamp = $thisBuild->timestampif defined $thisBuild && $thisBuild->timestamp > $timestamp;push @jobs, { build => $thisBuild, job => $job };}return{ id => $primaryBuild->id, releasename => $primaryBuild->get_column('releasename'), jobs => [@jobs], status => $status, timestamp => $timestamp};
return ($project, $releaseSet, $primaryJob, $jobs);
sub getPrimaryBuildsForReleaseSet {my ($project, $primaryJob) = @_;my @primaryBuilds = $project->builds->search({ attrname => $primaryJob->job, finished => 1 },{ join => 'resultInfo', order_by => "timestamp DESC", '+select' => ["resultInfo.releasename"], '+as' => ["releasename"], where => \ attrsToSQL($primaryJob->attrs, "me.id")});return @primaryBuilds;}
my $latest;foreach my $release (getPrimaryBuildsForReleaseSet($project, $primaryJob)) {if (getRelease($c, $release)->{status} == 0) {$latest = $release;last;}}
my $latest = getLatestSuccessfulRelease($project, $primaryJob, $jobs);
}sub attrsToSQL {my ($attrs, $id) = @_;my @attrs = split / /, $attrs;my $query = "1 = 1";foreach my $attr (@attrs) {$attr =~ /^([\w-]+)=([\w-]*)$/ or die "invalid attribute in release set: $attr";my $name = $1;my $value = $2;# !!! Yes, this is horribly injection-prone... (though# name/value are filtered above). Should use SQL::Abstract,# but it can't deal with subqueries. At least we should use# placeholders.$query .= " and (select count(*) from buildinputs where build = $id and name = '$name' and value = '$value') = 1";}return $query;}sub getPrimaryBuildsForReleaseSet {my ($project, $primaryJob) = @_;my @primaryBuilds = $project->builds->search({ attrname => $primaryJob->job, finished => 1 },{ join => 'resultInfo', order_by => "timestamp DESC", '+select' => ["resultInfo.releasename"], '+as' => ["releasename"], where => \ attrsToSQL($primaryJob->attrs, "me.id")});return @primaryBuilds;}sub getRelease {my ($primaryBuild, $jobs) = @_;my @jobs = ();my $status = 0; # = okay# The timestamp of the release is the highest timestamp of all# constitutent builds.my $timestamp = 0;foreach my $job (@{$jobs}) {my $thisBuild;if ($job->isprimary) {$thisBuild = $primaryBuild;} else {# Find a build of this job that had the primary build# as input. If there are multiple, prefer successful# ones, and then oldest. !!! order_by buildstatus is hacky($thisBuild) = $primaryBuild->dependentBuilds->search({ attrname => $job->job, finished => 1 },{ join => 'resultInfo', rows => 1, order_by => ["buildstatus", "timestamp"], where => \ attrsToSQL($job->attrs, "build.id")});}if ($job->mayfail != 1) {if (!defined $thisBuild) {$status = 2 if $status == 0; # = unfinished} elsif ($thisBuild->resultInfo->buildstatus != 0) {$status = 1; # = failed}}$timestamp = $thisBuild->timestampif defined $thisBuild && $thisBuild->timestamp > $timestamp;push @jobs, { build => $thisBuild, job => $job };}return{ id => $primaryBuild->id, releasename => $primaryBuild->get_column('releasename'), jobs => [@jobs], status => $status, timestamp => $timestamp};
keepBuild $_ foreach @recentBuilds;
# Go over all releases in this project.foreach my $releaseSet ($project->releasesets->all) {print "*** looking for builds to keep in release set ", $project->name, ":", $releaseSet->name, "\n";(my $primaryJob) = $releaseSet->releasesetjobs->search({isprimary => 1});my $jobs = [$releaseSet->releasesetjobs->all];# Keep all builds belonging to the most recent successful release.my $latest = getLatestSuccessfulRelease($project, $primaryJob, $jobs);if (defined $latest) {print "keeping latest successful release ", $latest->id, " (", $latest->get_column('releasename'), ")\n";my $release = getRelease($latest, $jobs);keepBuild $_->{build} foreach @{$release->{jobs}};}