-
Notifications
You must be signed in to change notification settings - Fork 65
142 lines (121 loc) · 4.71 KB
/
benchmark.yml
File metadata and controls
142 lines (121 loc) · 4.71 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
138
139
140
141
142
name: Performance Benchmarks
on:
pull_request:
paths:
- 'internal/adapter/**'
- 'scripts/ci-benchmark-check.sh'
- 'scripts/perf-regressor.go'
- '.github/workflows/benchmark.yml'
push:
branches:
- main
paths:
- 'internal/adapter/**'
workflow_dispatch:
jobs:
benchmark:
name: Run Performance Benchmarks
runs-on: macos-latest # Use macOS for consistency with CI environment
timeout-minutes: 20
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch full history for baseline comparison
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
cache: true
- name: Create baseline directory
run: mkdir -p .benchmarks
- name: Download baseline from main
if: github.event_name == 'pull_request'
run: |
# Fetch baseline from main branch
git fetch origin main:main
git show main:.benchmarks/baseline.json > .benchmarks/baseline-main.json 2>/dev/null || {
echo "⚠️ Baseline not found on main branch, skipping regression check"
echo "To create baseline: scripts/benchmark-baseline.sh"
exit 0
}
mv .benchmarks/baseline-main.json .benchmarks/baseline.json
continue-on-error: true
- name: Run benchmark regression check
if: github.event_name == 'pull_request'
run: |
chmod +x scripts/ci-benchmark-check.sh
REGRESSION_THRESHOLD=10 scripts/ci-benchmark-check.sh
continue-on-error: true
env:
CI_COMMIT_SHA: ${{ github.sha }}
- name: Create baseline (main branch)
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
chmod +x scripts/benchmark-baseline.sh
scripts/benchmark-baseline.sh
# The baseline file is created as .benchmarks/baseline-<commit>.json
- name: Upload benchmark results
if: always()
uses: actions/upload-artifact@v3
with:
name: benchmark-reports
path: .benchmarks/
retention-days: 30
- name: Comment PR with results
if: github.event_name == 'pull_request' && always()
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
// Look for regression report
const reportFiles = fs.readdirSync('.benchmarks')
.filter(f => f.startsWith('regression-report'));
if (reportFiles.length === 0) {
console.log('No regression report found');
return;
}
const reportFile = path.join('.benchmarks', reportFiles[0]);
const report = JSON.parse(fs.readFileSync(reportFile, 'utf8'));
let comment = '## 📊 Performance Benchmark Results\n\n';
if (report.passed_threshold) {
comment += '✅ **All benchmarks passed!** No performance regressions detected.\n\n';
comment += `- Total benchmarks checked: ${report.total_benchmarks}\n`;
} else {
comment += '❌ **Performance regression detected**\n\n';
comment += `- Regressions: ${report.regression_count}/${report.total_benchmarks}\n`;
comment += '\n### Regressions\n\n';
for (const reg of report.regressions) {
comment += `- **${reg.benchmark}**: ${reg.degradation_percent}% slower\n`;
comment += ` - Threshold: ${reg.threshold_ms}ms\n`;
comment += ` - Actual: ${reg.actual_ms}ms\n`;
}
}
if (report.warnings && report.warnings.length > 0) {
comment += '\n### Warnings\n\n';
for (const warning of report.warnings) {
comment += `- ⚠️ ${warning}\n`;
}
}
comment += '\n**Regression threshold**: 10%\n';
comment += `**Report**: [Download](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
benchmark-summary:
name: Benchmark Summary
needs: benchmark
runs-on: ubuntu-latest
if: always()
steps:
- name: Check benchmark status
run: |
if [ "${{ needs.benchmark.result }}" == "failure" ]; then
echo "⚠️ Benchmark check completed with issues"
else
echo "✅ Benchmark check passed"
fi