fix(ci): pin orchestra/testbench and phpunit per Laravel major in the… #41
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: Tests | |
| on: | |
| push: | |
| branches: [main] | |
| pull_request: | |
| branches: [main] | |
| jobs: | |
| test: | |
| name: PHP ${{ matrix.php }} / Laravel ${{ matrix.laravel }} | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - php: "8.4" | |
| laravel: "10.*" | |
| testbench: "8.*" | |
| phpunit: "^10.1" | |
| - php: "8.4" | |
| laravel: "11.*" | |
| testbench: "9.*" | |
| phpunit: "^11.3.6" | |
| - php: "8.4" | |
| laravel: "12.*" | |
| testbench: "10.*" | |
| phpunit: "^11.5.3" | |
| - php: "8.4" | |
| laravel: "13.*" | |
| testbench: "11.*" | |
| phpunit: "^11.5.50" | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up PHP ${{ matrix.php }} | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| coverage: none | |
| - name: Require Laravel version | |
| run: | | |
| composer require \ | |
| "illuminate/contracts:${{ matrix.laravel }}" \ | |
| "illuminate/support:${{ matrix.laravel }}" \ | |
| --no-update | |
| composer require \ | |
| "orchestra/testbench:${{ matrix.testbench }}" \ | |
| "phpunit/phpunit:${{ matrix.phpunit }}" \ | |
| --no-update --dev | |
| - name: Install dependencies | |
| run: composer install --no-interaction --prefer-dist | |
| - name: Run tests | |
| run: vendor/bin/phpunit --no-coverage | |
| coverage: | |
| name: Coverage | |
| runs-on: ubuntu-latest | |
| needs: test | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Set up PHP 8.4 with pcov | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.4" | |
| coverage: pcov | |
| - name: Install dependencies | |
| run: composer install --no-interaction --prefer-dist | |
| - name: Run tests with coverage | |
| run: | | |
| mkdir -p build | |
| vendor/bin/phpunit --coverage-clover=build/coverage.xml --coverage-text | |
| - name: Enforce 100% coverage | |
| run: composer coverage:check | |
| - name: Extract coverage percentage | |
| run: | | |
| PCT=$(php -r " | |
| \$xml = simplexml_load_file('build/coverage.xml'); | |
| \$m = \$xml->project->metrics; | |
| \$t = (int)\$m['statements']; | |
| \$c = (int)\$m['coveredstatements']; | |
| echo \$t > 0 ? round(\$c / \$t * 100) : 0; | |
| ") | |
| echo "COVERAGE_PCT=$PCT" >> $GITHUB_ENV | |
| - name: Update coverage badge | |
| if: github.ref == 'refs/heads/main' | |
| env: | |
| GIST_SECRET: ${{ secrets.GIST_SECRET }} | |
| run: | | |
| CONTENT=$(printf '{"schemaVersion":1,"label":"coverage","message":"%s%%","color":"brightgreen"}' "$COVERAGE_PCT") | |
| curl -sf -X PATCH \ | |
| -H "Authorization: token $GIST_SECRET" \ | |
| -H "Content-Type: application/json" \ | |
| -H "User-Agent: GitHub-Actions" \ | |
| -d "{\"files\":{\"coverage.json\":{\"content\":$(echo "$CONTENT" | jq -Rs .)}}}" \ | |
| "https://api.github.com/gists/1a6bdbea77d160eeaf4524b8e165d3ac" |