12
12
description : ' New Ref'
13
13
required : true
14
14
15
+ # Cancel the workflow in progress in newer build is about to start.
16
+ concurrency :
17
+ group : ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
18
+ cancel-in-progress : true
19
+
15
20
env :
16
21
GO111MODULE : " on"
17
22
CACHE_BENCHMARK : " off" # Enables benchmark result reuse between runs, may skew latency results.
18
23
RUN_BASE_BENCHMARK : " on" # Runs benchmark for PR base in case benchmark result is missing.
24
+ GO_VERSION : 1.20.x
19
25
jobs :
20
26
bench :
21
- strategy :
22
- matrix :
23
- go-version : [ 1.17.x ]
24
27
runs-on : ubuntu-latest
25
28
steps :
26
- - name : Install Go
27
- uses : actions/setup-go@v2
29
+ - name : Install Go stable
30
+ if : env.GO_VERSION != 'tip'
31
+ uses : actions/setup-go@v4
28
32
with :
29
- go-version : ${{ matrix.go-version }}
33
+ go-version : ${{ env.GO_VERSION }}
34
+
35
+ - name : Install Go tip
36
+ if : env.GO_VERSION == 'tip'
37
+ run : |
38
+ curl -sL https://storage.googleapis.com/go-build-snap/go/linux-amd64/$(git ls-remote https://github.com/golang/go.git HEAD | awk '{print $1;}').tar.gz -o gotip.tar.gz
39
+ ls -lah gotip.tar.gz
40
+ mkdir -p ~/sdk/gotip
41
+ tar -C ~/sdk/gotip -xzf gotip.tar.gz
42
+ ~/sdk/gotip/bin/go version
43
+ echo "PATH=$HOME/go/bin:$HOME/sdk/gotip/bin/:$PATH" >> $GITHUB_ENV
44
+
30
45
- name : Checkout code
31
- uses : actions/checkout@v2
46
+ uses : actions/checkout@v3
32
47
with :
33
48
ref : ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
49
+
34
50
- name : Go cache
35
- uses : actions/cache@v2
51
+ uses : actions/cache@v3
36
52
with :
37
53
# In order:
38
54
# * Module download cache
@@ -43,49 +59,58 @@ jobs:
43
59
key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
44
60
restore-keys : |
45
61
${{ runner.os }}-go-cache
62
+
46
63
- name : Restore benchstat
47
- uses : actions/cache@v2
64
+ uses : actions/cache@v3
48
65
with :
49
66
path : ~/go/bin/benchstat
50
- key : ${{ runner.os }}-benchstat
67
+ key : ${{ runner.os }}-benchstat-legacy
68
+
51
69
- name : Restore base benchmark result
70
+ id : base-benchmark
52
71
if : env.CACHE_BENCHMARK == 'on'
53
- id : benchmark-base
54
- uses : actions/cache@v2
72
+ uses : actions/cache@v3
55
73
with :
56
74
path : |
57
75
bench-master.txt
58
76
bench-main.txt
59
77
# Use base sha for PR or new commit hash for master/main push in benchmark result key.
60
78
key : ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
61
- - name : Checkout base code
62
- if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
63
- uses : actions/checkout@v2
64
- with :
65
- ref : ${{ (github.event.pull_request.base.sha != '' ) && github.event.pull_request.base.sha || github.event.inputs.old }}
66
- path : __base
67
- - name : Run base benchmark
68
- if : env.RUN_BASE_BENCHMARK == 'on' && steps.benchmark-base.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
79
+
80
+ - name : Run benchmark
81
+ run : |
82
+ export REF_NAME=new
83
+ make bench
84
+ OUTPUT=$(make bench-stat-diff)
85
+ echo "${OUTPUT}"
86
+ echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
87
+ OUTPUT=$(make bench-stat)
88
+ echo "${OUTPUT}"
89
+ echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
90
+
91
+ - name : Run benchmark for base code
92
+ if : env.RUN_BASE_BENCHMARK == 'on' && steps.base-benchmark.outputs.cache-hit != 'true' && (github.event.pull_request.base.sha != '' || github.event.inputs.old != '')
69
93
run : |
94
+ git fetch origin master ${{ github.event.pull_request.base.sha }}
95
+ HEAD=$(git rev-parse HEAD)
96
+ git reset --hard ${{ github.event.pull_request.base.sha }}
70
97
export REF_NAME=master
71
- cd __base
72
- make | grep bench-run && (BENCH_COUNT=5 make bench-run bench-stat && cp bench-master.txt ../bench-master.txt) || echo "No benchmarks in base"
73
- - name : Benchmark
98
+ make bench-run bench-stat
99
+ git reset --hard $HEAD
100
+
101
+ - name : Benchmark stats
74
102
id : bench
75
103
run : |
76
104
export REF_NAME=new
77
- BENCH_COUNT=5 make bench
78
105
OUTPUT=$(make bench-stat-diff)
79
- OUTPUT="${OUTPUT//'%'/'%25'}"
80
- OUTPUT="${OUTPUT//$'\n'/'%0A'}"
81
- OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82
- echo "::set-output name=diff::$OUTPUT"
106
+ echo "${OUTPUT}"
107
+ echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
83
108
OUTPUT=$(make bench-stat)
84
- OUTPUT= "${OUTPUT//'%'/'%25' }"
85
- OUTPUT="${ OUTPUT//$'\n'/'%0A'}"
86
- OUTPUT="${OUTPUT//$'\r'/'%0D'}"
87
- echo "::set-output name= result::$OUTPUT"
88
- - name : Comment Benchmark Result
109
+ echo "${OUTPUT}"
110
+ echo "result<<EOF" >> $GITHUB_OUTPUT && echo "$ OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
111
+
112
+ - name : Comment benchmark result
113
+ continue-on-error : true
89
114
uses : marocchino/sticky-pull-request-comment@v2
90
115
with :
91
116
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments