1010
1111permissions : {}
1212
13+ env :
14+ BENCH_COUNT : 6
15+ BENCH_FILTER : ' BenchmarkCompare/(mem|os)fs'
16+ BENCH_PATH : ./test/...
17+
1318jobs :
14- benchmark :
15- name : Compare Benchmarks
19+ setup :
20+ name : Get PR Info
1621 runs-on : ubuntu-latest
17-
1822 permissions :
1923 contents : read
20- pull-requests : write
21-
24+ outputs :
25+ base_ref : ${{ steps.pr-info.outputs.base_ref }}
2226 steps :
2327 - name : Get PR base ref
2428 id : pr-info
@@ -28,48 +32,102 @@ jobs:
2832 base_ref=$(gh pr view ${{ inputs.pr_number }} --repo ${{ github.repository }} --json baseRefName --jq .baseRefName)
2933 echo "base_ref=$base_ref" >> $GITHUB_OUTPUT
3034
35+ bench-base :
36+ name : Benchmark base branch
37+ runs-on : ubuntu-latest
38+ needs : setup
39+ permissions : {}
40+ outputs :
41+ outcome : ${{ steps.bench.outcome }}
42+ steps :
43+ - name : Checkout base branch
44+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
45+ with :
46+ ref : ${{ needs.setup.outputs.base_ref }}
47+ persist-credentials : false
48+
49+ - name : Set up Go
50+ uses : actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
51+ with :
52+ go-version : stable
53+ cache-dependency-path : go.sum
54+
55+ - name : Run benchmarks
56+ id : bench
57+ run : go test -run='^$' -bench="$BENCH_FILTER" -benchmem -count=$BENCH_COUNT $BENCH_PATH > base.txt 2>&1
58+ continue-on-error : true
59+
60+ - name : Upload results
61+ uses : actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
62+ with :
63+ name : base-bench
64+ path : base.txt
65+
66+ bench-pr :
67+ name : Benchmark PR branch
68+ runs-on : ubuntu-latest
69+ needs : setup
70+ permissions : {}
71+ outputs :
72+ outcome : ${{ steps.bench.outcome }}
73+ steps :
3174 - name : Checkout PR branch
32- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5 .0.0
75+ uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 .0.2
3376 with :
3477 ref : refs/pull/${{ inputs.pr_number }}/head
35- path : new
78+ persist-credentials : false
3679
37- - name : Checkout base branch
38- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
80+ - name : Set up Go
81+ uses : actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
82+ with :
83+ go-version : stable
84+ cache-dependency-path : go.sum
85+
86+ - name : Run benchmarks
87+ id : bench
88+ run : go test -run='^$' -bench="$BENCH_FILTER" -benchmem -count=$BENCH_COUNT $BENCH_PATH > pr.txt 2>&1
89+ continue-on-error : true
90+
91+ - name : Upload results
92+ uses : actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
3993 with :
40- ref : ${{ steps. pr-info.outputs.base_ref }}
41- path : old
94+ name : pr-bench
95+ path : pr.txt
4296
97+ compare :
98+ name : Compare and report
99+ runs-on : ubuntu-latest
100+ needs : [bench-base, bench-pr]
101+ if : always()
102+ permissions :
103+ pull-requests : write
104+ steps :
43105 - name : Set up Go
44- uses : actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0 .0
106+ uses : actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3 .0
45107 with :
46108 go-version : stable
47- cache-dependency-path : new/go.sum
48109
49110 - name : Install benchstat
50111 # renovate: datasource=go depName=golang.org/x/perf/cmd/benchstat
51112 run : go install golang.org/x/perf/cmd/benchstat@v0.0.0-20260211190930-8161c38c6cdc
52113
53- - name : Run base branch benchmarks
54- id : base-bench
55- working-directory : old
56- run : go test -run='^$' -bench=. -benchmem -count=1 ./test/... > ../base.txt 2>&1
57- continue-on-error : true
114+ - name : Download base results
115+ uses : actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
116+ with :
117+ name : base-bench
58118
59- - name : Run PR branch benchmarks
60- id : pr-bench
61- working-directory : new
62- run : go test -run='^$' -bench=. -benchmem -count=1 ./test/... > ../pr.txt 2>&1
63- continue-on-error : true
119+ - name : Download PR results
120+ uses : actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
121+ with :
122+ name : pr-bench
64123
65124 - name : Compare and report
66- if : always()
67125 env :
68126 GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
69127 PR_NUMBER : ${{ inputs.pr_number }}
70128 REPO : ${{ github.repository }}
71- BASE_OUTCOME : ${{ steps.base- bench.outcome }}
72- PR_OUTCOME : ${{ steps.pr- bench.outcome }}
129+ BASE_OUTCOME : ${{ needs. bench-base.outputs .outcome }}
130+ PR_OUTCOME : ${{ needs. bench-pr.outputs .outcome }}
73131 run : |
74132 if [ "$BASE_OUTCOME" != "success" ] || [ "$PR_OUTCOME" != "success" ]; then
75133 {
0 commit comments