Add flake configuration to the web interface

This commit is contained in:
Eelco Dolstra 2019-05-10 23:39:55 +02:00
parent 6ee6ec3bda
commit f9f595cd21
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
7 changed files with 124 additions and 31 deletions

View file

@ -223,12 +223,19 @@ sub updateJobset {
error($c, "Cannot rename jobset to $jobsetName since that identifier is already taken.") error($c, "Cannot rename jobset to $jobsetName since that identifier is already taken.")
if $jobsetName ne $oldName && defined $c->stash->{project}->jobsets->find({ name => $jobsetName }); if $jobsetName ne $oldName && defined $c->stash->{project}->jobsets->find({ name => $jobsetName });
# When the expression is in a .scm file, assume it's a Guile + Guix my $type = int($c->stash->{params}->{"type"}) // 0;
# build expression.
my $exprType =
$c->stash->{params}->{"nixexprpath"} =~ /.scm$/ ? "guile" : "nix";
my ($nixExprPath, $nixExprInput) = nixExprPathFromParams $c; my ($nixExprPath, $nixExprInput);
my $flake;
if ($type == 0) {
($nixExprPath, $nixExprInput) = nixExprPathFromParams $c;
} elsif ($type == 1) {
$flake = trim($c->stash->{params}->{"flakeref"});
error($c, "Invalid flake URI $flake.") if $flake !~ /^[a-zA-Z]/;
} else {
error($c, "Invalid jobset type.");
}
my $enabled = int($c->stash->{params}->{enabled}); my $enabled = int($c->stash->{params}->{enabled});
die if $enabled < 0 || $enabled > 2; die if $enabled < 0 || $enabled > 2;
@ -251,6 +258,8 @@ sub updateJobset {
, checkinterval => $checkinterval , checkinterval => $checkinterval
, triggertime => ($enabled && $checkinterval > 0) ? $jobset->triggertime // time() : undef , triggertime => ($enabled && $checkinterval > 0) ? $jobset->triggertime // time() : undef
, schedulingshares => $shares , schedulingshares => $shares
, type => $type
, flake => $flake
}); });
$jobset->project->jobsetrenames->search({ from_ => $jobsetName })->delete; $jobset->project->jobsetrenames->search({ from_ => $jobsetName })->delete;
@ -260,6 +269,7 @@ sub updateJobset {
# Set the inputs of this jobset. # Set the inputs of this jobset.
$jobset->jobsetinputs->delete; $jobset->jobsetinputs->delete;
if ($type == 0) {
foreach my $name (keys %{$c->stash->{params}->{inputs}}) { foreach my $name (keys %{$c->stash->{params}->{inputs}}) {
my $inputData = $c->stash->{params}->{inputs}->{$name}; my $inputData = $c->stash->{params}->{inputs}->{$name};
my $type = $inputData->{type}; my $type = $inputData->{type};
@ -279,6 +289,7 @@ sub updateJobset {
$input->jobsetinputalts->create({altnr => 0, value => $value}); $input->jobsetinputalts->create({altnr => 0, value => $value});
} }
} }
}
sub clone : Chained('jobsetChain') PathPart('clone') Args(0) { sub clone : Chained('jobsetChain') PathPart('clone') Args(0) {

View file

@ -191,6 +191,11 @@ __PACKAGE__->table("Builds");
default_value: 0 default_value: 0
is_nullable: 0 is_nullable: 0
=head2 notificationpendingsince
data_type: 'integer'
is_nullable: 1
=cut =cut
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
@ -252,6 +257,8 @@ __PACKAGE__->add_columns(
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"keep", "keep",
{ data_type => "integer", default_value => 0, is_nullable => 0 }, { data_type => "integer", default_value => 0, is_nullable => 0 },
"notificationpendingsince",
{ data_type => "integer", is_nullable => 1 },
); );
=head1 PRIMARY KEY =head1 PRIMARY KEY
@ -537,8 +544,8 @@ __PACKAGE__->many_to_many(
); );
# Created by DBIx::Class::Schema::Loader v0.07043 @ 2016-02-12 17:20:42 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2019-05-10 22:30:12
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:/8aVtXu/+o0jmKHnSzwt+g # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YK8Fc+37UAcL0u6ziOc5xQ
__PACKAGE__->has_many( __PACKAGE__->has_many(
"dependents", "dependents",

View file

@ -56,12 +56,12 @@ __PACKAGE__->table("Jobsets");
data_type: 'text' data_type: 'text'
is_foreign_key: 1 is_foreign_key: 1
is_nullable: 0 is_nullable: 1
=head2 nixexprpath =head2 nixexprpath
data_type: 'text' data_type: 'text'
is_nullable: 0 is_nullable: 1
=head2 errormsg =head2 errormsg
@ -139,6 +139,17 @@ __PACKAGE__->table("Jobsets");
data_type: 'integer' data_type: 'integer'
is_nullable: 1 is_nullable: 1
=head2 type
data_type: 'integer'
default_value: 0
is_nullable: 0
=head2 flake
data_type: 'text'
is_nullable: 1
=cut =cut
__PACKAGE__->add_columns( __PACKAGE__->add_columns(
@ -149,9 +160,9 @@ __PACKAGE__->add_columns(
"description", "description",
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"nixexprinput", "nixexprinput",
{ data_type => "text", is_foreign_key => 1, is_nullable => 0 }, { data_type => "text", is_foreign_key => 1, is_nullable => 1 },
"nixexprpath", "nixexprpath",
{ data_type => "text", is_nullable => 0 }, { data_type => "text", is_nullable => 1 },
"errormsg", "errormsg",
{ data_type => "text", is_nullable => 1 }, { data_type => "text", is_nullable => 1 },
"errortime", "errortime",
@ -180,6 +191,10 @@ __PACKAGE__->add_columns(
{ data_type => "boolean", is_nullable => 1 }, { data_type => "boolean", is_nullable => 1 },
"starttime", "starttime",
{ data_type => "integer", is_nullable => 1 }, { data_type => "integer", is_nullable => 1 },
"type",
{ data_type => "integer", default_value => 0, is_nullable => 0 },
"flake",
{ data_type => "text", is_nullable => 1 },
); );
=head1 PRIMARY KEY =head1 PRIMARY KEY
@ -282,7 +297,12 @@ __PACKAGE__->belongs_to(
"jobsetinput", "jobsetinput",
"Hydra::Schema::JobsetInputs", "Hydra::Schema::JobsetInputs",
{ jobset => "name", name => "nixexprinput", project => "project" }, { jobset => "name", name => "nixexprinput", project => "project" },
{ is_deferrable => 0, on_delete => "NO ACTION", on_update => "NO ACTION" }, {
is_deferrable => 0,
join_type => "LEFT",
on_delete => "NO ACTION",
on_update => "NO ACTION",
},
); );
=head2 jobsetinputs =head2 jobsetinputs
@ -352,8 +372,8 @@ __PACKAGE__->has_many(
); );
# Created by DBIx::Class::Schema::Loader v0.07045 @ 2017-03-09 13:03:05 # Created by DBIx::Class::Schema::Loader v0.07049 @ 2019-05-11 00:03:52
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:ivYvsUyhEeaeI4EmRQ0/QQ # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:UVG1D59bXaQ1TUEF237tXQ
my %hint = ( my %hint = (
columns => [ columns => [

View file

@ -42,7 +42,7 @@
[% END %] [% END %]
[% BLOCK renderJobsetInputs %] [% BLOCK renderJobsetInputs %]
<table class="table table-striped table-condensed"> <table class="table table-striped table-condensed show-on-legacy">
<thead> <thead>
<tr><th></th><th>Input name</th><th>Type</th><th style="width: 50%">Value</th><th>Notify committers</th></tr> <tr><th></th><th>Input name</th><th>Type</th><th style="width: 50%">Value</th><th>Notify committers</th></tr>
</thead> </thead>
@ -96,6 +96,24 @@
</div> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label">Type</label>
<div class="controls">
<div class="btn-group" data-toggle="buttons-radio">
<input type="hidden" id="type" name="type" value="[% jobset.type %]" />
<button type="button" class="btn" value="1" id="type-flake">Flake</button>
<button type="button" class="btn" value="0" id="type-legacy">Legacy</button>
</div>
</div>
</div>
<div class="control-group show-on-flake">
<label class="control-label">Flake URI</label>
<div class="controls">
<input type="text" class="span3" name="flakeref" [% HTML.attributes(value => jobset.flake) %]/>
</div>
</div>
<div class="control-group show-on-legacy">
<label class="control-label">Nix expression</label> <label class="control-label">Nix expression</label>
<div class="controls"> <div class="controls">
<input type="text" class="span3" name="nixexprpath" [% HTML.attributes(value => jobset.nixexprpath) %]/> <input type="text" class="span3" name="nixexprpath" [% HTML.attributes(value => jobset.nixexprpath) %]/>
@ -167,6 +185,21 @@
$(document).ready(function() { $(document).ready(function() {
var id = 0; var id = 0;
function update() {
if ($("#type").val() == 0) {
$(".show-on-legacy").show();
$(".show-on-flake").hide();
} else {
$(".show-on-legacy").hide();
$(".show-on-flake").show();
}
}
$("#type-flake").click(function() { update(); });
$("#type-legacy").click(function() { update(); });
update();
$(".add-input").click(function() { $(".add-input").click(function() {
var newid = "input-" + id++; var newid = "input-" + id++;
var x = $("#input-template").clone(true).attr("id", "").insertBefore($(this).parents("tr")).show(); var x = $("#input-template").clone(true).attr("id", "").insertBefore($(this).parents("tr")).show();

View file

@ -135,6 +135,15 @@
<th>Description:</th> <th>Description:</th>
<td>[% HTML.escape(jobset.description) %]</td> <td>[% HTML.escape(jobset.description) %]</td>
</tr> </tr>
[% IF jobset.type == 1 %]
<tr>
<th>Flake URI:</th>
<td>
<tt>[% HTML.escape(jobset.flake) %]</tt>
</td>
</tr>
[% END %]
[% IF jobset.type == 0 %]
<tr> <tr>
<th>Nix expression:</th> <th>Nix expression:</th>
<td> <td>
@ -142,6 +151,7 @@
<tt>[% HTML.escape(jobset.nixexprinput) %]</tt> <tt>[% HTML.escape(jobset.nixexprinput) %]</tt>
</td> </td>
</tr> </tr>
[% END %]
<tr> <tr>
<th>Check interval:</th> <th>Check interval:</th>
<td>[% jobset.checkinterval || "<em>disabled</em>" %]</td> <td>[% jobset.checkinterval || "<em>disabled</em>" %]</td>
@ -166,7 +176,9 @@
</tr> </tr>
</table> </table>
[% IF jobset.type == 0 %]
[% INCLUDE renderJobsetInputs %] [% INCLUDE renderJobsetInputs %]
[% END %]
</div> </div>
[% INCLUDE makeLazyTab tabName="tabs-jobs" uri=c.uri_for('/jobset' project.name jobset.name "jobs-tab") %] [% INCLUDE makeLazyTab tabName="tabs-jobs" uri=c.uri_for('/jobset' project.name jobset.name "jobs-tab") %]

View file

@ -54,8 +54,8 @@ create table Jobsets (
name text not null, name text not null,
project text not null, project text not null,
description text, description text,
nixExprInput text not null, -- name of the jobsetInput containing the Nix or Guix expression nixExprInput text, -- name of the jobsetInput containing the Nix or Guix expression
nixExprPath text not null, -- relative path of the Nix or Guix expression nixExprPath text, -- relative path of the Nix or Guix expression
errorMsg text, -- used to signal the last evaluation error etc. for this jobset errorMsg text, -- used to signal the last evaluation error etc. for this jobset
errorTime integer, -- timestamp associated with errorMsg errorTime integer, -- timestamp associated with errorMsg
lastCheckedTime integer, -- last time the evaluator looked at this jobset lastCheckedTime integer, -- last time the evaluator looked at this jobset
@ -70,7 +70,11 @@ create table Jobsets (
fetchErrorMsg text, fetchErrorMsg text,
forceEval boolean, forceEval boolean,
startTime integer, -- if jobset is currently running startTime integer, -- if jobset is currently running
type integer not null default 0, -- 0 == legacy, 1 == flake
flake text,
check (schedulingShares > 0), check (schedulingShares > 0),
check ((type = 0) = (nixExprInput is not null and nixExprPath is not null)),
check ((type = 1) = (flake is not null)),
primary key (project, name), primary key (project, name),
foreign key (project) references Projects(name) on delete cascade on update cascade foreign key (project) references Projects(name) on delete cascade on update cascade
#ifdef SQLITE #ifdef SQLITE

6
src/sql/upgrade-57.sql Normal file
View file

@ -0,0 +1,6 @@
alter table Jobsets alter column nixExprInput drop not null;
alter table Jobsets alter column nixExprPath drop not null;
alter table Jobsets add column type integer default 0;
alter table Jobsets add column flake text;
alter table Jobsets add check ((type = 0) = (nixExprInput is not null and nixExprPath is not null));
alter table Jobsets add check ((type = 1) = (flake is not null));