-
Notifications
You must be signed in to change notification settings - Fork 2
137 lines (112 loc) · 4.75 KB
/
Copy pathbenchmark.yml
File metadata and controls
137 lines (112 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: Benchmarks
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Run benchmarks
run: |
./mvnw clean test-compile exec:java -P benchmark -Djmh.options="-wi 2 -i 3 -f 1 -rf json -rff benchmark-results.json"
- name: Process benchmark results
if: always()
run: |
if [ -f benchmark-results.json ]; then
echo "## Benchmark Results" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# Extract and display results with jq
jq -r '.[] | "\(.benchmark): \(.primaryMetric.score) ± \(.primaryMetric.scoreError) \(.primaryMetric.scoreUnit)"' benchmark-results.json >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
# Check for performance regressions (fail if any benchmark takes >50ms)
FAILED=0
while IFS= read -r line; do
SCORE=$(echo "$line" | jq -r '.primaryMetric.score')
BENCHMARK=$(echo "$line" | jq -r '.benchmark')
# Convert to integer for comparison (assuming milliseconds)
SCORE_INT=$(echo "$SCORE" | cut -d. -f1)
if [ "$SCORE_INT" -gt 50 ]; then
echo "❌ Performance regression detected in $BENCHMARK: ${SCORE}ms exceeds 50ms threshold" >> $GITHUB_STEP_SUMMARY
FAILED=1
fi
done < <(jq -c '.[]' benchmark-results.json)
if [ "$FAILED" -eq 1 ]; then
echo "::error::Performance regression detected - one or more benchmarks exceeded the 50ms threshold"
exit 1
else
echo "✅ All benchmarks passed performance thresholds" >> $GITHUB_STEP_SUMMARY
fi
else
echo "::error::No benchmark results found"
exit 1
fi
- name: Upload benchmark results
if: always()
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: benchmark-results.json
retention-days: 30
- name: Comment PR with benchmark results
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
if (!fs.existsSync('benchmark-results.json')) {
console.log('No benchmark results found');
return;
}
const results = JSON.parse(fs.readFileSync('benchmark-results.json', 'utf8'));
let comment = '## 📊 Benchmark Results\n\n';
comment += '| Benchmark | Score | Error | Unit |\n';
comment += '|-----------|-------|-------|------|\n';
let hasRegression = false;
results.forEach(result => {
const score = result.primaryMetric.score;
const error = result.primaryMetric.scoreError;
const unit = result.primaryMetric.scoreUnit;
const benchmark = result.benchmark.split('.').pop();
// Check if score exceeds threshold
const emoji = score > 50 ? '🔴' : '🟢';
if (score > 50) hasRegression = true;
comment += `| ${emoji} ${benchmark} | ${score.toFixed(3)} | ±${error.toFixed(3)} | ${unit} |\n`;
});
if (hasRegression) {
comment += '\n⚠️ **Performance regression detected**: One or more benchmarks exceeded the 50ms threshold.\n';
} else {
comment += '\n✅ **All benchmarks passed** performance thresholds.\n';
}
// Find and update or create comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const botComment = comments.find(comment =>
comment.user.type === 'Bot' && comment.body.includes('📊 Benchmark Results')
);
if (botComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
}