-
Notifications
You must be signed in to change notification settings - Fork 303
297 lines (265 loc) · 9.74 KB
/
benchmark-baseline.yml
File metadata and controls
297 lines (265 loc) · 9.74 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
name: Benchmark Baseline
on:
# Runs nightly at 4:00 AM UTC
schedule:
- cron: "0 4 * * *"
# Allow manual triggers for ad-hoc baseline refreshes
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
DO_NOT_TRACK: "1"
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: "buildwithfern"
TURBO_NO_UPDATE_NOTIFIER: "1"
TURBO_DAEMON: "false"
jobs:
# Fetch specs once and share via artifact (avoids 9x redundant downloads)
fetch-specs:
runs-on: ubuntu-latest
timeout-minutes: 10
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout main
uses: actions/checkout@v6
with:
sparse-checkout: |
.github/actions/fetch-benchmark-specs
benchmarks/fern/apis
benchmarks/fern/api-versions.txt
- name: Fetch benchmark OpenAPI specs
uses: ./.github/actions/fetch-benchmark-specs
- name: Upload specs as shared artifact
uses: actions/upload-artifact@v6
with:
name: benchmark-specs
path: benchmarks/fern/apis/*/openapi.json
retention-days: 1
# Run generator-only benchmarks (--skip-scripts) for all SDK generators on main.
# This is the primary baseline that PR benchmarks compare against.
baseline:
runs-on: Seed
timeout-minutes: 60
needs: [fetch-specs]
if: ${{ github.ref == 'refs/heads/main' }}
strategy:
fail-fast: false
matrix:
generator:
[ts-sdk, python-sdk, java-sdk, go-sdk, csharp-sdk, ruby-sdk-v2, php-sdk, swift-sdk, rust-sdk]
steps:
- name: Checkout main
uses: actions/checkout@v6
- name: Install
uses: ./.github/actions/install
- name: Download shared specs
uses: actions/download-artifact@v7
with:
name: benchmark-specs
path: benchmarks/fern/apis
- name: Run benchmark (generator-only)
uses: ./.github/actions/run-benchmark
with:
generator: ${{ matrix.generator }}
skip-scripts: "true"
- name: Upload baseline results
if: always()
uses: actions/upload-artifact@v6
with:
name: benchmark-baseline-${{ matrix.generator }}
path: benchmark-results/
retention-days: 30
# Run full E2E benchmarks (with build/test scripts) for informational purposes.
# These capture the complete customer-observable generation time including
# npm install, compilation, and test execution.
baseline-e2e:
runs-on: Seed
timeout-minutes: 120
needs: [fetch-specs]
if: ${{ github.ref == 'refs/heads/main' }}
strategy:
fail-fast: false
matrix:
generator:
[ts-sdk, python-sdk, java-sdk, go-sdk, csharp-sdk, ruby-sdk-v2, php-sdk, swift-sdk, rust-sdk]
steps:
- name: Checkout main
uses: actions/checkout@v6
- name: Install
uses: ./.github/actions/install
- name: Download shared specs
uses: actions/download-artifact@v7
with:
name: benchmark-specs
path: benchmarks/fern/apis
- name: Run benchmark (full E2E)
uses: ./.github/actions/run-benchmark
with:
generator: ${{ matrix.generator }}
- name: Upload E2E results
if: always()
uses: actions/upload-artifact@v6
with:
name: benchmark-e2e-${{ matrix.generator }}
path: benchmark-results/
retention-days: 30
# Run docs generation benchmark on main.
# Uses --preview to create an ephemeral preview deployment (no production impact).
docs-baseline:
runs-on: Seed
timeout-minutes: 45
needs: [fetch-specs]
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout main
uses: actions/checkout@v6
- name: Install
uses: ./.github/actions/install
- name: Download shared specs
uses: actions/download-artifact@v7
with:
name: benchmark-specs
path: benchmarks/fern/apis
- name: Run docs benchmark
uses: ./.github/actions/run-docs-benchmark
with:
fern-token: ${{ secrets.FERN_FERN_TOKEN }}
- name: Upload docs baseline results
uses: actions/upload-artifact@v6
with:
name: benchmark-docs-baseline
path: benchmark-results/
retention-days: 30
# Send benchmark results to PostHog for long-term trend analysis and dashboards.
# Uses the same PostHog project + API key as seed test metrics (seed.yml).
# Fire-and-forget: failures here never affect cache save or downstream jobs.
post-metrics:
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [baseline, baseline-e2e, docs-baseline]
if: ${{ always() && !cancelled() && (needs.baseline.result != 'skipped' || needs.docs-baseline.result != 'skipped') }}
# No repo permissions needed — only makes outbound HTTPS calls to PostHog.
permissions: {}
steps:
- name: Download generator-only baseline artifacts
uses: actions/download-artifact@v7
with:
pattern: benchmark-baseline-*
path: baseline-results
merge-multiple: true
- name: Download E2E baseline artifacts
uses: actions/download-artifact@v7
with:
pattern: benchmark-e2e-*
path: e2e-results
merge-multiple: true
- name: Download docs baseline artifacts
uses: actions/download-artifact@v7
with:
pattern: benchmark-docs-baseline
path: docs-results
merge-multiple: true
- name: Send benchmark events to PostHog
shell: bash
env:
POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}
COMMIT_SHA: ${{ github.sha }}
RUN_ID: ${{ github.run_id }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
if [ -z "$POSTHOG_API_KEY" ]; then
echo "::warning::POSTHOG_API_KEY not set, skipping metrics"
exit 0
fi
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
SENT=0
FAILED=0
send_event() {
local mode="$1" generator="$2" spec="$3" duration="$4" exit_code="$5" skipped="$6"
local payload
payload=$(jq -n \
--arg api_key "$POSTHOG_API_KEY" \
--arg event "benchmark-baseline-result" \
--arg distinct_id "fern-ci-benchmark" \
--arg timestamp "$TIMESTAMP" \
--arg generator "$generator" \
--arg spec "$spec" \
--argjson duration_seconds "$duration" \
--argjson exit_code "$exit_code" \
--argjson skipped "$skipped" \
--arg mode "$mode" \
--arg branch "main" \
--arg commit_sha "$COMMIT_SHA" \
--arg run_id "$RUN_ID" \
--arg run_url "$RUN_URL" \
'{
api_key: $api_key,
event: $event,
distinct_id: $distinct_id,
timestamp: $timestamp,
properties: {
generator: $generator,
spec: $spec,
duration_seconds: $duration_seconds,
exit_code: $exit_code,
skipped: $skipped,
mode: $mode,
branch: $branch,
commit_sha: $commit_sha,
run_id: $run_id,
run_url: $run_url
}
}')
if ! curl -sf --max-time 10 -X POST https://us.i.posthog.com/capture/ \
-H "Content-Type: application/json" \
-d "$payload" 2>/dev/null; then
echo "::warning::Failed to send PostHog event for ${mode}/${generator}/${spec}"
FAILED=$((FAILED + 1))
else
SENT=$((SENT + 1))
fi
}
# Send generator-only results
for f in baseline-results/*.jsonl; do
[ -f "$f" ] || continue
while IFS= read -r line; do
gen=$(echo "$line" | jq -r '.generator')
spec=$(echo "$line" | jq -r '.spec')
dur=$(echo "$line" | jq -r '.duration_seconds')
ec=$(echo "$line" | jq -r '.exit_code // 0')
skip=$(echo "$line" | jq -r '.skipped // false')
send_event "generator-only" "$gen" "$spec" "$dur" "$ec" "$skip"
done < "$f"
done
# Send E2E results
for f in e2e-results/*.jsonl; do
[ -f "$f" ] || continue
while IFS= read -r line; do
gen=$(echo "$line" | jq -r '.generator')
spec=$(echo "$line" | jq -r '.spec')
dur=$(echo "$line" | jq -r '.duration_seconds')
ec=$(echo "$line" | jq -r '.exit_code // 0')
skip=$(echo "$line" | jq -r '.skipped // false')
send_event "e2e" "$gen" "$spec" "$dur" "$ec" "$skip"
done < "$f"
done
# Send docs benchmark results
for f in docs-results/*.jsonl; do
[ -f "$f" ] || continue
while IFS= read -r line; do
spec=$(echo "$line" | jq -r '.spec')
dur=$(echo "$line" | jq -r '.duration_seconds')
ec=$(echo "$line" | jq -r '.exit_code // 0')
skip=$(echo "$line" | jq -r '.skipped // false')
send_event "docs" "docs" "$spec" "$dur" "$ec" "$skip"
done < "$f"
done
echo "PostHog metrics: ${SENT} sent, ${FAILED} failed"
log-rejection:
runs-on: ubuntu-latest
timeout-minutes: 3
if: ${{ github.ref != 'refs/heads/main' }}
steps:
- name: Log rejection
run: echo "Benchmark baseline only runs on main. Current ref:${{ github.ref }}"