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-
2015env :
2116 GO111MODULE : " on"
2217 CACHE_BENCHMARK : " off" # Enables benchmark result reuse between runs, may skew latency results.
2318 RUN_BASE_BENCHMARK : " on" # Runs benchmark for PR base in case benchmark result is missing.
24- GO_VERSION : 1.20.x
2519jobs :
2620 bench :
21+ strategy :
22+ matrix :
23+ go-version : [ stable ]
2724 runs-on : ubuntu-latest
2825 steps :
29- - name : Install Go stable
30- if : env.GO_VERSION != 'tip'
31- uses : actions/setup-go@v4
26+ - name : Install Go
27+ uses : actions/setup-go@v5
3228 with :
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-
29+ go-version : ${{ matrix.go-version }}
4530 - name : Checkout code
46- uses : actions/checkout@v3
31+ uses : actions/checkout@v4
4732 with :
4833 ref : ${{ (github.event.inputs.new != '') && github.event.inputs.new || github.event.ref }}
49-
5034 - name : Go cache
51- uses : actions/cache@v3
35+ uses : actions/cache@v4
5236 with :
5337 # In order:
5438 # * Module download cache
@@ -59,58 +43,49 @@ jobs:
5943 key : ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
6044 restore-keys : |
6145 ${{ runner.os }}-go-cache
62-
6346 - name : Restore benchstat
64- uses : actions/cache@v3
47+ uses : actions/cache@v4
6548 with :
6649 path : ~/go/bin/benchstat
67- key : ${{ runner.os }}-benchstat-legacy
68-
50+ key : ${{ runner.os }}-benchstat
6951 - name : Restore base benchmark result
70- id : base-benchmark
7152 if : env.CACHE_BENCHMARK == 'on'
72- uses : actions/cache@v3
53+ id : benchmark-base
54+ uses : actions/cache@v4
7355 with :
7456 path : |
7557 bench-master.txt
7658 bench-main.txt
7759 # Use base sha for PR or new commit hash for master/main push in benchmark result key.
7860 key : ${{ runner.os }}-bench-${{ (github.event.pull_request.base.sha != github.event.after) && github.event.pull_request.base.sha || github.event.after }}
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 != '')
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@v4
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 != '')
9369 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 }}
9770 export REF_NAME=master
98- make bench-run bench-stat
99- git reset --hard $HEAD
100-
101- - name : Benchmark stats
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
10274 id : bench
10375 run : |
10476 export REF_NAME=new
77+ BENCH_COUNT=5 make bench
10578 OUTPUT=$(make bench-stat-diff)
106- echo "${OUTPUT}"
107- echo "diff<<EOF" >> $GITHUB_OUTPUT && echo "$OUTPUT" >> $GITHUB_OUTPUT && echo "EOF" >> $GITHUB_OUTPUT
79+ OUTPUT="${OUTPUT//'%'/'%25'}"
80+ OUTPUT="${OUTPUT//$'\n'/'%0A'}"
81+ OUTPUT="${OUTPUT//$'\r'/'%0D'}"
82+ echo "::set-output name=diff::$OUTPUT"
10883 OUTPUT=$(make bench-stat)
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
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
11489 uses : marocchino/sticky-pull-request-comment@v2
11590 with :
11691 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments