Skip to content

Bump actions/checkout from 4 to 5 #12

Bump actions/checkout from 4 to 5

Bump actions/checkout from 4 to 5 #12

Workflow file for this run

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@v5
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.4'
extensions: zip, curl, mbstring, xml
coverage: none
# Step 3: Install dependencies for PR branch
- name: Install Composer dependencies
run: |
composer install --prefer-dist --no-progress --no-suggest
composer require --dev phpbench/phpbench
# Step 4: Run benchmarks on PR branch
- name: Run benchmarks on PR branch
run: |
mkdir -p tests/Benchmark
./vendor/bin/phpbench 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: |
composer install --prefer-dist --no-progress --no-suggest
composer require --dev phpbench/phpbench
# Step 7: Run benchmarks on base branch
- name: Run benchmarks on base branch
run: |
mkdir -p tests/Benchmark
./vendor/bin/phpbench 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 9: Compare benchmarks
- name: Compare benchmarks with baseline
id: compare
run: |
mkdir -p tests/Benchmark
./vendor/bin/phpbench 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@v8
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