-
Notifications
You must be signed in to change notification settings - Fork 81
101 lines (89 loc) · 3.22 KB
/
benchmark.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# This script is a modified version of github.com/bool64/dev.
name: benchmark
on:
pull_request:
workflow_dispatch:
inputs:
old:
description: 'Old Ref'
required: false
default: 'main'
new:
description: 'New Ref'
required: true
# Cancel the workflow in progress in newer build is about to start.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
GO111MODULE: "on"
RUN_BASE_BENCHMARK: "on"
jobs:
benchmarks:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
- name: Install Go stable
uses: actions/setup-go@v3
with:
go-version-file: 'go.mod'
cache: true
- name: Go cache
uses: actions/cache@v3
with:
# In order:
# * Module download cache
# * Build cache (Linux)
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache
- name: Restore benchstat
uses: actions/cache@v3
with:
path: ~/go/bin/benchstat
key: ${{ runner.os }}-benchstat-legacy
- name: Benchmark results for changes
id: bench-next
run: |
BENCH_BASE=next.out make benchmark
echo "next<<EOF" >> $GITHUB_OUTPUT && cat build/next.out >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Benchmark results for base
id: bench-base
if: env.RUN_BASE_BENCHMARK == 'on' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
run: |
git fetch origin main ${{ github.event.pull_request.base.sha }}
HEAD=$(git rev-parse HEAD)
git reset --hard ${{ github.event.pull_request.base.sha }}
BENCH_BASE=base.out make benchmark
git reset --hard $HEAD
echo "base<<EOF" >> $GITHUB_OUTPUT && cat build/base.out >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Benchmark diff against base
id: bench-diff
run: |
echo "${{ steps.bench-next.outputs.next }}" > build/bench-next
echo "${{ steps.bench-base.outputs.base }}" > build/bench-base
BENCH_BASE=bench-base BENCH_NEXT=bench-next make benchstat | tee build/bench-diff.out
echo "diff<<EOF" >> $GITHUB_OUTPUT && cat build/bench-diff.out >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
- name: Comment benchmark result
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
GITHUB_TOKEN: ${{ secrets.PROJECT_ASSIGNER_TOKEN }}
header: benchmark
message: |
### Benchmark Result
<details><summary>Benchmark diff against base branch</summary>
```bash
${{ steps.bench-diff.outputs.diff }}
```
</details>
<details><summary>Benchmark result</summary>
```bash
${{ steps.bench-next.outputs.next }}
```
</details>