2015-08-17 14:18:07 +02:00
|
|
|
|
#! /usr/bin/env perl
|
2015-06-23 00:14:49 +02:00
|
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
use utf8;
|
|
|
|
|
use Hydra::Plugin;
|
|
|
|
|
use Hydra::Helper::Nix;
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
use Hydra::Helper::AddBuilds;
|
2015-06-23 00:14:49 +02:00
|
|
|
|
|
|
|
|
|
STDERR->autoflush(1);
|
|
|
|
|
binmode STDERR, ":encoding(utf8)";
|
|
|
|
|
|
|
|
|
|
my $config = getHydraConfig();
|
|
|
|
|
|
|
|
|
|
my $db = Hydra::Model::DB->new();
|
|
|
|
|
|
|
|
|
|
my @plugins = Hydra::Plugin->instantiate(db => $db, config => $config);
|
|
|
|
|
|
2016-05-27 14:32:48 +02:00
|
|
|
|
my $cmd = shift @ARGV or die "Syntax: hydra-notify build-started BUILD | build-finished BUILD-ID [BUILD-IDs...] | step-finished BUILD-ID STEP-NR LOG-PATH\n";
|
2015-06-23 00:14:49 +02:00
|
|
|
|
|
2016-03-11 21:48:31 -05:00
|
|
|
|
my $buildId = shift @ARGV or die;
|
|
|
|
|
my $build = $db->resultset('Builds')->find($buildId)
|
|
|
|
|
or die "build $buildId does not exist\n";
|
2016-05-27 14:32:48 +02:00
|
|
|
|
|
2016-03-11 21:48:31 -05:00
|
|
|
|
if ($cmd eq "build-finished") {
|
Enable declarative projects.
This allows fully declarative project specifications. This is best
illustrated by example:
* I create a new project, setting the declarative spec file to
"spec.json" and the declarative input to a git repo pointing
at git://github.com/shlevy/declarative-hydra-example.git
* hydra creates a special ".jobsets" jobset alongside the project
* Just before evaluating the ".jobsets" jobset, hydra fetches
declarative-hydra-example.git, reads spec.json as a jobset spec,
and updates the jobset's configuration accordingly:
{
"enabled": 1,
"hidden": false,
"description": "Jobsets",
"nixexprinput": "src",
"nixexprpath": "default.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
* When the "jobsets" job of the ".jobsets" jobset completes, hydra
reads its output as a JSON representation of a dictionary of
jobset specs and creates a jobset named "master" configured
accordingly (In this example, this is the same configuration as
.jobsets itself, except using release.nix instead of default.nix):
{
"enabled": 1,
"hidden": false,
"description": "js",
"nixexprinput": "src",
"nixexprpath": "release.nix",
"checkinterval": 300,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 3,
"inputs": {
"src": { "type": "git", "value": "git://github.com/shlevy/declarative-hydra-example.git", "emailresponsible": false },
"nixpkgs": { "type": "git", "value": "git://github.com/NixOS/nixpkgs.git release-16.03", "emailresponsible": false }
}
}
2016-03-11 18:14:58 -05:00
|
|
|
|
my $project = $build->project;
|
|
|
|
|
my $jobset = $build->jobset;
|
|
|
|
|
if (length($project->declfile) && $jobset->name eq ".jobsets" && $build->iscurrent) {
|
|
|
|
|
handleDeclarativeJobsetBuild($db, $project, $build);
|
|
|
|
|
}
|
2015-06-23 00:14:49 +02:00
|
|
|
|
my @dependents;
|
|
|
|
|
foreach my $id (@ARGV) {
|
|
|
|
|
my $dep = $db->resultset('Builds')->find($id)
|
|
|
|
|
or die "build $id does not exist\n";
|
|
|
|
|
push @dependents, $dep;
|
|
|
|
|
}
|
2016-05-27 14:32:48 +02:00
|
|
|
|
|
|
|
|
|
foreach my $plugin (@plugins) {
|
|
|
|
|
eval { $plugin->buildFinished($build, [@dependents]); };
|
|
|
|
|
if ($@) {
|
|
|
|
|
print STDERR "$plugin->buildFinished: $@\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-24 09:45:31 -04:00
|
|
|
|
elsif ($cmd eq "build-queued") {
|
|
|
|
|
foreach my $plugin (@plugins) {
|
|
|
|
|
eval { $plugin->buildQueued($build); };
|
|
|
|
|
if ($@) {
|
|
|
|
|
print STDERR "$plugin->buildQueued: $@\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-27 14:32:48 +02:00
|
|
|
|
elsif ($cmd eq "build-started") {
|
|
|
|
|
foreach my $plugin (@plugins) {
|
|
|
|
|
eval { $plugin->buildStarted($build); };
|
|
|
|
|
if ($@) {
|
|
|
|
|
print STDERR "$plugin->buildStarted: $@\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elsif ($cmd eq "step-finished") {
|
2018-08-01 17:17:46 +02:00
|
|
|
|
die if scalar @ARGV < 2;
|
|
|
|
|
my $stepNr = shift @ARGV;
|
2016-05-27 14:32:48 +02:00
|
|
|
|
my $step = $build->buildsteps->find({stepnr => $stepNr})
|
|
|
|
|
or die "step $stepNr does not exist\n";
|
2018-08-01 17:17:46 +02:00
|
|
|
|
my $logPath = shift @ARGV;
|
|
|
|
|
$logPath = undef if $logPath eq "";
|
2016-05-27 14:32:48 +02:00
|
|
|
|
|
|
|
|
|
foreach my $plugin (@plugins) {
|
|
|
|
|
eval { $plugin->stepFinished($step, $logPath); };
|
|
|
|
|
if ($@) {
|
|
|
|
|
print STDERR "$plugin->stepFinished: $@\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-23 00:14:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
die "unknown action ‘$cmd’";
|
|
|
|
|
}
|