PHPUnit 13 Support #20
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: benchmark | |
| on: | |
| pull_request: | |
| branches: | |
| - master | |
| types: [opened, synchronize, reopened] | |
| permissions: | |
| pull-requests: write | |
| issues: write | |
| jobs: | |
| benchmark: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: Checkout the PR branch | |
| - name: Checkout PR branch | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 # Fetch all history for comparison | |
| # Step 2: Setup PHP | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@bf6b4fbd49ca58e4608c9c89fba0b8d90bd2a39f | |
| with: | |
| php-version: '8.5' | |
| extensions: zip, curl, mbstring, xml | |
| coverage: none | |
| tools: composer:v2 | |
| # Step 2.1: Install PHPBench globally | |
| - name: Install PHPBench | |
| run: | | |
| composer global require phpbench/phpbench:^1.6 --prefer-dist --no-progress --no-interaction | |
| PHPBENCH_BIN="$(composer global config bin-dir --absolute)/phpbench" | |
| echo "PHPBENCH_BIN=$PHPBENCH_BIN" >> "$GITHUB_ENV" | |
| "$PHPBENCH_BIN" --version | |
| # Step 3: Install dependencies for PR branch | |
| - name: Install Composer dependencies | |
| run: | | |
| # Remove dependency artifacts that can leak across branch switches in CI | |
| git clean -fd -- composer.lock vendor | |
| composer install --prefer-dist --no-progress | |
| # Step 4: Run benchmarks on PR branch | |
| - name: Run benchmarks on PR branch | |
| run: | | |
| mkdir -p tests/Benchmark | |
| "$PHPBENCH_BIN" run tests/Benchmark \ | |
| --report=default \ | |
| --tag=pr \ | |
| --retry-threshold=5 \ | |
| --iterations=10 | |
| # Step 5: Checkout base branch | |
| - name: Checkout base branch | |
| run: | | |
| git fetch origin "$BASE_REF" | |
| git checkout "origin/$BASE_REF" | |
| env: | |
| BASE_REF: ${{ github.base_ref }} | |
| # Step 6: Install dependencies for base branch | |
| - name: Install Composer dependencies (base) | |
| run: | | |
| # Ensure install uses only files from the checked out base branch | |
| git clean -fd -- composer.lock vendor | |
| composer install --prefer-dist --no-progress | |
| # Step 7: Run benchmarks on base branch | |
| - name: Run benchmarks on base branch | |
| run: | | |
| mkdir -p tests/Benchmark | |
| "$PHPBENCH_BIN" run tests/Benchmark \ | |
| --report=default \ | |
| --tag=base \ | |
| --retry-threshold=5 \ | |
| --iterations=10 | |
| # Step 8: Checkout PR branch again | |
| - name: Checkout PR branch again | |
| run: git checkout "$HEAD_REF" | |
| env: | |
| HEAD_REF: ${{ github.head_ref }} | |
| # Step 8.1: Reinstall dependencies for PR branch | |
| - name: Install Composer dependencies (PR, comparison) | |
| run: | | |
| # Prevent base branch dependency artifacts from affecting PR comparison run | |
| git clean -fd -- composer.lock vendor | |
| composer install --prefer-dist --no-progress | |
| # Step 9: Compare benchmarks | |
| - name: Compare benchmarks with baseline | |
| id: compare | |
| run: | | |
| mkdir -p tests/Benchmark | |
| "$PHPBENCH_BIN" run tests/Benchmark \ | |
| --report=aggregate \ | |
| --ref=base \ | |
| --retry-threshold=5 \ | |
| --iterations=10 \ | |
| --tag=pr \ | |
| --assert="mode(variant.time.avg) <= mode(baseline.time.avg) +/- 2%" \ | |
| | tee benchmark-comparison.txt | |
| continue-on-error: true | |
| # Step 10: Post results as PR comment | |
| - name: Comment PR with benchmark results | |
| if: ${{ github.actor != 'dependabot[bot]' }} | |
| uses: actions/github-script@v9 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const fs = require('fs'); | |
| const results = fs.readFileSync('benchmark-comparison.txt', 'utf8'); | |
| const body = `## 📊 Benchmark Results\n\n\`\`\`\n${results}\n\`\`\`\n\n**Note:** Benchmarks compare PR against \`${{ github.base_ref }}\` branch.\nPerformance regression threshold: ±2%`; | |
| github.rest.issues.createComment({ | |
| issue_number: context.issue.number, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: body | |
| }); | |
| # Step 11: Fail if performance degrades | |
| - name: Check benchmark assertions | |
| if: steps.compare.outcome == 'failure' | |
| run: | | |
| echo "::error::Performance regression detected! Benchmarks exceeded acceptable threshold." | |
| exit 1 |