From a5fa3fccc3b3535386f010d785711d82a00226dc Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 19 Oct 2021 22:22:58 -0400 Subject: [PATCH 1/6] perlcritic: level 3 --- .perlcriticrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.perlcriticrc b/.perlcriticrc index 9d756697..bfc20693 100644 --- a/.perlcriticrc +++ b/.perlcriticrc @@ -1,4 +1,4 @@ theme = community # 5 is the least complainy, 1 is the most complainy -severity = 4 +severity = 3 From 43c056bb7bd34a3f1012ba41ae3692795e3b5ca2 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 19 Oct 2021 22:38:50 -0400 Subject: [PATCH 2/6] t/TaskDispatcher.t: array / arrayref consistency Also fixes a test which was comparing the length of two lists instead of the values inside the lists. Dang, Perl. --- t/TaskDispatcher.t | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/t/TaskDispatcher.t b/t/TaskDispatcher.t index c055ce45..4bf3e8ed 100644 --- a/t/TaskDispatcher.t +++ b/t/TaskDispatcher.t @@ -87,24 +87,23 @@ sub make_fake_record { subtest "dispatch_event" => sub { subtest "every plugin gets called once, even if it fails all of them." => sub { - my @plugins = [make_noop_plugin("bogus-1"), make_noop_plugin("bogus-2")]; + my $plugins = [make_noop_plugin("bogus-1"), make_noop_plugin("bogus-2")]; - my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, @plugins); + my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, $plugins); my $event = make_failing_event("bogus-channel"); $dispatcher->dispatch_event($event); is(@{$event->{"called_with"}}, 2, "Both plugins should be called"); - my @expected_names = [ "bogus-1", "bogus-2" ]; - my @actual_names = sort([ - $event->{"called_with"}[0]->name, - $event->{"called_with"}[1]->name - ]); - + my @expected_names = ( "bogus-1", "bogus-2" ); + my @actual_names = sort( + $event->{"called_with"}[0]->name, + $event->{"called_with"}[1]->name + ); is( - @actual_names, - @expected_names, + \@actual_names, + \@expected_names, "Both plugins should be executed, but not in any particular order." ); }; @@ -113,9 +112,9 @@ subtest "dispatch_event" => sub { subtest "dispatch_task" => sub { subtest "every plugin gets called once" => sub { my $bogus_plugin = make_noop_plugin("bogus-1"); - my @plugins = [$bogus_plugin, make_noop_plugin("bogus-2")]; + my $plugins = [$bogus_plugin, make_noop_plugin("bogus-2")]; - my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, @plugins); + my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, $plugins); my $event = make_fake_event("bogus-channel"); my $task = Hydra::Task->new($event, ref $bogus_plugin); @@ -132,9 +131,9 @@ subtest "dispatch_task" => sub { subtest "a task with an invalid plugin is not fatal" => sub { my $bogus_plugin = make_noop_plugin("bogus-1"); - my @plugins = [$bogus_plugin, make_noop_plugin("bogus-2")]; + my $plugins = [$bogus_plugin, make_noop_plugin("bogus-2")]; - my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, @plugins); + my $dispatcher = Hydra::TaskDispatcher->new($db, $prometheus, $plugins); my $event = make_fake_event("bogus-channel"); my $task = Hydra::Task->new($event, "this-plugin-does-not-exist"); From 7095d0060893d859358ef308a0c10fa2e2cbd562 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 19 Oct 2021 22:37:17 -0400 Subject: [PATCH 3/6] perlcritic: make all open() calls three-argument Two-argument calls end up parsing the second argument to guess what should happen, three-arg parses ... less? --- src/lib/Hydra/Helper/Nix.pm | 4 ++-- src/lib/Hydra/View/NixClosure.pm | 2 +- src/lib/Hydra/View/NixLog.pm | 8 ++++---- src/lib/Hydra/View/NixNAR.pm | 2 +- t/plugins/gitea.t | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index e76ac18b..00c1c6a7 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -141,7 +141,7 @@ sub registerRoot { my ($path) = @_; my $link = gcRootFor $path; return if -e $link; - open my $root, ">$link" or die "cannot create GC root `$link' to `$path'"; + open(my $root, ">", $link) or die "cannot create GC root `$link' to `$path'"; close $root; } @@ -342,7 +342,7 @@ sub getMachines { for my $machinesFile (@machinesFiles) { next unless -e $machinesFile; - open my $conf, "<$machinesFile" or die; + open(my $conf, "<", $machinesFile) or die; while (my $line = <$conf>) { chomp; s/\#.*$//g; diff --git a/src/lib/Hydra/View/NixClosure.pm b/src/lib/Hydra/View/NixClosure.pm index c157af6b..f1e462d2 100644 --- a/src/lib/Hydra/View/NixClosure.pm +++ b/src/lib/Hydra/View/NixClosure.pm @@ -14,7 +14,7 @@ sub process { my $fh = IO::Handle->new(); - open $fh, "nix-store --export `nix-store -qR @storePaths` | gzip |"; + open($fh, "-|", "nix-store --export `nix-store -qR @storePaths` | gzip"); $c->response->body($fh); diff --git a/src/lib/Hydra/View/NixLog.pm b/src/lib/Hydra/View/NixLog.pm index c2146bd4..7f37ae78 100644 --- a/src/lib/Hydra/View/NixLog.pm +++ b/src/lib/Hydra/View/NixLog.pm @@ -17,13 +17,13 @@ sub process { my $tail = int($c->stash->{tail} // "0"); if ($logPath =~ /\.bz2$/) { - my $doTail = $tail ? " tail -n '$tail' |" : ""; - open $fh, "bzip2 -dc < '$logPath' | $doTail" or die; + my $doTail = $tail ? "| tail -n '$tail'" : ""; + open($fh, "-|", "bzip2 -dc < '$logPath' $doTail") or die; } else { if ($tail) { - open $fh, "tail -n '$tail' '$logPath' |" or die; + open($fh, "-|", "tail -n '$tail' '$logPath'") or die; } else { - open $fh, "<$logPath" or die; + open($fh, "<", $logPath) or die; } } binmode($fh); diff --git a/src/lib/Hydra/View/NixNAR.pm b/src/lib/Hydra/View/NixNAR.pm index cae43275..a3b85818 100644 --- a/src/lib/Hydra/View/NixNAR.pm +++ b/src/lib/Hydra/View/NixNAR.pm @@ -16,7 +16,7 @@ sub process { my $fh = IO::Handle->new(); - open $fh, "nix-store --dump '$storePath' | pixz -0 $pParam |"; + open($fh, "-|", "nix-store --dump '$storePath' | pixz -0 $pParam"); setCacheHeaders($c, 365 * 24 * 60 * 60); diff --git a/t/plugins/gitea.t b/t/plugins/gitea.t index 8180d5b3..9fc7d213 100644 --- a/t/plugins/gitea.t +++ b/t/plugins/gitea.t @@ -60,7 +60,7 @@ if (!defined($pid = fork())) { kill('INT', $pid); } -open my $fh, $filename or die ("Can't open(): $!\n"); +open(my $fh, "<", $filename) or die ("Can't open(): $!\n"); my $i = 0; my $uri = <$fh>; my $data = <$fh>; From c317ab0dbe9cdb2c87e4aa04139c488be0bf3eb7 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 20 Oct 2021 11:25:55 -0400 Subject: [PATCH 4/6] shell: add pixz so NAR serving works from foreman --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 1982e8b9..b723382b 100644 --- a/flake.nix +++ b/flake.nix @@ -499,7 +499,7 @@ buildInputs = [ makeWrapper autoconf automake libtool unzip nukeReferences pkgconfig libpqxx gitAndTools.topGit mercurial darcs subversion breezy openssl bzip2 libxslt - final.nix perlDeps perl mdbook + final.nix perlDeps perl mdbook pixz boost postgresql_11 (if lib.versionAtLeast lib.version "20.03pre" From d98d74fa4f667a41456d691fdc8ed46512128a84 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 20 Oct 2021 11:33:50 -0400 Subject: [PATCH 5/6] perlcritic: doesn't like prototypes --- src/lib/Hydra/Helper/Nix.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 00c1c6a7..3881acbc 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -488,7 +488,7 @@ sub getTotalShares { } -sub cancelBuilds($$) { +sub cancelBuilds { my ($db, $builds) = @_; return $db->txn_do(sub { $builds = $builds->search({ finished => 0 }); @@ -505,7 +505,7 @@ sub cancelBuilds($$) { } -sub restartBuilds($$) { +sub restartBuilds { my ($db, $builds) = @_; $builds = $builds->search({ finished => 1 }); From 5285d0b6cb3d9b99bb14509a44cacd8ecd91267d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Wed, 20 Oct 2021 12:56:02 -0400 Subject: [PATCH 6/6] gittea test: prune trailing space --- t/plugins/gitea.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/plugins/gitea.t b/t/plugins/gitea.t index 9fc7d213..56601b95 100644 --- a/t/plugins/gitea.t +++ b/t/plugins/gitea.t @@ -41,7 +41,7 @@ updateRepository('gitea', "$ctx{testdir}/jobs/git-update.sh", $scratch); ok(evalSucceeds($jobset), "Evaluating nix expression"); is(nrQueuedBuildsForJobset($jobset), 1, "Evaluating jobs/runcommand.nix should result in 1 build1"); - + (my $build) = queuedBuildsForJobset($jobset); ok(runBuild($build), "Build should succeed with exit code 0");