diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 99c93f2..2449410 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -28,6 +28,7 @@ jobs: php-version: ${{ fromJson(needs.setup.outputs.php-versions) }} tool: ${{ fromJson(needs.setup.outputs.tools) }} fail-fast: false + name: ${{ matrix.php-version }} - ${{ matrix.tool }} steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 diff --git a/src/Command/CodesnifferCommand.php b/src/Command/CodesnifferCommand.php index 09371ac..76bea11 100644 --- a/src/Command/CodesnifferCommand.php +++ b/src/Command/CodesnifferCommand.php @@ -19,13 +19,20 @@ protected function getProcess(InputInterface $input): Process { if ($this->isGitHubFormat($input)) { return Process::fromShellCommandline( - $this->withVendorBinPath('phpcs') . ' -q --report=checkstyle | cs2pr', + \sprintf( + '%s -q --parallel=%s --report=checkstyle | cs2pr', + $this->withVendorBinPath('phpcs'), + $this->configuration->getThreads(), + ), timeout: null, ); } return new Process( - [$this->withVendorBinPath('phpcs')], + [ + $this->withVendorBinPath('phpcs'), + '--parallel=' . $this->configuration->getThreads(), + ], timeout: null, ); } diff --git a/src/Command/PsalmCommand.php b/src/Command/PsalmCommand.php index 1a5c6fa..1fe1b17 100644 --- a/src/Command/PsalmCommand.php +++ b/src/Command/PsalmCommand.php @@ -17,7 +17,10 @@ final class PsalmCommand extends DevToolsCommand protected function getProcess(InputInterface $input): Process { - $command = [$this->withVendorBinPath('psalm')]; + $command = [ + $this->withVendorBinPath('psalm'), + '--threads=' . $this->configuration->getThreads(), + ]; if ($this->isGitHubFormat($input)) { $command[] = '--output-format=github'; diff --git a/src/Command/RoaveInfectionCommand.php b/src/Command/RoaveInfectionCommand.php index 7e4f596..6f5f8fd 100644 --- a/src/Command/RoaveInfectionCommand.php +++ b/src/Command/RoaveInfectionCommand.php @@ -17,15 +17,18 @@ final class RoaveInfectionCommand extends DevToolsCommand protected function getProcess(InputInterface $input): Process { - return new Process( - [ - $this->withVendorBinPath('roave-infection-static-analysis-plugin'), - '--only-covered', - '--show-mutations', - ], - env: ['XDEBUG_MODE' => 'coverage'], - timeout: null, - ); + $command = [ + $this->withVendorBinPath('roave-infection-static-analysis-plugin'), + '--threads=' . $this->configuration->getThreads(), + '--only-covered', + '--show-mutations', + ]; + + if ($this->isGitHubFormat($input)) { + $command[] = '--logger-github'; + } + + return new Process($command, env: ['XDEBUG_MODE' => 'coverage'], timeout: null); } public static function isAvailable(Configuration $configuration): bool diff --git a/src/Configuration.php b/src/Configuration.php index 47fa920..1d96331 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -5,6 +5,7 @@ use Composer\Semver\Semver; use MyOnlineStore\DevTools\Command\DevToolsCommand; +use Symfony\Component\Process\Process; final class Configuration { @@ -20,6 +21,7 @@ final class Configuration private ?array $phpVersions = null; private string $rootDir; + private ?string $threads = null; public function __construct() { @@ -40,6 +42,55 @@ public function __construct() throw new \RuntimeException('Unable to determine project root'); } + /** + * @return array> + */ + public function getEnabledTools(): array + { + if (null === $this->enabledTools) { + $this->enabledTools = $this->gatherEnabledTools(); + } + + return $this->enabledTools; + } + + /** + * @return list + */ + public function getPhpVersions(): array + { + if (null === $this->phpVersions) { + $this->phpVersions = $this->gatherPhpVersions(); + } + + return $this->phpVersions; + } + + public function getRootDir(): string + { + return $this->rootDir; + } + + public function getThreads(): string + { + if (null === $this->threads) { + $this->threads = $this->determineThreads(); + } + + return $this->threads; + } + + private function determineThreads(): string + { + return \trim( + match (\php_uname('s')) { + 'Linux' => Process::fromShellCommandline('nproc')->mustRun()->getOutput(), + 'Darwin' => Process::fromShellCommandline('sysctl -n hw.logicalcpu')->mustRun()->getOutput(), + default => '2', + } + ); + } + /** * @return list */ @@ -111,33 +162,4 @@ private function gatherEnabledTools(): array return $enabledTools; } - - /** - * @return array> - */ - public function getEnabledTools(): array - { - if (null === $this->enabledTools) { - $this->enabledTools = $this->gatherEnabledTools(); - } - - return $this->enabledTools; - } - - /** - * @return list - */ - public function getPhpVersions(): array - { - if (null === $this->phpVersions) { - $this->phpVersions = $this->gatherPhpVersions(); - } - - return $this->phpVersions; - } - - public function getRootDir(): string - { - return $this->rootDir; - } }