From 04046388ac369f4fcc74da4b5ea4321e176740c7 Mon Sep 17 00:00:00 2001 From: core23 Date: Sat, 4 Dec 2021 12:30:30 +0100 Subject: [PATCH] Update tools and use make to run them --- .github/workflows/continuous-integration.yml | 30 ++++----- .gitignore | 1 + .php-cs-fixer.php => .php-cs-fixer.dist.php | 0 Makefile | 64 ++++++++++++++++++++ composer.json | 21 ------- phpstan.neon.dist | 5 +- 6 files changed, 79 insertions(+), 42 deletions(-) rename .php-cs-fixer.php => .php-cs-fixer.dist.php (100%) create mode 100644 Makefile diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index ee6d3dcf..8a097509 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -3,7 +3,6 @@ name: 'Continuous Integration' on: create: pull_request: - types: [ opened, synchronize, reopened ] push: branches: - "*.x" @@ -32,9 +31,6 @@ jobs: extensions: "mbstring, json, mongo" php-version: ${{ matrix.php-version }} - - name: "Validate composer.json and composer.lock" - run: composer validate --strict - - name: "Cache dependencies installed with composer" uses: actions/cache@v2.1.6 with: @@ -46,8 +42,8 @@ jobs: - name: "Install locked dependencies with composer" run: composer install --no-interaction --no-progress - - name: "Run localheinz/composer-normalize" - run: composer normalize --dry-run + - name: "Run composer lint" + run: make lint-composer - name: "Create cache directory for friendsofphp/php-cs-fixer" run: mkdir -p .build/php-cs-fixer @@ -61,7 +57,9 @@ jobs: php${{ matrix.php-version }}-php-cs-fixer- - name: "Run friendsofphp/php-cs-fixer" - run: composer cs-diff + env: + PHP_CS_FIXER_IGNORE_ENV: 1 + run: make cs static-code-analysis: name: "Static Code Analysis" @@ -96,13 +94,13 @@ jobs: run: composer install --no-interaction --no-progress - name: "Run phpstan/phpstan" - run: composer phpstan + run: make phpstan - name: "Run psalm" - run: vendor/bin/psalm --config=psalm.xml --diff --shepherd --show-info=false --stats --threads=4 + run: make psalm - name: "Run phpmd" - run: composer phpmd + run: make phpmd tests: name: "Test (PHP ${{ matrix.php-version }}, symfony ${{ matrix.symfony }}, ${{ matrix.dependencies }})" @@ -135,7 +133,8 @@ jobs: php-version: ${{ matrix.php-version }} - name: 'Install Symfony Flex' - run: composer global require --prefer-dist --no-progress --ansi symfony/flex + run: | + composer global require --prefer-dist --no-progress --ansi symfony/flex - name: "Cache dependencies installed with composer" uses: actions/cache@v2.1.6 @@ -157,7 +156,7 @@ jobs: run: composer update --no-interaction --no-progress - name: "Run tests with phpunit/phpunit" - run: composer test + run: make test code-coverage: name: "Code Coverage" @@ -192,7 +191,7 @@ jobs: run: composer install --no-interaction --no-progress - name: "Collect code coverage with pcov and phpunit/phpunit" - run: composer coverage + run: make coverage - name: "Send code coverage report to Codecov.io" env: @@ -231,8 +230,5 @@ jobs: - name: "Install locked dependencies with composer" run: composer install --no-interaction --no-progress - - name: "Download infection" - run: wget -O infection https://github.com/infection/infection/releases/download/0.19.0/infection.phar && chmod +x infection - - name: "Run mutation tests with pcov and infection/infection" - run: ./infection + run: make infection diff --git a/.gitignore b/.gitignore index 9bbaeed6..e2ccc906 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ phpunit.xml /vendor/ !/vendor-bin/tools/composer.lock /vendor-bin/tools/vendor/ +/vendor-bin/tools/bin/ diff --git a/.php-cs-fixer.php b/.php-cs-fixer.dist.php similarity index 100% rename from .php-cs-fixer.php rename to .php-cs-fixer.dist.php diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..9808c83d --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +.PHONY: default +default: lint + +.PHONY: fix +fix: cs-fix lint-fix + +.PHONY: lint +lint: lint-composer + +.PHONY: lint-composer +lint-composer: + composer validate --strict + composer normalize --dry-run + +.PHONY: test +test: vendor-bin/tools/vendor + vendor/bin/phpunit --colors=always + +.PHONY: infection +infection: vendor/bin/infection + vendor/bin/infection --threads=4 + +.PHONY: coverage +coverage: vendor-bin/tools/vendor + vendor/bin/phpunit --colors=always --coverage-clover=build/logs/clover.xml + +.PHONY: cs +cs: vendor-bin/tools/vendor + vendor/bin/php-cs-fixer fix --verbose --diff --dry-run + +.PHONY: cs-fix +cs-fix: vendor-bin/tools/vendor + vendor/bin/php-cs-fixer fix --verbose + +.PHONY: psalm +psalm: vendor-bin/tools/vendor + vendor/bin/psalm --config=psalm.xml --diff --shepherd --show-info=false --stats --threads=4 + +.PHONY: phpstan +phpstan: vendor-bin/tools/vendor + vendor/bin/phpstan analyse + +.PHONY: phpmd +phpmd: vendor-bin/tools/vendor + vendor/bin/phpmd src,tests ansi phpmd.xml + +.PHONY: lint-fix +lint-fix: + find ./src \\( -name '*.xml' -or -name '*.xml.dist' -or -name '*.xlf' \\) -type f -exec xmllint --encode UTF-8 --output '{}' --format '{}' \\; + find ./src \\( -name '*.yml' -or -name '*.yaml' \\) -not -path '*/vendor/*' | xargs yaml-lint + +.PHONY: check-dependencies +check-dependencies: vendor-bin/tools/vendor + vendor/bin/composer-require-checker check --config-file composer-require.json composer.json + +# +# Installation tasks +# + +vendor-bin/tools/vendor: + composer --working-dir=vendor-bin/tools install + +vendor/bin/infection: vendor-bin/tools/vendor + wget -O vendor/bin/infection https://github.com/infection/infection/releases/latest/download/infection.phar && chmod +x vendor/bin/infection diff --git a/composer.json b/composer.json index 173dc97b..2bee53fe 100644 --- a/composer.json +++ b/composer.json @@ -60,7 +60,6 @@ }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", - "bamarni/composer-bin-plugin": "^1.3", "doctrine/doctrine-bundle": "^1.12 || ^2.0", "doctrine/orm": "^2.7", "ergebnis/composer-normalize": "^2.0.1", @@ -85,25 +84,5 @@ }, "config": { "sort-packages": true - }, - "scripts": { - "post-install-cmd": [ - "@composer bin all install --ansi" - ], - "post-update-cmd": [ - "@composer bin all install --ansi" - ], - "coverage": "vendor/bin/phpunit --colors=always --coverage-clover=build/logs/clover.xml", - "cs": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --verbose", - "cs-diff": "PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --verbose --diff --dry-run", - "deps": "vendor/bin/composer-require-checker check --config-file composer-require.json composer.json", - "infection": "vendor/bin/infection", - "lint": [ - "find ./src \\( -name '*.xml' -or -name '*.xml.dist' -or -name '*.xlf' \\) -type f -exec xmllint --encode UTF-8 --output '{}' --format '{}' \\;", - "find ./src \\( -name '*.yml' -or -name '*.yaml' \\) -not -path '*/vendor/*' | xargs yaml-lint" - ], - "phpmd": "vendor/bin/phpmd src,tests ansi phpmd.xml", - "phpstan": "vendor/bin/phpstan analyse", - "test": "vendor/bin/phpunit --colors=always" } } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e0fdee44..fc58beb5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: max + level: 8 paths: - src @@ -10,6 +10,3 @@ parameters: bootstrapFiles: - vendor-bin/tools/vendor/autoload.php - - excludes_analyse: - - tests/bootstrap.php