ci: add GitHub Actions CI/CD pipeline, PHPStan & CS Fixer configs #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| tests: | |
| name: "Tests (PHP ${{ matrix.php }})" | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| php: ['8.1', '8.2', '8.3'] | |
| dependencies: ['highest'] | |
| include: | |
| - php: '8.1' | |
| dependencies: 'lowest' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: mbstring, json, redis | |
| coverage: xdebug | |
| tools: composer:v2 | |
| - name: Get Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }}-${{ hashFiles('**/composer.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.dependencies }}- | |
| ${{ runner.os }}-composer-${{ matrix.php }}- | |
| ${{ runner.os }}-composer- | |
| - name: Install dependencies (highest) | |
| if: matrix.dependencies == 'highest' | |
| run: composer install --prefer-dist --no-interaction --no-progress | |
| - name: Install dependencies (lowest) | |
| if: matrix.dependencies == 'lowest' | |
| run: composer update --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress | |
| - name: Run tests | |
| run: vendor/bin/phpunit --testdox | |
| coverage: | |
| name: "Code Coverage" | |
| runs-on: ubuntu-latest | |
| needs: tests | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| extensions: mbstring, json, redis | |
| coverage: xdebug | |
| tools: composer:v2 | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-interaction --no-progress | |
| - name: Run tests with coverage | |
| run: vendor/bin/phpunit --coverage-clover=coverage.xml | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@v4 | |
| with: | |
| file: coverage.xml | |
| fail_ci_if_error: false | |
| env: | |
| CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} | |
| phpstan: | |
| name: "PHPStan" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.3' | |
| extensions: mbstring, json, redis | |
| tools: composer:v2 | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-interaction --no-progress | |
| - name: Run PHPStan | |
| run: vendor/bin/phpstan analyse | |
| cs-fixer: | |
| name: "Code Style (informational)" | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.1' | |
| extensions: mbstring, json | |
| tools: composer:v2 | |
| - name: Install dependencies | |
| run: composer install --prefer-dist --no-interaction --no-progress | |
| - name: Run PHP CS Fixer (dry-run) | |
| run: vendor/bin/php-cs-fixer fix --dry-run --diff |