name: Performance Regression Check
on:
pull_request:
branches: [ main, develop ]
paths:
- 'src/**'
- 'benches/**'
- 'Cargo.toml'
- 'Cargo.lock'
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
jobs:
performance-regression:
name: Check for Performance Regressions
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-target-${{ hashFiles('**/Cargo.lock') }}
- name: Install criterion
run: cargo install --version=0.5.1 cargo-criterion || true
- name: Restore baseline
uses: actions/cache@v4
with:
path: .benchmark_baselines
key: benchmark-baseline-${{ github.base_ref }}
restore-keys: |
benchmark-baseline-
- name: Run performance benchmarks
run: |
cargo bench --bench regression_tracking -- --noplot
- name: Check for regressions
id: regression_check
run: |
chmod +x scripts/check_performance_regression.sh
./scripts/check_performance_regression.sh || echo "::set-output name=regression::true"
- name: Upload benchmark results
if: always()
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: |
target/criterion/
regression_report.md
- name: Comment PR with results
if: github.event_name == 'pull_request' && steps.regression_check.outputs.regression == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const report = fs.existsSync('regression_report.md')
? fs.readFileSync('regression_report.md', 'utf8')
: 'Performance regression detected. See workflow logs for details.';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## ⚠️ Performance Regression Detected\n\n${report}\n\nPlease review the changes and optimize as needed.`
});
- name: Fail if regression detected
if: steps.regression_check.outputs.regression == 'true'
run: |
echo "::error::Performance regression detected"
exit 1
update-baseline:
name: Update Performance Baseline
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Run benchmarks
run: cargo bench --bench regression_tracking -- --noplot
- name: Save new baseline
run: |
chmod +x scripts/save_baseline.sh
./scripts/save_baseline.sh
- name: Cache baseline
uses: actions/cache@v4
with:
path: .benchmark_baselines
key: benchmark-baseline-${{ github.ref_name }}-${{ github.sha }}