add CI to detect performance regressions #2
Workflow file for this run
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: Performance Regression | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
branches: [main] | |
jobs: | |
build: | |
name: Build ${{ matrix.name }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- commit: ${{ github.sha }} | |
name: current | |
- commit: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || github.event.before }} | |
name: previous | |
steps: | |
- name: Checkout ${{ matrix.name }} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ matrix.commit }} | |
- name: Cache base ref build | |
uses: actions/cache@v4 | |
id: cache | |
with: | |
key: bin-cache-${{ matrix.name }}-${{ matrix.commit }} | |
path: target/release/cpp-linter | |
- run: rustup update --no-self-update | |
if: steps.cache.outputs.cache-hit != 'true' | |
- run: cargo build --bin cpp-linter --release | |
if: steps.cache.outputs.cache-hit != 'true' | |
- name: Upload build artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.name }} | |
path: target/release/cpp-linter | |
benchmark: | |
name: Measure Performance Difference | |
needs: [build] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout libgit2 | |
uses: actions/checkout@v4 | |
with: | |
repository: libgit2/libgit2 | |
ref: v1.8.1 | |
- name: Download built binaries | |
uses: actions/download-artifact@v4 | |
- run: ls previous current | |
- run: chmod +x ./previous/cpp-linter && chmod +x ./current/cpp-linter | |
- name: Install cargo-binstall | |
uses: cargo-bins/cargo-binstall@main | |
- name: Install hyperfine | |
run: cargo binstall -y hyperfine | |
- name: Run hyperfine tool | |
run: >- | |
hyperfine | |
--warmup 1 | |
--runs 5 | |
--style color | |
--export-markdown '${{ runner.temp }}/benchmark.md' | |
--export-json '${{ runner.temp }}/benchmark.json' | |
--command-name=previous-build './previous/cpp-linter -l 0' | |
--command-name=current-build './current/cpp-linter -l 0' | |
- run: cat ${{ runner.temp }}/bench.md >> $GITHUB_STEP_SUMMARY | |
- name: Upload JSON results | |
uses: actions/upload-artifact@v4 | |
with: | |
path: ${{ runner.temp }}/benchmark.json | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: 3.x | |
- name: Annotate summary | |
run: python .github/workflows/bench.py "${{ runner.temp }}/benchmark.json" |