@@ -3,6 +3,8 @@ name: Benchmark Main
33on :
44 push :
55 branches : [ main ]
6+ pull_request :
7+ types : [labeled]
68 workflow_dispatch :
79
810permissions :
1719 container :
1820 image : ubuntu:24.04@sha256:353675e2a41babd526e2b837d7ec780c2a05bca0164f7ea5dbbd433d21d166fc
1921 timeout-minutes : 20 # since there is only a single bare metal runner across all repos
22+ if : github.event_name != 'pull_request' || contains(github.event.label.name, 'run benchmarks')
2023 steps :
2124 - name : Install Git
2225 run : |
4649 java -jar libs/opentelemetry-sdk-trace-*-jmh.jar -rf json SpanBenchmark SpanPipelineBenchmark ExporterBenchmark
4750
4851 - name : Use CLA approved github bot
52+ if : github.event_name != 'pull_request'
4953 run : .github/scripts/use-cla-approved-github-bot.sh
5054
5155 - name : Store benchmark results
56+ if : github.event_name != 'pull_request'
5257 uses : benchmark-action/github-action-benchmark@4bdcce38c94cec68da58d012ac24b7b1155efe8b # v1.20.7
5358 with :
5459 tool : ' jmh'
5762 github-token : ${{ secrets.GITHUB_TOKEN }}
5863 benchmark-data-dir-path : " benchmarks"
5964 auto-push : true
65+
66+ - name : Upload benchmark results (PR)
67+ if : github.event_name == 'pull_request'
68+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
69+ with :
70+ name : jmh-result.json
71+ path : sdk/trace/build/jmh-result.json
72+
73+ - name : Comment benchmark results on PR
74+ if : github.event_name == 'pull_request'
75+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
76+ with :
77+ script : |
78+ const fs = require('fs');
79+ const results = JSON.parse(fs.readFileSync('sdk/trace/build/jmh-result.json', 'utf8'));
80+
81+ let comment = '## Benchmark Results\n\n';
82+ comment += '| Benchmark | Score | Unit |\n';
83+ comment += '|-----------|-------|------|\n';
84+
85+ results.forEach(result => {
86+ const score = result.primaryMetric.score.toFixed(2);
87+ const unit = result.primaryMetric.scoreUnit;
88+ comment += `| ${result.benchmark} | ${score} | ${unit} |\n`;
89+ });
90+
91+ comment += '\nFull results are available as an artifact named `jmh-result.json`';
92+
93+ github.rest.issues.createComment({
94+ issue_number: context.issue.number,
95+ owner: context.repo.owner,
96+ repo: context.repo.repo,
97+ body: comment
98+ });
0 commit comments