forked from lix-project/hydra
Merge pull request #1118 from DeterminateSystems/project-jobset/declarativejobsets
Project jobset: Update DeclarativeJobsets to not use the project or jobsets columns on Bulids
This commit is contained in:
commit
f1a608ac35
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -33,6 +33,7 @@ Makefile.in
|
||||||
/t/nix
|
/t/nix
|
||||||
/t/data
|
/t/data
|
||||||
/t/jobs/config.nix
|
/t/jobs/config.nix
|
||||||
|
t/jobs/declarative/project.json
|
||||||
/inst
|
/inst
|
||||||
hydra-config.h
|
hydra-config.h
|
||||||
hydra-config.h.in
|
hydra-config.h.in
|
||||||
|
|
|
@ -43,7 +43,7 @@ then
|
||||||
NIX_STATE_DIR="$TMPDIR"
|
NIX_STATE_DIR="$TMPDIR"
|
||||||
export NIX_STATE_DIR
|
export NIX_STATE_DIR
|
||||||
fi
|
fi
|
||||||
if NIX_REMOTE=daemon PAGER=cat "$NIX_STORE_PROGRAM" --timeout 123 -q; then
|
if NIX_REMOTE=daemon PAGER=cat "$NIX_STORE_PROGRAM" --timeout 123 -q; then
|
||||||
AC_MSG_RESULT([yes])
|
AC_MSG_RESULT([yes])
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT([no])
|
AC_MSG_RESULT([no])
|
||||||
|
@ -55,6 +55,9 @@ PKG_CHECK_MODULES([NIX], [nix-main nix-expr nix-store])
|
||||||
testPath="$(dirname $(type -p expr))"
|
testPath="$(dirname $(type -p expr))"
|
||||||
AC_SUBST(testPath)
|
AC_SUBST(testPath)
|
||||||
|
|
||||||
|
jobsPath="$(realpath ./t/jobs)"
|
||||||
|
AC_SUBST(jobsPath)
|
||||||
|
|
||||||
CXXFLAGS+=" -include nix/config.h"
|
CXXFLAGS+=" -include nix/config.h"
|
||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
|
@ -72,6 +75,7 @@ AC_CONFIG_FILES([
|
||||||
src/script/Makefile
|
src/script/Makefile
|
||||||
t/Makefile
|
t/Makefile
|
||||||
t/jobs/config.nix
|
t/jobs/config.nix
|
||||||
|
t/jobs/declarative/project.json
|
||||||
])
|
])
|
||||||
|
|
||||||
AC_CONFIG_COMMANDS([executable-scripts], [])
|
AC_CONFIG_COMMANDS([executable-scripts], [])
|
||||||
|
|
|
@ -162,6 +162,8 @@ sub updateProject {
|
||||||
, declvalue => trim($c->stash->{params}->{declarative}->{value})
|
, declvalue => trim($c->stash->{params}->{declarative}->{value})
|
||||||
});
|
});
|
||||||
if (length($project->declfile)) {
|
if (length($project->declfile)) {
|
||||||
|
# This logic also exists in the DeclarativeJobets tests.
|
||||||
|
# TODO: refactor and deduplicate.
|
||||||
$project->jobsets->update_or_create(
|
$project->jobsets->update_or_create(
|
||||||
{ name=> ".jobsets"
|
{ name=> ".jobsets"
|
||||||
, nixexprinput => ""
|
, nixexprinput => ""
|
||||||
|
|
|
@ -9,7 +9,7 @@ sub buildFinished {
|
||||||
my ($self, $build, $dependents) = @_;
|
my ($self, $build, $dependents) = @_;
|
||||||
|
|
||||||
my $project = $build->project;
|
my $project = $build->project;
|
||||||
my $jobsetName = $build->get_column('jobset');
|
my $jobsetName = $build->jobset->get_column('name');
|
||||||
if (length($project->declfile) && $jobsetName eq ".jobsets" && $build->iscurrent) {
|
if (length($project->declfile) && $jobsetName eq ".jobsets" && $build->iscurrent) {
|
||||||
handleDeclarativeJobsetBuild($self->{"db"}, $project, $build);
|
handleDeclarativeJobsetBuild($self->{"db"}, $project, $build);
|
||||||
}
|
}
|
||||||
|
|
63
t/Hydra/Plugin/DeclarativeJobsets/basic.t
Normal file
63
t/Hydra/Plugin/DeclarativeJobsets/basic.t
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
use feature 'unicode_strings';
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Test2::V0;
|
||||||
|
use Setup;
|
||||||
|
|
||||||
|
my $ctx = test_context();
|
||||||
|
my $db = $ctx->db;
|
||||||
|
|
||||||
|
my $project = $db->resultset('Projects')->create({
|
||||||
|
name => "tests",
|
||||||
|
displayname => "",
|
||||||
|
owner => "root",
|
||||||
|
declfile => "declarative/project.json",
|
||||||
|
decltype => "path",
|
||||||
|
declvalue => $ctx->jobsdir,
|
||||||
|
});
|
||||||
|
|
||||||
|
subtest "Evaluating and building the top .jobsets jobset" => sub {
|
||||||
|
# This logic lives in the Project controller.
|
||||||
|
# Not great to duplicate it here.
|
||||||
|
# TODO: refactor and deduplicate.
|
||||||
|
my $jobset = $project->jobsets->create({
|
||||||
|
name=> ".jobsets",
|
||||||
|
nixexprinput => "",
|
||||||
|
nixexprpath => "",
|
||||||
|
emailoverride => "",
|
||||||
|
triggertime => time,
|
||||||
|
});
|
||||||
|
|
||||||
|
ok(evalSucceeds($jobset), "Evaluating the declarative jobsets with return code 0");
|
||||||
|
is(nrQueuedBuildsForJobset($jobset), 1, "We should have exactly 1 build queued, to build the jobsets data");
|
||||||
|
|
||||||
|
(my $build) = queuedBuildsForJobset($jobset);
|
||||||
|
|
||||||
|
is($build->job, "jobsets", "The only job should be jobsets");
|
||||||
|
ok(runBuild($build), "Build should exit with return code 0");
|
||||||
|
my $newbuild = $db->resultset('Builds')->find($build->id);
|
||||||
|
is($newbuild->finished, 1, "Build should be finished.");
|
||||||
|
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
|
||||||
|
|
||||||
|
ok(sendNotifications(), "Notifications execute successfully.");
|
||||||
|
};
|
||||||
|
|
||||||
|
subtest "Validating a new jobset appears" => sub {
|
||||||
|
my $jobset = $project->jobsets->find({ name => "my-jobset" });
|
||||||
|
ok($jobset, "We have a jobset");
|
||||||
|
is($jobset->description, "my-declarative-jobset", "The jobset's description matches");
|
||||||
|
|
||||||
|
subtest "Evaluating and building that jobset works" => sub {
|
||||||
|
ok(evalSucceeds($jobset), "Evaluating the new jobset with return code 0");
|
||||||
|
is(nrQueuedBuildsForJobset($jobset), 1, "We should have exactly 1 build queued");
|
||||||
|
|
||||||
|
(my $build) = queuedBuildsForJobset($jobset);
|
||||||
|
|
||||||
|
is($build->job, "one_job", "The only job should be jobsets");
|
||||||
|
ok(runBuild($build), "Build should exit with return code 0");
|
||||||
|
my $newbuild = $db->resultset('Builds')->find($build->id);
|
||||||
|
is($newbuild->finished, 1, "Build should be finished.");
|
||||||
|
is($newbuild->buildstatus, 0, "Build should have buildstatus 0.");
|
||||||
|
};
|
||||||
|
};
|
||||||
|
done_testing;
|
29
t/jobs/declarative/generator.nix
Normal file
29
t/jobs/declarative/generator.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{ jobspath, ... }:
|
||||||
|
with import ../config.nix;
|
||||||
|
{
|
||||||
|
jobsets = mkDerivation {
|
||||||
|
name = "jobsets";
|
||||||
|
builder = ./generator.sh;
|
||||||
|
jobsets = builtins.toJSON {
|
||||||
|
my-jobset = {
|
||||||
|
enabled = 1;
|
||||||
|
hidden = false;
|
||||||
|
description = "my-declarative-jobset";
|
||||||
|
nixexprinput = "src";
|
||||||
|
nixexprpath = "one-job.nix";
|
||||||
|
checkinterval = 300;
|
||||||
|
schedulingshares = 100;
|
||||||
|
enableemail = false;
|
||||||
|
emailoverride = "";
|
||||||
|
keepnr = 3;
|
||||||
|
inputs = {
|
||||||
|
src = {
|
||||||
|
type = "path";
|
||||||
|
value = jobspath;
|
||||||
|
emailresponsible = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
3
t/jobs/declarative/generator.sh
Executable file
3
t/jobs/declarative/generator.sh
Executable file
|
@ -0,0 +1,3 @@
|
||||||
|
#! /bin/sh
|
||||||
|
|
||||||
|
echo "$jobsets" > $out
|
24
t/jobs/declarative/project.json.in
Normal file
24
t/jobs/declarative/project.json.in
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
{
|
||||||
|
"enabled": 1,
|
||||||
|
"hidden": false,
|
||||||
|
"description": "declarative-jobset-example",
|
||||||
|
"nixexprinput": "src",
|
||||||
|
"nixexprpath": "declarative/generator.nix",
|
||||||
|
"checkinterval": 300,
|
||||||
|
"schedulingshares": 100,
|
||||||
|
"enableemail": false,
|
||||||
|
"emailoverride": "",
|
||||||
|
"keepnr": 3,
|
||||||
|
"inputs": {
|
||||||
|
"src": {
|
||||||
|
"type": "path",
|
||||||
|
"value": "@jobsPath@",
|
||||||
|
"emailresponsible": false
|
||||||
|
},
|
||||||
|
"jobspath": {
|
||||||
|
"type": "string",
|
||||||
|
"value": "@jobsPath@",
|
||||||
|
"emailresponsible": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue