From 194eda28b7fadeb5165fb70078264188078b4f6d Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 18 Aug 2021 14:06:48 -0400 Subject: [PATCH 1/4] flake.nix sort hydra-perl-deps inputs --- flake.nix | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index 9ee5b87e..24acc654 100644 --- a/flake.nix +++ b/flake.nix @@ -363,7 +363,7 @@ perlDeps = buildEnv { name = "hydra-perl-deps"; paths = with perlPackages; lib.closePropagation - [ ModulePluggable + [ AuthenSASL CatalystActionREST CatalystAuthenticationStoreDBIxClass @@ -382,20 +382,22 @@ CatalystViewDownload CatalystViewJSON CatalystViewTT - CatalystXScriptServerStarman CatalystXRoleApplicator + CatalystXScriptServerStarman CryptPassphrase CryptPassphraseArgon2 CryptRandPasswd - DBDPg - DBDSQLite DataDump DateTime + DBDPg + DBDSQLite DigestSHA1 EmailMIME EmailSender FileSlurp FileWhich + final.nix.perl-bindings + git IOCompress IPCRun JSON @@ -403,27 +405,26 @@ JSONXS LWP LWPProtocolHttps + ModulePluggable NetAmazonS3 NetPrometheus NetStatsd PadWalker PrometheusTinyShared Readonly - SQLSplitStatement SetScalar + SQLSplitStatement Starman StringCompareConstantTime SysHostnameLong TermSizeAny + Test2Harness TestMore TestPostgreSQL TextDiff - Test2Harness TextTable XMLSimple YAML - final.nix.perl-bindings - git ]; }; From 098e48d0551e765becd09225171cdb4fd205aeb9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Aug 2021 15:55:52 -0400 Subject: [PATCH 2/4] Flake: add perlcritic deps --- flake.nix | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/flake.nix b/flake.nix index 24acc654..616fa81c 100644 --- a/flake.nix +++ b/flake.nix @@ -345,6 +345,66 @@ }; }; + PerlCriticCommunity = prev.perlPackages.buildPerlModule { + pname = "Perl-Critic-Community"; + version = "1.0.0"; + src = final.fetchurl { + url = "mirror://cpan/authors/id/D/DB/DBOOK/Perl-Critic-Community-v1.0.0.tar.gz"; + sha256 = "311b775da4193e9de94cf5225e993cc54dd096ae1e7ef60738cdae1d9b8854e7"; + }; + buildInputs = with final.perlPackages; [ ModuleBuildTiny ]; + propagatedBuildInputs = with final.perlPackages; [ PPI PathTiny PerlCritic PerlCriticPolicyVariablesProhibitLoopOnHash PerlCriticPulp ]; + meta = { + homepage = "https://github.com/Grinnz/Perl-Critic-Freenode"; + description = "Community-inspired Perl::Critic policies"; + license = final.lib.licenses.artistic2; + }; + }; + + PerlCriticPolicyVariablesProhibitLoopOnHash = prev.perlPackages.buildPerlPackage { + pname = "Perl-Critic-Policy-Variables-ProhibitLoopOnHash"; + version = "0.008"; + src = final.fetchurl { + url = "mirror://cpan/authors/id/X/XS/XSAWYERX/Perl-Critic-Policy-Variables-ProhibitLoopOnHash-0.008.tar.gz"; + sha256 = "12f5f0be96ea1bdc7828058577bd1c5c63ca23c17fac9c3709452b3dff5b84e0"; + }; + propagatedBuildInputs = with final.perlPackages; [ PerlCritic ]; + meta = { + description = "Don't write loops on hashes, only on keys and values of hashes"; + license = with final.lib.licenses; [ artistic1 gpl1Plus ]; + }; + }; + + PerlCriticPulp = prev.perlPackages.buildPerlPackage { + pname = "Perl-Critic-Pulp"; + version = "99"; + src = final.fetchurl { + url = "mirror://cpan/authors/id/K/KR/KRYDE/Perl-Critic-Pulp-99.tar.gz"; + sha256 = "b8fda842fcbed74d210257c0a284b6dc7b1d0554a47a3de5d97e7d542e23e7fe"; + }; + propagatedBuildInputs = with final.perlPackages; [ IOString ListMoreUtils PPI PerlCritic PodMinimumVersion ]; + meta = { + homepage = "http://user42.tuxfamily.org/perl-critic-pulp/index.html"; + description = "Some add-on policies for Perl::Critic"; + license = final.lib.licenses.gpl3Plus; + }; + }; + + PodMinimumVersion = prev.perlPackages.buildPerlPackage { + pname = "Pod-MinimumVersion"; + version = "50"; + src = final.fetchurl { + url = "mirror://cpan/authors/id/K/KR/KRYDE/Pod-MinimumVersion-50.tar.gz"; + sha256 = "0bd2812d9aacbd99bb71fa103a4bb129e955c138ba7598734207dc9fb67b5a6f"; + }; + propagatedBuildInputs = with final.perlPackages; [ IOString PodParser ]; + meta = { + homepage = "http://user42.tuxfamily.org/pod-minimumversion/index.html"; + description = "Determine minimum Perl version of POD directives"; + license = final.lib.licenses.free; + }; + }; + StringCompareConstantTime = final.buildPerlPackage { pname = "String-Compare-ConstantTime"; version = "0.321"; @@ -410,6 +470,7 @@ NetPrometheus NetStatsd PadWalker + PerlCriticCommunity PrometheusTinyShared Readonly SetScalar From 241985fb2d1b8338396067063b4902ae996b3141 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Aug 2021 16:13:45 -0400 Subject: [PATCH 3/4] Start checking PRs with perlcritic --- .perlcriticrc | 4 ++++ README.md | 24 ++++++++++++++++++++---- t/Makefile.am | 1 + t/perlcritic.pl | 13 +++++++++++++ 4 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 .perlcriticrc create mode 100755 t/perlcritic.pl diff --git a/.perlcriticrc b/.perlcriticrc new file mode 100644 index 00000000..ddddcada --- /dev/null +++ b/.perlcriticrc @@ -0,0 +1,4 @@ +theme = community + +# 5 is the least complainy, 1 is the most complainy +severity = 5 diff --git a/README.md b/README.md index 8156f22f..e1c2725c 100644 --- a/README.md +++ b/README.md @@ -106,17 +106,33 @@ conflicts with services that might be running on your host, hydra and postgress Note that this is only ever meant as an ad-hoc way of executing Hydra during development. Please make use of the NixOS module for actually running Hydra in production. -### Running Tests +### Checking your patches -After making your changes, verify the test suite still passes. After following the steps in [Development Environment](#development-environment), run: +After making your changes, verify the test suite passes and perlcritic is still happy. + +Start by following the steps in [Development Environment](#development-environment). + +Then, you can run the tests and the perlcritic linter together with: + +```console +$ nix-shell +$ make check +``` + +You can run a single test with: ``` $ nix-shell -$ make check -$ # Or, to run a single test, use: $ yath test ./t/foo/bar.t ``` +And you can run just perlcritic with: + +``` +$ nix-shell +$ make perlcritic +``` + ### JSON API You can also interface with Hydra through a JSON API. The API is defined in [hydra-api.yaml](./hydra-api.yaml) and you can test and explore via the [swagger editor](https://editor.swagger.io/?url=https://raw.githubusercontent.com/NixOS/hydra/master/hydra-api.yaml) diff --git a/t/Makefile.am b/t/Makefile.am index b8448fe8..9c14c1e3 100644 --- a/t/Makefile.am +++ b/t/Makefile.am @@ -23,6 +23,7 @@ EXTRA_DIST = \ $(TESTS) TESTS = \ + perlcritic.pl \ test.pl check_SCRIPTS = repos diff --git a/t/perlcritic.pl b/t/perlcritic.pl new file mode 100755 index 00000000..2477fe21 --- /dev/null +++ b/t/perlcritic.pl @@ -0,0 +1,13 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use Cwd 'abs_path'; +use File::Basename; + +my $dirname = abs_path(dirname(__FILE__) . "/.."); + +print STDERR "Executing perlcritic against $dirname\n"; +chdir($dirname) or die "Failed to enter $dirname\n"; + +exec("perlcritic", ".") or die "Failed to execute perlcritic."; From 4632132d02064c3e6d2f5cd29e28e1f06e368f6d Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 19 Aug 2021 16:25:21 -0400 Subject: [PATCH 4/4] fixup perlcritic: indirect new > Subroutine new called using indirect syntax at line 14, column 14. See page 349 of PBP. (Severity: 5) --- src/lib/Hydra/Controller/User.pm | 4 ++-- src/lib/Hydra/Helper/Nix.pm | 2 +- src/lib/Hydra/View/NixClosure.pm | 2 +- src/lib/Hydra/View/NixLog.pm | 2 +- src/lib/Hydra/View/NixNAR.pm | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/Hydra/Controller/User.pm b/src/lib/Hydra/Controller/User.pm index 49c49c84..852dd16d 100644 --- a/src/lib/Hydra/Controller/User.pm +++ b/src/lib/Hydra/Controller/User.pm @@ -143,7 +143,7 @@ sub google_login :Path('/google-login') Args(0) { error($c, "Logging in via Google is not enabled.") unless $c->config->{enable_google_login}; - my $ua = new LWP::UserAgent; + my $ua = LWP::UserAgent->new(); my $response = $ua->post( 'https://www.googleapis.com/oauth2/v3/tokeninfo', { id_token => ($c->stash->{params}->{id_token} // die "No token."), @@ -171,7 +171,7 @@ sub github_login :Path('/github-login') Args(0) { }; die "No github secret configured" unless $client_secret; - my $ua = new LWP::UserAgent; + my $ua = LWP::UserAgent->new(); my $response = $ua->post( 'https://github.com/login/oauth/access_token', { diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 5e055e4f..7ab4ab60 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -44,7 +44,7 @@ sub getHydraConfig { my $conf = $ENV{"HYDRA_CONFIG"} || (Hydra::Model::DB::getHydraPath . "/hydra.conf"); my %opts = (%Hydra::Config::configGeneralOpts, -ConfigFile => $conf); if (-f $conf) { - my %h = new Config::General(%opts)->getall; + my %h = Config::General->new(%opts)->getall; $hydraConfig = \%h; } else { diff --git a/src/lib/Hydra/View/NixClosure.pm b/src/lib/Hydra/View/NixClosure.pm index 51376699..d906dce3 100644 --- a/src/lib/Hydra/View/NixClosure.pm +++ b/src/lib/Hydra/View/NixClosure.pm @@ -11,7 +11,7 @@ sub process { my @storePaths = @{$c->stash->{storePaths}}; - my $fh = new IO::Handle; + my $fh = IO::Handle->new(); open $fh, "nix-store --export `nix-store -qR @storePaths` | gzip |"; diff --git a/src/lib/Hydra/View/NixLog.pm b/src/lib/Hydra/View/NixLog.pm index 8103726d..fb9e0e1f 100644 --- a/src/lib/Hydra/View/NixLog.pm +++ b/src/lib/Hydra/View/NixLog.pm @@ -11,7 +11,7 @@ sub process { $c->response->content_type('text/plain; charset=utf-8'); - my $fh = new IO::Handle; + my $fh = IO::Handle->new(); my $tail = int($c->stash->{tail} // "0"); diff --git a/src/lib/Hydra/View/NixNAR.pm b/src/lib/Hydra/View/NixNAR.pm index 350ee8e9..e1798275 100644 --- a/src/lib/Hydra/View/NixNAR.pm +++ b/src/lib/Hydra/View/NixNAR.pm @@ -13,7 +13,7 @@ sub process { $c->response->content_type('application/x-nix-archive'); # !!! check MIME type - my $fh = new IO::Handle; + my $fh = IO::Handle->new(); open $fh, "nix-store --dump '$storePath' | pixz -0 $pParam |";