1212 description : ' New Ref'
1313 required : true
1414
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+
1520env :
1621 GO111MODULE : " on"
1722 CACHE_BENCHMARK : " off" # Enables benchmark result reuse between runs, may skew latency results.
1823 RUN_BASE_BENCHMARK : " on" # Runs benchmark for PR base in case benchmark result is missing.
24+ GO_VERSION : 1.23.x
1925jobs :
2026 bench :
21- strategy :
22- matrix :
23- go-version : [ 1.16.x ]
2427 runs-on : ubuntu-latest
2528 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
2832 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+
3045 - name : Checkout code
31- uses : actions/checkout@v2
46+ uses : actions/checkout@v3
3247 with :
3348 ref : ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
49+
3450 - name : Go cache
35- uses : actions/cache@v2
51+ uses : actions/cache@v3
3652 with :
3753 # In order:
3854 # * Module download cache
@@ -43,44 +59,58 @@ jobs:
4359 key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
4460 restore-keys : |
4561 ${{ runner.os }}-go-cache
62+
4663 - name : Restore benchstat
47- uses : actions/cache@v2
64+ uses : actions/cache@v3
4865 with :
4966 path : ~/go/bin/benchstat
50- key : ${{ runner.os }}-benchstat
67+ key : ${{ runner.os }}-benchstat-legacy
68+
5169 - name : Restore base benchmark result
70+ id : base-benchmark
5271 if : env.CACHE_BENCHMARK == 'on'
53- id : benchmark-base
54- uses : actions/cache@v2
72+ uses : actions/cache@v3
5573 with :
5674 path : |
5775 bench-master.txt
5876 bench-main.txt
5977 # Use base sha for PR or new commit hash for master/main push in benchmark result key.
6078 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 != '')
6993 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 }}
7097 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
74102 id : bench
75103 run : |
76104 export REF_NAME=new
77- BENCH_COUNT=5 make bench-run bench-stat
105+ OUTPUT=$(make bench-stat-diff)
106+ echo "${OUTPUT}"
107+ echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
78108 OUTPUT=$(make bench-stat)
79- OUTPUT= "${OUTPUT//'%'/'%25' }"
80- OUTPUT="${ OUTPUT//$'\n'/'%0A'}"
81- OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82- echo "::set-output name= result::$OUTPUT"
83- - 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
84114 uses : marocchino/sticky-pull-request-comment@v2
85115 with :
86116 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
@@ -89,6 +119,13 @@ jobs:
89119 ### Benchmark Result
90120 <details><summary>Benchmark diff with base branch</summary>
91121
122+ ```
123+ ${{ steps.bench.outputs.diff }}
124+ ```
125+ </details>
126+
127+ <details><summary>Benchmark result</summary>
128+
92129 ```
93130 ${{ steps.bench.outputs.result }}
94131 ```
0 commit comments