Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the project name to declarative inputs #717

Merged
merged 1 commit into from Mar 8, 2021

Conversation

dasJ
Copy link
Member

@dasJ dasJ commented Feb 18, 2020

This allows for more generic declarative configurations which can be
shared between projects.

@grahamc
Copy link
Member

grahamc commented Sep 3, 2020

I don't really understand what this is changing. Can you give a concrete explanation (docs, maybe, even) of what this enables, which couldn't be done before, and how to use it?

@dasJ
Copy link
Member Author

dasJ commented Sep 3, 2020

@grahamc This makes https://github.com/dasJ/hydra-configs2 work.

Currently, we need one spec JSON for every Hydra project we want to configure from the same repository. This is because the Nix expression that is called in .jobsets cannot differentiate between projects. This is what I did here which inputs the project name into the expression.

However, this PR does so automatically by adding a second input to the .jobsets evaluation: projectName. With this, the .jobsets Nix expression can differentiate between projects without the user having to change the spec JSON, so multiple projects can share one JSON file and the decision on what jobsets are generated and what inputs are used is soley done in nix.
hydra-configs2 allows to do exactly that and can include whatever additional nix code is needed.

@grahamc
Copy link
Member

grahamc commented Sep 3, 2020

Got it. Cool! Can you add some information to that effect around here? https://github.com/NixOS/hydra/blob/master/doc/manual/declarative-projects.xml#L181

@ajs124 ajs124 force-pushed the projectname branch 2 times, most recently from 3afd4b8 to e6ba22b Compare September 13, 2020 17:27
@ajs124
Copy link
Member

ajs124 commented Sep 13, 2020

@grahamc done

@@ -587,6 +587,7 @@ sub checkJobsetWrapped {
updateDeclarativeJobset($db, $project, ".jobsets", $declSpec);
$jobset->discard_changes;
$inputInfo->{"declInput"} = [ $declInput ];
$inputInfo->{"projectName"} = [ fetchInput($plugins, $db, $project, $jobset, "", "string", $project->name, 0) ];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really threw me for a loop why this code is so complicated, but this is just making:

$inputInfo ->{"projectName"} = [ { "value" => $project->name,  } ]

which is used later on by inputsToArgs:

    my $alt = $inputInfo->{$input}->[0];

        if ($alt->{type} eq "string") {
            push @res, "--argstr", $input, $alt->{value};
        }

which is so complicated because of the support for "alternative" inputs, a largely and perhaps totally dead feature.

@grahamc
Copy link
Member

grahamc commented Mar 8, 2021

Can you rebase on master then ping me on IRC when the tests pass?

From e6ba22b96b9bc7b5646fdf3cd454dd8cb54b460d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Janne=20He=C3=9F?= <janne@hess.ooo>
Date: Tue, 18 Feb 2020 02:16:18 +0100
Subject: [PATCH] Add the project name to declarative inputs

This allows for more generic declarative configurations which can be
shared between projects.
---
 doc/manual/declarative-projects.xml | 3 ++-
 src/script/hydra-eval-jobset        | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/doc/manual/declarative-projects.xml b/doc/manual/declarative-projects.xml
index df909a89..8287e011 100644
--- a/doc/manual/declarative-projects.xml
+++ b/doc/manual/declarative-projects.xml
@@ -179,7 +179,8 @@
         file as the jobset configuration for this evaluation. In addition
         to any inputs specified in the spec file, hydra will also pass the
         <literal>declInput</literal> argument corresponding to the input
-        fetched in step 1.
+        fetched in step 1 and the <literal>projectName</literal> argument
+        containing the project's name.
       </para>
     </listitem>
     <listitem>
diff --git a/src/script/hydra-eval-jobset b/src/script/hydra-eval-jobset
index ff76f4ef..3bd53faa 100755
--- a/src/script/hydra-eval-jobset
+++ b/src/script/hydra-eval-jobset
@@ -560,7 +560,7 @@ sub checkJobsetWrapped {
     if ($jobsetsJobset) {
         my @declInputs = fetchInput($plugins, $db, $project, $jobset, "decl", $project->decltype, $project->declvalue, 0);
         my $declInput = @declInputs[0] or die "cannot find the input containing the declarative project specification\n";
-        die "multiple alternatives for the input containing the declarative project specificaiton are not supported\n"
+        die "multiple alternatives for the input containing the declarative project specification are not supported\n"
             if scalar @declInputs != 1;
         my $declFile = $declInput->{storePath} . "/" . $project->declfile;
         my $declText = read_file($declFile)
@@ -587,6 +587,7 @@ sub checkJobsetWrapped {
                 updateDeclarativeJobset($db, $project, ".jobsets", $declSpec);
                 $jobset->discard_changes;
                 $inputInfo->{"declInput"} = [ $declInput ];
+                $inputInfo->{"projectName"} = [ fetchInput($plugins, $db, $project, $jobset, "", "string", $project->name, 0) ];
             }
         } else {
             die "Declarative specification file $declFile is not a dictionary"
-- 
2.28.0

This allows for more generic declarative configurations which can be
shared between projects.
@grahamc
Copy link
Member

grahamc commented Mar 8, 2021

Thanks for rebasing!

@grahamc grahamc merged commit ebf1cd2 into NixOS:master Mar 8, 2021
@ajs124 ajs124 deleted the projectname branch March 8, 2021 20:28
grahamc added a commit to grahamc/hydra that referenced this pull request Mar 16, 2021
```
Mar 10 16:22:35 hydra-b hydra-evaluator[41419]: DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::Pg::st execute failed: ERROR:  null value in column "type" violates not-null constraint
Mar 10 16:22:35 hydra-b hydra-evaluator[41419]: DETAIL:  Failing row contains (62358, projectName, 0, null, null, null, hackworthltd, null, , null). [for Statement "INSERT INTO jobsetevalinputs ( altnr, dependency, eval, name, path, revision, sha256hash, type, uri, value) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )" with ParamValues: 1='0', 2=undef, 3='62358', 4='projectName', 5='', 6=undef, 7=undef, 8=undef, 9=undef, 10='hackworthltd'] at /nix/store/cmqblv437mp57yz5lwvkzcqca4ldf3r5-hydra-0.1.20210308.ebf1cd2/bin/.hydra-eval-jobset-wrapped line 793
Mar 10 16:22:35 hydra-b hydra-evaluator[25828]: evaluation of jobset ‘hackworthltd:.jobsets (jobset#1)’ failed with exit code 1
```

Use the abstraction for creating inputs for simulating the project
name input.

Co-authored-by: Graham Christensen <graham@grahamc.com>
grahamc added a commit that referenced this pull request Mar 16, 2021
Fixup #717 "Add the project name to declarative inputs"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants