1
1
name : bench
2
2
on :
3
- push :
4
- tags :
5
- - v*
6
- branches :
7
- - master
8
- - main
9
3
pull_request :
4
+ workflow_dispatch :
5
+ inputs :
6
+ old :
7
+ description : ' Old Ref'
8
+ required : false
9
+ default : ' master'
10
+ new :
11
+ description : ' New Ref'
12
+ required : true
13
+
10
14
env :
11
15
GO111MODULE : " on"
16
+ CACHE_BENCHMARK : " off" # Enables benchmark result reuse between runs, may skew latency results.
17
+ RUN_BASE_BENCHMARK : " on" # Runs benchmark for PR base in case benchmark result is missing.
12
18
jobs :
13
19
bench :
14
20
strategy :
@@ -22,32 +28,52 @@ jobs:
22
28
go-version : ${{ matrix.go-version }}
23
29
- name : Checkout code
24
30
uses : actions/checkout@v2
25
- - name : Restore vendor
31
+ with :
32
+ ref : ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
33
+ - name : Go cache
26
34
uses : actions/cache@v2
27
35
with :
36
+ # In order:
37
+ # * Module download cache
38
+ # * Build cache (Linux)
28
39
path : |
29
- vendor
30
- key : ${{ runner.os }}-go${{ matrix.go-version }}-vendor-${{ hashFiles('** /go.mod') }}
31
- - name : Populate dependencies
32
- run : |
33
- (test -d vendor && echo vendor found) || (go mod vendor && du -sh vendor && du -sh ~/go/pkg/mod)
40
+ ~/go/pkg/mod
41
+ ~/.cache /go-build
42
+ key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
43
+ restore-keys : |
44
+ ${{ runner.os }}-go-cache
34
45
- name : Restore benchstat
35
46
uses : actions/cache@v2
36
47
with :
37
48
path : ~/go/bin/benchstat
38
49
key : ${{ runner.os }}-benchstat
39
50
- name : Restore base benchmark result
51
+ if : env.CACHE_BENCHMARK == 'on'
52
+ id : benchmark-base
40
53
uses : actions/cache@v2
41
54
with :
42
55
path : |
43
56
bench-master.txt
44
57
bench-main.txt
45
58
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
46
59
key : ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
60
+ - name : Checkout base code
61
+ if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
62
+ uses : actions/checkout@v2
63
+ with :
64
+ ref : ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
65
+ path : __base
66
+ - name : Run base benchmark
67
+ if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
68
+ run : |
69
+ export REF_NAME=master
70
+ cd __base
71
+ BENCH_COUNT=5 make bench-run bench-stat
72
+ cp bench-master.txt ../bench-master.txt
47
73
- name : Benchmark
48
74
id : bench
49
75
run : |
50
- export REF_NAME=${GITHUB_REF##*/}
76
+ export REF_NAME=new
51
77
BENCH_COUNT=5 make bench-run bench-stat
52
78
OUTPUT=$(make bench-stat)
53
79
OUTPUT="${OUTPUT//'%'/'%25'}"
0 commit comments