Skip to content

Commit 750c99d

Browse files
committed
ci: add automated benchmark comparison workflow for pull requests
1 parent 30416a1 commit 750c99d

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

.github/workflows/benchmark.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Go Benchmark
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
permissions:
8+
pull-requests: write
9+
10+
jobs:
11+
benchmark:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Install Nix
15+
uses: DeterminateSystems/nix-installer-action@main
16+
17+
- name: Run benchmarks on base
18+
run: |
19+
echo "Running benchmarks on base commit ${{ github.event.pull_request.base.sha }}"
20+
nix run github:csvenke/dev-cli/${{ github.event.pull_request.base.sha }}#benchmark > base.bench
21+
22+
- name: Run benchmarks on PR
23+
run: |
24+
echo "Running benchmarks on PR commit ${{ github.event.pull_request.head.sha }}"
25+
nix run github:csvenke/dev-cli/${{ github.event.pull_request.head.sha }}#benchmark > pr.bench
26+
27+
- name: Compare benchmarks
28+
id: compare
29+
run: |
30+
echo "Comparing benchmarks"
31+
nix-shell -p go-tools --run "benchstat base.bench pr.bench" > comparison.txt
32+
echo "COMPARISON<<EOF" >> $GITHUB_OUTPUT
33+
echo '```' >> $GITHUB_OUTPUT
34+
cat comparison.txt >> $GITHUB_OUTPUT
35+
echo '```' >> $GITHUB_OUTPUT
36+
echo "EOF" >> $GITHUB_OUTPUT
37+
38+
- name: Post comment
39+
name: Post benchmark comment
40+
uses: peter-evans/create-or-update-comment@v2
41+
with:
42+
issue-number: ${{ github.event.pull_request.number }}
43+
body: |
44+
## Benchmark Comparison
45+
46+
${{ steps.compare.outputs.COMPARISON }}

0 commit comments

Comments
 (0)