|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [master] |
| 6 | + pull_request: |
| 7 | + branches: [master] |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + |
| 12 | +env: |
| 13 | + PHP_PRIMARY: '8.5' |
| 14 | + |
| 15 | +jobs: |
| 16 | + validate: |
| 17 | + name: Validate composer.json |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v6 |
| 21 | + |
| 22 | + - uses: shivammathur/setup-php@v2 |
| 23 | + with: |
| 24 | + php-version: ${{ env.PHP_PRIMARY }} |
| 25 | + tools: composer:v2 |
| 26 | + |
| 27 | + - run: composer validate --strict |
| 28 | + |
| 29 | + tests: |
| 30 | + name: Tests / PHP ${{ matrix.php }} |
| 31 | + runs-on: ubuntu-latest |
| 32 | + needs: validate |
| 33 | + strategy: |
| 34 | + fail-fast: false |
| 35 | + matrix: |
| 36 | + php: ['8.2', '8.3', '8.4', '8.5', '8.6'] |
| 37 | + |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v6 |
| 40 | + |
| 41 | + - uses: shivammathur/setup-php@v2 |
| 42 | + with: |
| 43 | + php-version: ${{ matrix.php }} |
| 44 | + coverage: ${{ matrix.php == env.PHP_PRIMARY && 'xdebug' || 'none' }} |
| 45 | + tools: composer:v2 |
| 46 | + |
| 47 | + - name: Cache Composer packages |
| 48 | + uses: actions/cache@v4 |
| 49 | + with: |
| 50 | + path: vendor |
| 51 | + key: php-${{ matrix.php }}-${{ hashFiles('composer.json') }} |
| 52 | + restore-keys: php-${{ matrix.php }}- |
| 53 | + |
| 54 | + - run: composer install --no-interaction --no-progress --prefer-dist |
| 55 | + |
| 56 | + - name: Run tests |
| 57 | + if: matrix.php != env.PHP_PRIMARY |
| 58 | + run: vendor/bin/phpunit --colors=always |
| 59 | + |
| 60 | + - name: Run tests with coverage |
| 61 | + if: matrix.php == env.PHP_PRIMARY |
| 62 | + run: vendor/bin/phpunit --colors=always --coverage-text |
| 63 | + env: |
| 64 | + XDEBUG_MODE: coverage |
| 65 | + |
| 66 | + phpstan: |
| 67 | + name: PHPStan |
| 68 | + runs-on: ubuntu-latest |
| 69 | + needs: validate |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v6 |
| 72 | + |
| 73 | + - uses: shivammathur/setup-php@v2 |
| 74 | + with: |
| 75 | + php-version: ${{ env.PHP_PRIMARY }} |
| 76 | + tools: composer:v2 |
| 77 | + |
| 78 | + - name: Cache Composer packages |
| 79 | + uses: actions/cache@v4 |
| 80 | + with: |
| 81 | + path: vendor |
| 82 | + key: php-${{ env.PHP_PRIMARY }}-${{ hashFiles('composer.json') }} |
| 83 | + restore-keys: php-${{ env.PHP_PRIMARY }}- |
| 84 | + |
| 85 | + - run: composer install --no-interaction --no-progress --prefer-dist |
| 86 | + |
| 87 | + - run: vendor/bin/phpstan analyse --no-progress --error-format=github |
| 88 | + |
| 89 | + benchmark: |
| 90 | + name: Benchmark |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: tests |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v6 |
| 95 | + with: |
| 96 | + fetch-depth: 0 |
| 97 | + |
| 98 | + - uses: shivammathur/setup-php@v2 |
| 99 | + with: |
| 100 | + php-version: ${{ env.PHP_PRIMARY }} |
| 101 | + coverage: none |
| 102 | + extensions: curl, dom, mbstring, tokenizer, xml |
| 103 | + ini-values: opcache.enable_cli=1, opcache.jit=1255, opcache.jit_buffer_size=128M |
| 104 | + tools: composer:v2 |
| 105 | + |
| 106 | + - name: Cache Composer packages |
| 107 | + uses: actions/cache@v4 |
| 108 | + with: |
| 109 | + path: vendor |
| 110 | + key: php-${{ env.PHP_PRIMARY }}-bench-${{ hashFiles('composer.json') }} |
| 111 | + restore-keys: php-${{ env.PHP_PRIMARY }}-bench- |
| 112 | + |
| 113 | + - run: composer install --no-interaction --no-progress --prefer-dist |
| 114 | + |
| 115 | + - name: Benchmark baseline (master) |
| 116 | + if: github.event_name == 'pull_request' |
| 117 | + run: | |
| 118 | + git checkout ${{ github.event.pull_request.base.sha }} |
| 119 | + if [ ! -f phpbench.json ]; then |
| 120 | + echo "No phpbench.json on base — skipping baseline" |
| 121 | + git checkout ${{ github.event.pull_request.head.sha }} |
| 122 | + exit 0 |
| 123 | + fi |
| 124 | + composer install --no-interaction --no-progress --prefer-dist --quiet |
| 125 | + vendor/bin/phpbench run --tag=baseline --progress=plain |
| 126 | + git checkout ${{ github.event.pull_request.head.sha }} |
| 127 | + composer install --no-interaction --no-progress --prefer-dist --quiet |
| 128 | +
|
| 129 | + - name: Benchmark (compare with baseline) |
| 130 | + if: github.event_name == 'pull_request' |
| 131 | + run: | |
| 132 | + if vendor/bin/phpbench report --ref=baseline > /dev/null 2>&1; then |
| 133 | + vendor/bin/phpbench run --ref=baseline --report=default --progress=plain |
| 134 | + else |
| 135 | + echo "No baseline available — running without comparison" |
| 136 | + vendor/bin/phpbench run --report=default --progress=plain |
| 137 | + fi |
| 138 | +
|
| 139 | + - name: Benchmark |
| 140 | + if: github.event_name == 'push' |
| 141 | + run: vendor/bin/phpbench run --report=default --progress=plain |
0 commit comments