diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 64d973d..481cccf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,9 +1,11 @@ -on: - - pull_request - - push - name: build +on: + pull_request: + push: + branches: + - master + jobs: tests: name: PHP ${{ matrix.php }}-${{ matrix.os }} @@ -17,15 +19,14 @@ jobs: - windows-latest php: - - 8.0 - - 8.1 - 8.2 + - 8.3 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Install PHP with extensions. + - name: Install PHP with extensions uses: shivammathur/setup-php@v2 env: update: true @@ -35,27 +36,14 @@ jobs: coverage: xdebug tools: composer:v2 - - name: Determine composer cache directory on Linux. - if: matrix.os == 'ubuntu-latest' - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 - - name: Determine composer cache directory on Windows. - if: matrix.os == 'windows-latest' - run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + - name: Run tests with PHPUnit + run: vendor/bin/phpunit --colors=always --coverage-clover=coverage.xml - - name: Cache dependencies installed with composer. - uses: actions/cache@v3 + - name: Upload coverage to Coveralls + if: matrix.os == 'ubuntu-latest' + uses: coverallsapp/github-action@v2 with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Update composer. - run: composer self-update - - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Run tests with phpunit. - run: vendor/bin/phpunit --colors=always + file: ./coverage.xml diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml new file mode 100644 index 0000000..eadb692 --- /dev/null +++ b/.github/workflows/composer-require-checker.yml @@ -0,0 +1,38 @@ +name: Composer require checker + +on: + pull_request: + push: + branches: + - master + +jobs: + composer-require-checker: + name: PHP ${{ matrix.php }}-${{ matrix.os }} + + runs-on: ${{ matrix.os }} + + strategy: + matrix: + os: + - ubuntu-latest + php: + - 8.2 + - 8.3 + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install PHP with extensions + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + + - name: Check dependencies + run: vendor/bin/composer-require-checker diff --git a/.github/workflows/cs.yml b/.github/workflows/cs.yml new file mode 100644 index 0000000..23373f2 --- /dev/null +++ b/.github/workflows/cs.yml @@ -0,0 +1,37 @@ +name: cs fixer + +on: + pull_request_target: + +jobs: + php-cs-fixer: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + token: ${{ secrets.VJIK_GITHUB_TOKEN }} + ref: ${{ github.head_ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: composer:v2 + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHP CS Fixer + run: composer cs-fix + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Apply PHP CS Fixer changes (CI)" + file_pattern: '*.php' + disable_globbing: true diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index f166f4e..1026b82 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -1,10 +1,10 @@ +name: mutation test + on: pull_request: push: branches: - - "master" - -name: mutation test + - master jobs: mutation: @@ -16,13 +16,12 @@ jobs: matrix: os: - ubuntu-latest - php: - - 8.0 + - 8.3 steps: - name: Checkout. - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP with extensions. uses: shivammathur/setup-php@v2 @@ -32,25 +31,11 @@ jobs: coverage: xdebug tools: composer:v2 - - name: Determine composer cache directory on Linux. - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer. - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer - - - name: Update composer. - run: composer self-update - - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 - name: Run roave infection. run: | - vendor/bin/roave-infection-static-analysis-plugin -j2 --ignore-msi-with-no-mutations --only-covered + vendor/bin/roave-infection-static-analysis-plugin --threads=2 --ignore-msi-with-no-mutations --only-covered env: STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }} diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index a26e78d..4a44753 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,9 +1,11 @@ -on: - - pull_request - - push - name: static analysis +on: + pull_request: + push: + branches: + - master + jobs: mutation: name: PHP ${{ matrix.php }}-${{ matrix.os }} @@ -14,39 +16,23 @@ jobs: matrix: os: - ubuntu-latest - php: - - 8.0 - - 8.1 - 8.2 + - 8.3 steps: - - name: Checkout. - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 - - name: Install PHP with extensions. + - name: Install PHP with extensions uses: shivammathur/setup-php@v2 with: coverage: none php-version: ${{ matrix.php }} tools: composer:v2, cs2pr - - name: Determine composer cache directory on Linux. - run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV - - - name: Cache dependencies installed with composer. - uses: actions/cache@v3 - with: - path: ${{ env.COMPOSER_CACHE_DIR }} - key: php${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} - restore-keys: | - php${{ matrix.php }}-composer- - - - name: Update composer. - run: composer self-update - - - name: Install dependencies with composer. - run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 - - name: Static analysis. + - name: Static analysis run: vendor/bin/psalm --shepherd --stats --output-format=checkstyle --php-version=${{ matrix.php }} | cs2pr --graceful-warnings --colorize diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..0f14cad --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,17 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return (new Config()) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules(['@PER-CS2.0' => true]) + ->setFinder($finder); diff --git a/README.md b/README.md index d5c97b7..02f3afc 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Latest Stable Version](https://poser.pugx.org/vjik/_____/v/stable.png)](https://packagist.org/packages/vjik/_____) [![Total Downloads](https://poser.pugx.org/vjik/_____/downloads.png)](https://packagist.org/packages/vjik/_____) [![Build status](https://github.com/vjik/_____/workflows/build/badge.svg)](https://github.com/vjik/_____/actions?query=workflow%3Abuild) +[![Coverage Status](https://coveralls.io/repos/github/vjik/_____/badge.svg)](https://coveralls.io/github/vjik/_____) [![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fvjik%2F_____%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/vjik/_____/master) [![type-coverage](https://shepherd.dev/github/vjik/_____/coverage.svg)](https://shepherd.dev/github/vjik/_____) [![static analysis](https://github.com/vjik/_____/workflows/static%20analysis/badge.svg)](https://github.com/vjik/_____/actions?query=workflow%3A%22static+analysis%22) diff --git a/composer.json b/composer.json index 86f4cde..710ab8b 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,7 @@ "php": "^8.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.64", "phpunit/phpunit": "^9.5", "roave/infection-static-analysis-plugin": "^1.25", "vimeo/psalm": "^4.30|^5.1" @@ -30,6 +31,7 @@ } }, "scripts": { + "cs-fix": "php-cs-fixer fix" }, "config": { "sort-packages": true,