mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Run phpstan locally with lnms dev:check lint (#13458)
* Run phpstan locally with `lnms dev:check lint` Separate result cache for deprecated functions so we don't break the cache every time. * Skip phpstan flag Skip all lints on ci except php lint (so we can check on multiple php versions) * forgot default value * fix up test cases * Update LibreNMS/Util/CiHelper.php Co-authored-by: Jellyfrog <Jellyfrog@users.noreply.github.com> Co-authored-by: Jellyfrog <Jellyfrog@users.noreply.github.com>
This commit is contained in:
@@ -59,6 +59,7 @@ class CiHelper
|
||||
'unit_skip' => false,
|
||||
'web_skip' => false,
|
||||
'lint_skip_php' => false,
|
||||
'lint_skip_phpstan' => false,
|
||||
'lint_skip_python' => false,
|
||||
'lint_skip_bash' => false,
|
||||
'unit_os' => false,
|
||||
@@ -273,6 +274,12 @@ class CiHelper
|
||||
$php_lint_cmd = array_merge($php_lint_cmd, $files);
|
||||
|
||||
$return += $this->execute('PHP lint', $php_lint_cmd);
|
||||
|
||||
if (! $this->flags['lint_skip_phpstan']) {
|
||||
$phpstan_cmd = [$this->checkPhpExec('phpstan'), 'analyze', '--no-interaction', '--memory-limit=2G'];
|
||||
$return += $this->execute('PHPStan Deprecated', $phpstan_cmd + ['--configuration=phpstan-deprecated.neon']);
|
||||
$return += $this->execute('PHPStan', $phpstan_cmd);
|
||||
}
|
||||
}
|
||||
|
||||
if (! $this->flags['lint_skip_python']) {
|
||||
@@ -425,6 +432,7 @@ class CiHelper
|
||||
|
||||
$this->setFlags([
|
||||
'lint_skip_php' => empty($this->changed['php']),
|
||||
'lint_skip_phpstan' => empty($this->changed['php']),
|
||||
'lint_skip_python' => empty($this->changed['python']),
|
||||
'lint_skip_bash' => empty($this->changed['bash']),
|
||||
'unit_os' => $this->getFlag('unit_os') || (! empty($this->changed['os']) && empty(array_diff($this->changed['php'], $this->changed['os-files']))),
|
||||
@@ -435,7 +443,7 @@ class CiHelper
|
||||
|
||||
$this->setFlags([
|
||||
'unit_skip' => empty($this->changed['php']) && ! array_sum(Arr::only($this->getFlags(), ['unit_os', 'unit_docs', 'unit_svg', 'unit_modules', 'docs_changed'])),
|
||||
'lint_skip' => array_sum(Arr::only($this->getFlags(), ['lint_skip_php', 'lint_skip_python', 'lint_skip_bash'])) === 3,
|
||||
'lint_skip' => array_sum(Arr::only($this->getFlags(), ['lint_skip_php', 'lint_skip_phpstan', 'lint_skip_python', 'lint_skip_bash'])) === 4,
|
||||
'style_skip' => ! $this->flags['ci'] && empty($this->changed['php']),
|
||||
'web_skip' => empty($this->changed['php']) && empty($this->changed['resources']),
|
||||
]);
|
||||
|
||||
@@ -100,7 +100,14 @@ class DevCheckCommand extends LnmsCommand
|
||||
}
|
||||
|
||||
if ($check == 'ci') {
|
||||
$this->helper->setFlags(['ci' => true, 'fail-fast' => true]);
|
||||
$this->helper->setFlags([
|
||||
'ci' => true,
|
||||
'fail-fast' => true,
|
||||
// checked in lint workflow
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
$this->helper->duskHeadless();
|
||||
$this->helper->enableSnmpsim();
|
||||
$this->helper->enableDb();
|
||||
|
||||
@@ -6,6 +6,7 @@ parameters:
|
||||
|
||||
customRulesetUsed: true
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
resultCachePath: %tmpDir%/resultCache-deprecated.php
|
||||
|
||||
paths:
|
||||
- LibreNMS
|
||||
|
||||
@@ -72,6 +72,7 @@ class CiHelperTest extends TestCase
|
||||
'unit_skip' => true,
|
||||
'web_skip' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -95,6 +96,7 @@ class CiHelperTest extends TestCase
|
||||
'web_skip' => true,
|
||||
'unit_os' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -108,6 +110,7 @@ class CiHelperTest extends TestCase
|
||||
'web_skip' => true,
|
||||
'unit_os' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -131,6 +134,7 @@ class CiHelperTest extends TestCase
|
||||
'web_skip' => true,
|
||||
'unit_modules' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -147,6 +151,7 @@ class CiHelperTest extends TestCase
|
||||
'unit_os' => true,
|
||||
'unit_modules' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -160,6 +165,7 @@ class CiHelperTest extends TestCase
|
||||
'web_skip' => true,
|
||||
'unit_os' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -173,6 +179,7 @@ class CiHelperTest extends TestCase
|
||||
'web_skip' => true,
|
||||
'unit_os' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
]);
|
||||
@@ -204,6 +211,7 @@ class CiHelperTest extends TestCase
|
||||
'unit_skip' => true,
|
||||
'web_skip' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
]);
|
||||
|
||||
putenv('FILES=includes/polling/sensors/ios.inc.php');
|
||||
@@ -223,6 +231,7 @@ class CiHelperTest extends TestCase
|
||||
'style_skip' => true,
|
||||
'web_skip' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
'unit_svg' => true,
|
||||
@@ -236,6 +245,7 @@ class CiHelperTest extends TestCase
|
||||
'style_skip' => true,
|
||||
'web_skip' => true,
|
||||
'lint_skip_php' => true,
|
||||
'lint_skip_phpstan' => true,
|
||||
'lint_skip_python' => true,
|
||||
'lint_skip_bash' => true,
|
||||
'unit_svg' => true,
|
||||
@@ -272,6 +282,7 @@ class CiHelperTest extends TestCase
|
||||
'unit_skip' => false,
|
||||
'web_skip' => false,
|
||||
'lint_skip_php' => false,
|
||||
'lint_skip_phpstan' => false,
|
||||
'lint_skip_python' => false,
|
||||
'lint_skip_bash' => false,
|
||||
'unit_os' => false,
|
||||
|
||||
Reference in New Issue
Block a user