Skip to content

Commit

Permalink
chore: Add --threads argument where possible (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankverhoeven authored May 17, 2022
1 parent eac50e5 commit 3541eba
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 41 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions src/Command/CodesnifferCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Command/PsalmCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
21 changes: 12 additions & 9 deletions src/Command/RoaveInfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
80 changes: 51 additions & 29 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Composer\Semver\Semver;
use MyOnlineStore\DevTools\Command\DevToolsCommand;
use Symfony\Component\Process\Process;

final class Configuration
{
Expand All @@ -20,6 +21,7 @@ final class Configuration
private ?array $phpVersions = null;

private string $rootDir;
private ?string $threads = null;

public function __construct()
{
Expand All @@ -40,6 +42,55 @@ public function __construct()
throw new \RuntimeException('Unable to determine project root');
}

/**
* @return array<string, class-string<DevToolsCommand>>
*/
public function getEnabledTools(): array
{
if (null === $this->enabledTools) {
$this->enabledTools = $this->gatherEnabledTools();
}

return $this->enabledTools;
}

/**
* @return list<string>
*/
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<string>
*/
Expand Down Expand Up @@ -111,33 +162,4 @@ private function gatherEnabledTools(): array

return $enabledTools;
}

/**
* @return array<string, class-string<DevToolsCommand>>
*/
public function getEnabledTools(): array
{
if (null === $this->enabledTools) {
$this->enabledTools = $this->gatherEnabledTools();
}

return $this->enabledTools;
}

/**
* @return list<string>
*/
public function getPhpVersions(): array
{
if (null === $this->phpVersions) {
$this->phpVersions = $this->gatherPhpVersions();
}

return $this->phpVersions;
}

public function getRootDir(): string
{
return $this->rootDir;
}
}

0 comments on commit 3541eba

Please sign in to comment.