77 paths :
88 - go.mod
99 - go.sum
10- - ' **.go'
11- - ' !**_test.go'
12- - ' !cloud/testserver/**'
13- - ' **_bench_test.go'
10+ - " **.go"
11+ - " !**_test.go"
12+ - " !cloud/testserver/**"
13+ - " **_bench_test.go"
14+ - .github/workflows/benchmark.yml
1415
1516permissions :
1617 pull-requests : write
1718
1819jobs :
20+ discover :
21+ runs-on : blacksmith-4vcpu-ubuntu-2404
22+ outputs :
23+ packages : ${{ steps.find-packages.outputs.packages }}
24+ steps :
25+ - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
26+ with :
27+ ref : ${{github.event.pull_request.head.ref}}
28+ repository : ${{github.event.pull_request.head.repo.full_name}}
29+ fetch-depth : 0
30+
31+ - name : Find benchmark packages
32+ id : find-packages
33+ run : |
34+ # Find all packages containing benchmark functions (not just files named *_bench_test.go)
35+ packages=$(grep -r --include='*_test.go' -l '^func Benchmark' . || true | xargs -r dirname | sed 's|^\./||' | sort -u | jq -R -s -c 'split("\n") | map(select(length > 0))')
36+ echo "packages=${packages}" >> $GITHUB_OUTPUT
37+ echo "Found packages: ${packages}"
38+
1939 benchmarks :
40+ needs : discover
2041 runs-on : blacksmith-4vcpu-ubuntu-2404
2142
43+ strategy :
44+ fail-fast : false
45+ matrix :
46+ package : ${{ fromJson(needs.discover.outputs.packages) }}
47+
2248 steps :
2349 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # pin@v4
2450 with :
@@ -28,19 +54,60 @@ jobs:
2854
2955 - uses : actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # pin@v5
3056 with :
31- go-version-file : ' go.mod'
57+ go-version-file : " go.mod"
58+
59+ - name : Set artifact name
60+ id : artifact
61+ run : |
62+ # Replace / with - for artifact name compatibility
63+ artifact_name=$(echo "${{ matrix.package }}" | tr '/' '-')
64+ echo "name=benchmark-${artifact_name}" >> $GITHUB_OUTPUT
3265
3366 - name : run benchcheck
3467 id : benchmark
68+ run : |
69+ result=$(make bench/check 'pkg=./${{ matrix.package }}' 'parallel=1' 'new=${{ github.event.pull_request.head.sha }}' 'old=${{ github.event.pull_request.base.sha }}')
70+ echo "$result"
71+ echo "## Package: ${{ matrix.package }}" > benchmark-result.txt
72+ echo "$result" >> benchmark-result.txt
73+
74+ - name : Upload benchmark result
75+ uses : actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # pin@v4
76+ with :
77+ name : ${{ steps.artifact.outputs.name }}
78+ path : benchmark-result.txt
79+ retention-days : 1
80+
81+ report :
82+ needs : [discover, benchmarks]
83+ runs-on : blacksmith-4vcpu-ubuntu-2404
84+ if : always() && needs.benchmarks.result != 'skipped'
85+
86+ steps :
87+ - name : Download all benchmark results
88+ uses : actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # pin@v4
89+ continue-on-error : true
90+ with :
91+ path : benchmark-results
92+ pattern : benchmark-*
93+
94+ - name : Combine results
95+ id : combine
3596 run : |
3697 echo "result<<EOF" >> $GITHUB_OUTPUT
37- echo "$(make bench/check 'new=${{ github.event.pull_request.head.sha }}' 'old=${{ github.event.pull_request.base.ref }}')" >> $GITHUB_OUTPUT
98+ # Sort and combine all benchmark result files
99+ find benchmark-results -name 'benchmark-result.txt' -type f | sort | while read -r result_file; do
100+ cat "$result_file" >> $GITHUB_OUTPUT
101+ echo "" >> $GITHUB_OUTPUT
102+ echo "---" >> $GITHUB_OUTPUT
103+ echo "" >> $GITHUB_OUTPUT
104+ done
38105 echo "EOF" >> $GITHUB_OUTPUT
39106
40107 - uses : marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # pin@v2
41108 with :
42109 header : benchmark
43110 message : |
44111 ```
45- ${{ steps.benchmark .outputs.result }}
112+ ${{ steps.combine .outputs.result }}
46113 ```
0 commit comments