From f689fcbef9af6f4f93068756c873b437ec10f456 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Mon, 25 May 2020 14:10:07 -0500 Subject: [PATCH] CI Helper fixes 3 (#11696) --- .travis.yml | 1 + LibreNMS/Util/CiHelper.php | 74 +++++++++++++++----------------------- 2 files changed, 30 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index c04c907d08..70cb07643a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -40,6 +40,7 @@ after_failure: before_script: - phpenv config-rm xdebug.ini - test -n "$SKIP_WEB_CHECK" || php artisan serve --env=dusk.testing 2>/dev/null & + - test -n "$SKIP_UNIT_CHECK" || ~/.local/bin/snmpsimd.py --data-dir=tests/snmpsim --agent-udpv4-endpoint=127.1.6.1:1161 --logging-method=file:/tmp/snmpsimd.log & script: - php artisan dev:check ci diff --git a/LibreNMS/Util/CiHelper.php b/LibreNMS/Util/CiHelper.php index f1e6bd17a0..a9adb03388 100644 --- a/LibreNMS/Util/CiHelper.php +++ b/LibreNMS/Util/CiHelper.php @@ -174,12 +174,10 @@ class CiHelper */ public function checkUnit() { - $phpunit_bin = $this->checkPhpExec('phpunit'); - - $phpunit_cmd = "$phpunit_bin --colors=always"; + $phpunit_cmd = [$this->checkPhpExec('phpunit'), '--colors=always']; if ($this->flags['fail-fast']) { - $phpunit_cmd .= ' --stop-on-error --stop-on-failure'; + array_push($phpunit_cmd, '--stop-on-error', '--stop-on-failure'); } // exclusive tests @@ -187,13 +185,14 @@ class CiHelper echo 'Only checking os: ' . implode(', ', $this->os) . PHP_EOL; $filter = implode('.*|', $this->os); // include tests that don't have data providers and only data sets that match - $phpunit_cmd .= " --group os --filter '/::test[A-Za-z]+$|::test[A-Za-z]+ with data set \"$filter.*\"$/'"; + array_push($phpunit_cmd, '--group', 'os'); + array_push($phpunit_cmd, '--filter', "/::test[A-Za-z]+$|::test[A-Za-z]+ with data set \"$filter .*\"$/"); } elseif ($this->flags['unit_docs']) { - $phpunit_cmd .= " --group docs"; + array_push($phpunit_cmd, '--group', 'docs'); } elseif ($this->flags['unit_svg']) { - $phpunit_cmd .= ' tests/SVGTest.php'; + $phpunit_cmd[] = 'tests/SVGTest.php'; } elseif ($this->flags['unit_modules']) { - $phpunit_cmd .= ' tests/OSModulesTest.php'; + $phpunit_cmd[] = 'tests/OSModulesTest.php'; } return $this->execute('unit', $phpunit_cmd, false, $this->unitEnv); @@ -206,11 +205,17 @@ class CiHelper */ public function checkStyle() { - $phpcs_bin = $this->checkPhpExec('phpcs'); + $cs_cmd = [ + $this->checkPhpExec('phpcs'), + '-n', + '-p', + '--colors', + '--extensions=php', + '--standard=misc/phpcs_librenms.xml' + ]; - $files = $this->flags['full'] ? './' : implode(' ', $this->changed['php']); - - $cs_cmd = "$phpcs_bin -n -p --colors --extensions=php --standard=misc/phpcs_librenms.xml $files"; + $files = $this->flags['full'] ? ['./'] : $this->changed['php']; + $cs_cmd = array_merge($cs_cmd, $files); return $this->execute('style', $cs_cmd); } @@ -240,10 +245,10 @@ class CiHelper } } - $dusk_cmd = "php artisan dusk"; + $dusk_cmd = ['php', 'artisan', 'dusk']; if ($this->flags['fail-fast']) { - $dusk_cmd .= ' --stop-on-error --stop-on-failure'; + array_push($dusk_cmd, '--stop-on-error', '--stop-on-failure'); } return $this->execute('web', $dusk_cmd, false, $this->duskEnv); @@ -258,27 +263,25 @@ class CiHelper { $return = 0; if (!$this->flags['lint_skip_php']) { - $parallel_lint_bin = $this->checkPhpExec('parallel-lint'); + $php_lint_cmd = [$this->checkPhpExec('parallel-lint')]; // matches a substring of the relative path, leading / is treated as absolute path - $lint_excludes = ['vendor/']; - $lint_exclude = $this->buildPhpLintExcludes('--exclude ', $lint_excludes); + array_push($php_lint_cmd, '--exclude', 'vendor/'); - $files = $this->flags['full'] ? './' : implode(' ', $this->changed['php']); - - $php_lint_cmd = "$parallel_lint_bin $lint_exclude $files"; + $files = $this->flags['full'] ? ['./'] : $this->changed['php']; + $php_lint_cmd = array_merge($php_lint_cmd, $files); $return += $this->execute('PHP lint', $php_lint_cmd); } if (!$this->flags['lint_skip_python']) { - $pylint_bin = $this->checkPythonExec('pylint'); + $py_lint_cmd = [$this->checkPythonExec('pylint'), '-E', '-j', '0']; $files = $this->flags['full'] - ? str_replace(PHP_EOL, ' ', rtrim(shell_exec("find . -name '*.py' -not -path './vendor/*' -not -path './tests/*'"))) - : implode(' ', $this->changed['python']); + ? explode(PHP_EOL, rtrim(shell_exec("find . -name '*.py' -not -path './vendor/*' -not -path './tests/*'"))) + : $this->changed['python']; - $py_lint_cmd = "$pylint_bin -E -j 0 $files"; + $py_lint_cmd = array_merge($py_lint_cmd, $files); $return += $this->execute('Python lint', $py_lint_cmd); } @@ -287,9 +290,7 @@ class CiHelper ? explode(PHP_EOL, rtrim(shell_exec("find . -name '*.sh' -not -path './node_modules/*' -not -path './vendor/*'"))) : $this->changed['bash']; - $bash_cmd = implode(' && ', array_map(function ($file) { - return "bash -n $file"; - }, $files)); + $bash_cmd = array_merge(['scripts/bash_lint.sh'], $files); $return += $this->execute('Bash lint', $bash_cmd); } @@ -339,7 +340,7 @@ class CiHelper * Run a check command * * @param string $name name for status output - * @param string|array $command + * @param array $command * @param bool $silence silence the status ouput (still shows error output) * @param array $env environment to set * @return int @@ -501,21 +502,4 @@ class CiHelper echo "You can find more info at http://docs.librenms.org/Developing/Validating-Code/\n"; exit(1); } - - /** - * Build a list of exclude arguments from an array - * - * @param string $exclude_string such as "--exclude" - * @param array $excludes array of directories to exclude - * @return string resulting string - */ - private function buildPhpLintExcludes($exclude_string, $excludes) - { - $result = ''; - foreach ($excludes as $exclude) { - $result .= $exclude_string . $exclude . ' '; - } - - return $result; - } }