From a3c4a2816989a4b8099bb63e59b606451f56213a Mon Sep 17 00:00:00 2001 From: Aleksey Polyvanyi Date: Sun, 30 Jun 2024 15:34:48 +0200 Subject: [PATCH 1/2] feature/MTCE-203-allow-to-configure-parallel-processing --- .github/workflows/php-ci.yml | 4 ++ config/phpstan/eonx.neon | 3 ++ config/phpstan/phpstan_parallel_settings.php | 13 +++++++ quality/ecs.php | 7 +++- quality/phpstan.neon | 1 + quality/rector.php | 7 +++- readme.md | 20 +++++++--- src/Helper/ParallelSettingsResolver.php | 40 ++++++++++++++++++++ 8 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 config/phpstan/phpstan_parallel_settings.php create mode 100644 src/Helper/ParallelSettingsResolver.php diff --git a/.github/workflows/php-ci.yml b/.github/workflows/php-ci.yml index b299a7b..03b0d26 100644 --- a/.github/workflows/php-ci.yml +++ b/.github/workflows/php-ci.yml @@ -52,6 +52,10 @@ jobs: - {name: "Rector module tests", run: sh tests/autoload-patch.sh && vendor/bin/phpunit --testsuit Rector} - {name: "Sniffs module tests", run: vendor/bin/phpunit --testsuit Sniffs} - {name: "composer audit", run: composer audit} + env: + EONX_EASY_QUALITY_JOB_SIZE: 20 + EONX_EASY_QUALITY_MAX_NUMBER_OF_PROCESS: 32 + EONX_EASY_QUALITY_TIMEOUT_SECONDS: 120 name: ${{ matrix.actions.name}} (${{ matrix.php }}) steps: - uses: actions/checkout@v4 diff --git a/config/phpstan/eonx.neon b/config/phpstan/eonx.neon index 153612c..135072f 100644 --- a/config/phpstan/eonx.neon +++ b/config/phpstan/eonx.neon @@ -1,3 +1,6 @@ +includes: + - phpstan_parallel_settings.php + services: - class: EonX\EasyQuality\PHPStan\ThrowExceptionMessageRule diff --git a/config/phpstan/phpstan_parallel_settings.php b/config/phpstan/phpstan_parallel_settings.php new file mode 100644 index 0000000..266f2bf --- /dev/null +++ b/config/phpstan/phpstan_parallel_settings.php @@ -0,0 +1,13 @@ + ParallelSettingsResolver::resolveJobSize(), + 'maximumNumberOfProcesses' => ParallelSettingsResolver::resolveMaxNumberOfProcess(), + 'processTimeout' => (float)ParallelSettingsResolver::resolveTimeoutSeconds(), +]; + +return $config; diff --git a/quality/ecs.php b/quality/ecs.php index 6b26743..83c4e6f 100644 --- a/quality/ecs.php +++ b/quality/ecs.php @@ -1,6 +1,7 @@ withParallel(300, 32, 20) + ->withParallel( + ParallelSettingsResolver::resolveTimeoutSeconds(), + ParallelSettingsResolver::resolveMaxNumberOfProcess(), + ParallelSettingsResolver::resolveJobSize() + ) ->withSets([EasyQualitySetList::ECS]) ->withSkip([ 'tests/*/Fixture/*', diff --git a/quality/phpstan.neon b/quality/phpstan.neon index 7837cea..cd03ce2 100644 --- a/quality/phpstan.neon +++ b/quality/phpstan.neon @@ -1,5 +1,6 @@ includes: - %currentWorkingDirectory%/vendor/jangregor/phpstan-prophecy/extension.neon + - %currentWorkingDirectory%/config/phpstan/eonx.neon parameters: bootstrapFiles: diff --git a/quality/rector.php b/quality/rector.php index 8bea519..5ca893c 100644 --- a/quality/rector.php +++ b/quality/rector.php @@ -1,6 +1,7 @@ withParallel(300, 32, 20) + ->withParallel( + ParallelSettingsResolver::resolveTimeoutSeconds(), + ParallelSettingsResolver::resolveMaxNumberOfProcess(), + ParallelSettingsResolver::resolveJobSize() + ) ->withImportNames(importDocBlockNames: false) ->withPhpSets(php81: true) ->withSets([ diff --git a/readme.md b/readme.md index bddcfec..a89e99c 100644 --- a/readme.md +++ b/readme.md @@ -11,8 +11,12 @@ This package is a way to centralise reusable classes used for coding standards a 1. Create a `quality` directory in your project root. 2. Go to the `quality` directory and run `composer require eonx-com/easy-quality`. -3. Add `quality/vendor` to Git ignore (either in a `.gitignore` file inside the `quality` directory or in you project's root `.gitignore` file). -4. Update your project's `composer.json` file by adding a post-install script (this will automate an installation of `eonx-com/easy-quality` on all the local machines): +3. Set env variables to speed up local execution: + - `EONX_EASY_QUALITY_JOB_SIZE` - number of files to process in parallel (default: 2) + - `EONX_EASY_QUALITY_MAX_NUMBER_OF_PROCESS` - maximum number of parallel processes (default: 4) + - `EONX_EASY_QUALITY_TIMEOUT_SECONDS` - timeout in seconds for each process (default: 120) +4. Add `quality/vendor` to Git ignore (either in a `.gitignore` file inside the `quality` directory or in you project's root `.gitignore` file). +5. Update your project's `composer.json` file by adding a post-install script (this will automate an installation of `eonx-com/easy-quality` on all the local machines): ```json { @@ -22,7 +26,7 @@ This package is a way to centralise reusable classes used for coding standards a } ``` -5. Update your project's `composer.json` file by adding the following scripts. Here we use `veewee/composer-run-parallel` (install it as a **dev** dependency) for the `check-all` script to run multiple commands in parallel. Feel free to modiy these +6. Update your project's `composer.json` file by adding the following scripts. Here we use `veewee/composer-run-parallel` (install it as a **dev** dependency) for the `check-all` script to run multiple commands in parallel. Feel free to modiy these commands as you wish. ```json @@ -38,9 +42,9 @@ This package is a way to centralise reusable classes used for coding standards a } ``` -6. Make sure you have config files for ECS, Rector, PHP Mess Detector, and PHPStan in the project source code root. -7. Run `composer check-all` from the project source code root to make sure everything is working and fix the found issues. -8. If you want to use the quality tools in CI, here is an example of a GitHub action configuration: +7. Make sure you have config files for ECS, Rector, PHP Mess Detector, and PHPStan in the project source code root. +8. Run `composer check-all` from the project source code root to make sure everything is working and fix the found issues. +9. If you want to use the quality tools in CI, here is an example of a GitHub action configuration: ```yaml coding-standards: @@ -59,6 +63,10 @@ This package is a way to centralise reusable classes used for coding standards a - {name: security, run: composer check-security} - {name: yaml-linter, run: './bin/console lint:yaml config src translations --parse-tags'} - {name: ecs, run: composer check-ecs} + env: + EONX_EASY_QUALITY_JOB_SIZE: 20 + EONX_EASY_QUALITY_MAX_NUMBER_OF_PROCESS: 32 + EONX_EASY_QUALITY_TIMEOUT_SECONDS: 120 name: ${{ matrix.actions.name}} (${{ matrix.php }}) diff --git a/src/Helper/ParallelSettingsResolver.php b/src/Helper/ParallelSettingsResolver.php new file mode 100644 index 0000000..48994ec --- /dev/null +++ b/src/Helper/ParallelSettingsResolver.php @@ -0,0 +1,40 @@ + Date: Mon, 1 Jul 2024 12:42:57 +0200 Subject: [PATCH 2/2] -refactoring --- config/phpstan/phpstan_parallel_settings.php | 8 ++++---- quality/ecs.php | 8 ++++---- quality/rector.php | 8 ++++---- ...lelSettingsResolver.php => ParallelSettingsHelper.php} | 8 ++++---- 4 files changed, 16 insertions(+), 16 deletions(-) rename src/Helper/{ParallelSettingsResolver.php => ParallelSettingsHelper.php} (82%) diff --git a/config/phpstan/phpstan_parallel_settings.php b/config/phpstan/phpstan_parallel_settings.php index 266f2bf..59a603c 100644 --- a/config/phpstan/phpstan_parallel_settings.php +++ b/config/phpstan/phpstan_parallel_settings.php @@ -1,13 +1,13 @@ ParallelSettingsResolver::resolveJobSize(), - 'maximumNumberOfProcesses' => ParallelSettingsResolver::resolveMaxNumberOfProcess(), - 'processTimeout' => (float)ParallelSettingsResolver::resolveTimeoutSeconds(), + 'jobSize' => ParallelSettingsHelper::getJobSize(), + 'maximumNumberOfProcesses' => ParallelSettingsHelper::getMaxNumberOfProcess(), + 'processTimeout' => (float)ParallelSettingsHelper::getTimeoutSeconds(), ]; return $config; diff --git a/quality/ecs.php b/quality/ecs.php index 83c4e6f..b61d8e5 100644 --- a/quality/ecs.php +++ b/quality/ecs.php @@ -1,7 +1,7 @@ withParallel( - ParallelSettingsResolver::resolveTimeoutSeconds(), - ParallelSettingsResolver::resolveMaxNumberOfProcess(), - ParallelSettingsResolver::resolveJobSize() + ParallelSettingsHelper::getTimeoutSeconds(), + ParallelSettingsHelper::getMaxNumberOfProcess(), + ParallelSettingsHelper::getJobSize() ) ->withSets([EasyQualitySetList::ECS]) ->withSkip([ diff --git a/quality/rector.php b/quality/rector.php index 5ca893c..e0b1740 100644 --- a/quality/rector.php +++ b/quality/rector.php @@ -1,7 +1,7 @@ withParallel( - ParallelSettingsResolver::resolveTimeoutSeconds(), - ParallelSettingsResolver::resolveMaxNumberOfProcess(), - ParallelSettingsResolver::resolveJobSize() + ParallelSettingsHelper::getTimeoutSeconds(), + ParallelSettingsHelper::getMaxNumberOfProcess(), + ParallelSettingsHelper::getJobSize() ) ->withImportNames(importDocBlockNames: false) ->withPhpSets(php81: true) diff --git a/src/Helper/ParallelSettingsResolver.php b/src/Helper/ParallelSettingsHelper.php similarity index 82% rename from src/Helper/ParallelSettingsResolver.php rename to src/Helper/ParallelSettingsHelper.php index 48994ec..6b0ed12 100644 --- a/src/Helper/ParallelSettingsResolver.php +++ b/src/Helper/ParallelSettingsHelper.php @@ -3,7 +3,7 @@ namespace EonX\EasyQuality\Helper; -final class ParallelSettingsResolver +final class ParallelSettingsHelper { private const DEFAULT_JOB_SIZE = 2; @@ -17,21 +17,21 @@ final class ParallelSettingsResolver private const ENV_TIMEOUT_SECONDS = 'EONX_EASY_QUALITY_TIMEOUT_SECONDS'; - public static function resolveJobSize(): int + public static function getJobSize(): int { $jobSize = \getenv(self::ENV_JOB_SIZE); return $jobSize ? (int)$jobSize : self::DEFAULT_JOB_SIZE; } - public static function resolveMaxNumberOfProcess(): int + public static function getMaxNumberOfProcess(): int { $maxNumberOfProcess = \getenv(self::ENV_MAX_NUMBER_OF_PROCESS); return $maxNumberOfProcess ? (int)$maxNumberOfProcess : self::DEFAULT_MAX_NUMBER_OF_PROCESS; } - public static function resolveTimeoutSeconds(): int + public static function getTimeoutSeconds(): int { $timeoutSeconds = \getenv(self::ENV_TIMEOUT_SECONDS);