From 4751b0b19f794353bd4b15b9bba4f08a45246b99 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Fri, 12 Apr 2024 18:52:28 +0200 Subject: [PATCH] Replace Makefile with Castor task runner The Makefile has been deleted and replaced by the Castor task runner, implemented in castor.php file. It includes functions for running tests, mutation testing, static analysis, coding standards check, and more. Updates have been made to GitHub workflows, .gitattributes, .gitignore, and ecs.php to reflect these changes. --- .gitattributes | 1 + .github/workflows/infection.yml | 3 +- .github/workflows/integrate.yml | 13 ++-- .gitignore | 2 + Makefile | 50 --------------- castor.php | 106 ++++++++++++++++++++++++++++++++ ecs.php | 1 + 7 files changed, 121 insertions(+), 55 deletions(-) delete mode 100644 Makefile create mode 100644 castor.php diff --git a/.gitattributes b/.gitattributes index 6a77458..45cc172 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,6 +5,7 @@ /.gitattributes export-ignore /.gitignore export-ignore /CODE_OF_CONDUCT.md export-ignore +/castor.php export-ignore /ecs.php export-ignore /infection.json export-ignore /Makefile export-ignore diff --git a/.github/workflows/infection.yml b/.github/workflows/infection.yml index ef1c908..3baded5 100644 --- a/.github/workflows/infection.yml +++ b/.github/workflows/infection.yml @@ -15,6 +15,7 @@ jobs: with: php-version: "8.3" extensions: "json, mbstring, openssl, sqlite3, curl, uuid" + tools: castor - name: "Checkout code" uses: "actions/checkout@v4" @@ -29,4 +30,4 @@ jobs: composer-options: "--optimize-autoloader" - name: "Execute Infection" - run: "make ci-mu" + run: "castor infect --ci" diff --git a/.github/workflows/integrate.yml b/.github/workflows/integrate.yml index d2580a3..3eb385b 100644 --- a/.github/workflows/integrate.yml +++ b/.github/workflows/integrate.yml @@ -30,6 +30,7 @@ jobs: uses: "shivammathur/setup-php@v2" with: php-version: "8.3" + tools: castor - name: "Checkout code" uses: "actions/checkout@v4" @@ -66,6 +67,7 @@ jobs: php-version: "${{ matrix.php-version }}" extensions: "json, mbstring, openssl, sqlite3, curl, uuid" coverage: "xdebug" + tools: castor - name: "Checkout code" uses: "actions/checkout@v4" @@ -77,7 +79,7 @@ jobs: composer-options: "--optimize-autoloader" - name: "Execute unit tests" - run: "make ci-cc" + run: "castor test --coverage-text" static_analysis: name: "3️⃣ Static Analysis" @@ -91,6 +93,7 @@ jobs: with: php-version: "8.3" extensions: "json, mbstring, openssl, sqlite3, curl, uuid" + tools: castor - name: "Checkout code" uses: "actions/checkout@v4" @@ -105,7 +108,7 @@ jobs: composer-options: "--optimize-autoloader" - name: "Execute static analysis" - run: "make st" + run: "castor stan" coding_standards: name: "4️⃣ Coding Standards" @@ -119,6 +122,7 @@ jobs: with: php-version: "8.3" extensions: "json, mbstring, openssl, sqlite3, curl, uuid" + tools: castor - name: "Checkout code" uses: "actions/checkout@v4" @@ -133,7 +137,7 @@ jobs: composer-options: "--optimize-autoloader" - name: "Check coding style" - run: "make ci-cs" + run: "castor cs" rector_checkstyle: name: "6️⃣ Rector Checkstyle" @@ -147,6 +151,7 @@ jobs: with: php-version: "8.3" extensions: "json, mbstring, openssl, sqlite3, curl, uuid" + tools: castor coverage: "xdebug" - name: "Checkout code" @@ -162,7 +167,7 @@ jobs: composer-options: "--optimize-autoloader" - name: "Execute Rector" - run: "make rector" + run: "castor rector" exported_files: name: "7️⃣ Exported files" diff --git a/.gitignore b/.gitignore index c84ab0c..6cc252e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ /vendor/ /composer.lock /.phpunit.result.cache +/.castor.stub.php +/.phpunit.cache diff --git a/Makefile b/Makefile deleted file mode 100644 index debd016..0000000 --- a/Makefile +++ /dev/null @@ -1,50 +0,0 @@ -mu: vendor ## Mutation tests - vendor/bin/infection -s --threads=$$(nproc) --min-msi=0 --min-covered-msi=0 - -tests: vendor ## Run all tests - vendor/bin/phpunit --color - -cc: vendor ## Show test coverage rates (HTML) - vendor/bin/phpunit --coverage-html ./build - -cs: vendor ## Fix all files using defined ECS rules - XDEBUG_MODE=off vendor/bin/ecs check --fix - -tu: vendor ## Run only unit tests - vendor/bin/phpunit --color --group Unit - -ti: vendor ## Run only integration tests - vendor/bin/phpunit --color --group Integration - -tf: vendor ## Run only functional tests - vendor/bin/phpunit --color --group Functional - -st: vendor ## Run static analyse - XDEBUG_MODE=off vendor/bin/phpstan analyse - - -################################################ - -ci-mu: vendor ## Mutation tests (for GitHub only) - vendor/bin/infection --logger-github -s --threads=$$(nproc) --min-msi=0 --min-covered-msi=0 - -ci-cc: vendor ## Show test coverage rates (console) - vendor/bin/phpunit --coverage-text - -ci-cs: vendor ## Check all files using defined ECS rules - XDEBUG_MODE=off vendor/bin/ecs check - -################################################ - - -vendor: composer.json composer.lock - composer validate - composer install - -rector: vendor ## Check all files using Rector - XDEBUG_MODE=off vendor/bin/rector process --ansi --dry-run --xdebug - -.DEFAULT_GOAL := help -help: - @grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/' -.PHONY: help diff --git a/castor.php b/castor.php new file mode 100644 index 0000000..b7b8089 --- /dev/null +++ b/castor.php @@ -0,0 +1,106 @@ +title('Running infection'); + $nproc = run('nproc', quiet: true); + if (! $nproc->isSuccessful()) { + io()->error('Cannot determine the number of processors'); + return; + } + $threads = (int) $nproc->getOutput(); + $command = [ + 'php', + 'vendor/bin/infection', + sprintf('--min-msi=%s', $minMsi), + sprintf('--min-covered-msi=%s', $minCoveredMsi), + sprintf('--threads=%s', $threads), + ]; + if ($ci) { + $command[] = '--logger-github'; + $command[] = '-s'; + } + $environment = [ + 'XDEBUG_MODE' => 'coverage', + ]; + run($command, environment: $environment); +} + +#[AsTask(description: 'Run tests')] +function test(bool $coverageHtml = false, bool $coverageText = false, null|string $group = null): void +{ + io()->title('Running tests'); + $command = ['php', 'vendor/bin/phpunit', '--color']; + $environment = [ + 'XDEBUG_MODE' => 'off', + ]; + if ($coverageHtml) { + $command[] = '--coverage-html=build/coverage'; + $environment['XDEBUG_MODE'] = 'coverage'; + } + if ($coverageText) { + $command[] = '--coverage-text'; + $environment['XDEBUG_MODE'] = 'coverage'; + } + if ($group !== null) { + $command[] = sprintf('--group=%s', $group); + } + run($command, environment: $environment); +} + +#[AsTask(description: 'Coding standards check')] +function cs(bool $fix = false): void +{ + io()->title('Running coding standards check'); + $command = ['php', 'vendor/bin/ecs', 'check']; + $environment = [ + 'XDEBUG_MODE' => 'off', + ]; + if ($fix) { + $command[] = '--fix'; + } + run($command, environment: $environment); +} + +#[AsTask(description: 'Running PHPStan')] +function stan(): void +{ + io()->title('Running PHPStan'); + $command = ['php', 'vendor/bin/phpstan', 'analyse']; + $environment = [ + 'XDEBUG_MODE' => 'off', + ]; + run($command, environment: $environment); +} + +#[AsTask(description: 'Validate Composer configuration')] +function validate(): void +{ + io()->title('Validating Composer configuration'); + $command = ['composer', 'validate']; + $environment = [ + 'XDEBUG_MODE' => 'off', + ]; + run($command, environment: $environment); +} + +#[AsTask(description: 'Run Rector')] +function rector(bool $fix = false): void +{ + io()->title('Running Rector'); + $command = ['php', 'vendor/bin/rector', 'process', '--ansi']; + if (! $fix) { + $command[] = '--dry-run'; + } + $environment = [ + 'XDEBUG_MODE' => 'off', + ]; + run($command, environment: $environment); +} diff --git a/ecs.php b/ecs.php index d4761f0..ba351d1 100644 --- a/ecs.php +++ b/ecs.php @@ -96,6 +96,7 @@ __DIR__ . '/build', __DIR__ . '/vendor', __DIR__ . '/var', + __DIR__ . '/.castor.stub.php', PhpUnitTestClassRequiresCoversFixer::class, ] );