-
Notifications
You must be signed in to change notification settings - Fork 39
288 lines (263 loc) Β· 10.7 KB
/
benchmark.yml
File metadata and controls
288 lines (263 loc) Β· 10.7 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
name: Autorouting Benchmark
on:
issue_comment:
types: [created]
pull_request:
types: [opened, reopened, synchronize, edited]
push:
branches:
- main
workflow_dispatch:
inputs:
solver_name:
description: 'Solver name to benchmark (optional, default: AutoroutingPipelineSolver; use "all" for all solvers)'
required: false
type: string
scenario_limit:
description: Number of scenarios to run (optional)
required: false
type: string
effort:
description: Effort multiplier to apply to each scenario (optional)
required: false
type: string
concurrency:
description: Number of workers per solver (or "auto")
required: false
default: "auto"
type: string
include_assignable:
description: Include assignable pipelines
required: false
default: false
type: boolean
ref:
description: Git ref (branch, tag, or SHA) to benchmark
required: false
type: string
permissions:
contents: read
issues: write
pull-requests: write
jobs:
benchmark:
name: Run benchmark
if: |
github.event_name == 'workflow_dispatch' || (
github.event_name == 'push' &&
github.ref_name == 'main'
) || (
github.event_name == 'pull_request' &&
contains(github.event.pull_request.title, '[BENCHMARK TEST]')
) || (
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
github.event.comment.user.type != 'Bot' &&
startsWith(github.event.comment.body, '/benchmark') &&
(
github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR'
)
)
runs-on: ${{ vars.BENCHMARK_RUNNER || 'blacksmith-32vcpu-ubuntu-2404-arm' }}
timeout-minutes: 60
steps:
- name: Parse benchmark command
id: parse
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
script: |
const isComment = context.eventName === 'issue_comment'
const allSolversAliases = new Set(['all', '_'])
const defaultSolver = 'AutoroutingPipelineSolver'
let solverName = defaultSolver
let scenarioLimit = ''
let effort = ''
let concurrency = 'auto'
let ref = context.sha
let statusCommentId = ''
let includeAssignable = false
if (isComment) {
const body = context.payload.comment.body.trim()
const tokens = body.split(/\s+/).slice(1)
const positional = []
for (let i = 0; i < tokens.length; i += 1) {
const token = tokens[i]
if (token === '--concurrency') {
concurrency = tokens[i + 1] || concurrency
i += 1
continue
}
if (token === '--effort') {
effort = tokens[i + 1] || effort
i += 1
continue
}
if (token === '--include-assignable') {
includeAssignable = true
continue
}
positional.push(token)
}
const requestedSolver = positional[0] || ''
const usesAllSolvers =
requestedSolver !== '' &&
allSolversAliases.has(requestedSolver.toLowerCase())
if (requestedSolver && !usesAllSolvers) {
solverName = positional[0]
}
if (positional[1]) {
scenarioLimit = positional[1]
}
if (usesAllSolvers) {
solverName = ''
}
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
})
ref = pr.data.head.sha
const statusComment = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `## π Autorouting Benchmark\n\nβ³ Running benchmark on \`${ref.slice(0, 7)}\`...\n\nπ Workflow: [View run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})`,
})
statusCommentId = String(statusComment.data.id)
}
if (context.eventName === 'workflow_dispatch') {
const inputs = context.payload.inputs || {}
const requestedSolver = (inputs.solver_name || '').trim()
if (requestedSolver) {
solverName = allSolversAliases.has(requestedSolver.toLowerCase())
? ''
: requestedSolver
}
scenarioLimit = (inputs.scenario_limit || '').trim()
effort = (inputs.effort || '').trim()
concurrency = (inputs.concurrency || concurrency).trim()
includeAssignable = inputs.include_assignable === true || inputs.include_assignable === 'true'
ref = (inputs.ref || '').trim() || ref
}
if (context.eventName === 'pull_request') {
ref = context.payload.pull_request.head.sha
}
core.setOutput('solver_name', solverName)
core.setOutput('scenario_limit', scenarioLimit)
core.setOutput('effort', effort)
core.setOutput('concurrency', concurrency)
core.setOutput('include_assignable', includeAssignable ? 'true' : 'false')
core.setOutput('ref', ref)
core.setOutput('status_comment_id', statusCommentId)
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ steps.parse.outputs.ref }}
- name: Setup bun
uses: oven-sh/setup-bun@v2
with:
bun-version: latest
- name: Install dependencies
run: bun install
- name: Run benchmark (PR)
env:
SOLVER_NAME: ${{ steps.parse.outputs.solver_name }}
SCENARIO_LIMIT: ${{ steps.parse.outputs.scenario_limit }}
EFFORT: ${{ steps.parse.outputs.effort }}
CONCURRENCY: ${{ steps.parse.outputs.concurrency }}
INCLUDE_ASSIGNABLE: ${{ steps.parse.outputs.include_assignable }}
BENCHMARK_TASK_TIMEOUT_PER_EFFORT_MS: ${{ vars.BENCHMARK_TASK_TIMEOUT_PER_EFFORT_MS || vars.BENCHMARK_TASK_TIMEOUT_MS || '60000' }}
BENCHMARK_HEARTBEAT_INTERVAL_MS: ${{ vars.BENCHMARK_HEARTBEAT_INTERVAL_MS || '30000' }}
BENCHMARK_TERMINATE_TIMEOUT_MS: ${{ vars.BENCHMARK_TERMINATE_TIMEOUT_MS || '1000' }}
run: |
chmod +x ./benchmark.sh
RESOLVED_CONCURRENCY="$CONCURRENCY"
if [ -z "$RESOLVED_CONCURRENCY" ] || [ "$RESOLVED_CONCURRENCY" = "auto" ]; then
RESOLVED_CONCURRENCY="$(getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 4)"
fi
echo "Using benchmark concurrency: $RESOLVED_CONCURRENCY"
CMD=(./benchmark.sh --concurrency "$RESOLVED_CONCURRENCY")
if [ -n "$SOLVER_NAME" ]; then
CMD+=(--solver "$SOLVER_NAME")
fi
if [ -n "$SCENARIO_LIMIT" ]; then
CMD+=(--scenario-limit "$SCENARIO_LIMIT")
fi
if [ -n "$EFFORT" ]; then
CMD+=(--effort "$EFFORT")
fi
if [ "$INCLUDE_ASSIGNABLE" = "true" ]; then
CMD+=(--include-assignable)
fi
"${CMD[@]}"
cp benchmark-result.txt benchmark-result-pr.txt
- name: Download main branch benchmark result
if: github.event_name == 'issue_comment'
env:
GH_TOKEN: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
run: |
RUN_ID=$(gh api "repos/${{ github.repository }}/actions/workflows/benchmark.yml/runs?branch=main&event=push&status=success&per_page=1" --jq '.workflow_runs[0].id' 2>/dev/null || echo "")
if [ -z "$RUN_ID" ] || [ "$RUN_ID" = "null" ]; then
echo "(no main branch benchmark result available)" > benchmark-result-main.txt
exit 0
fi
gh run download "$RUN_ID" --repo "${{ github.repository }}" --name benchmark-result --dir ./main-artifact 2>/dev/null || true
if [ -f ./main-artifact/benchmark-result.txt ]; then
cp ./main-artifact/benchmark-result.txt benchmark-result-main.txt
else
echo "(no main branch benchmark result available)" > benchmark-result-main.txt
fi
- name: Upload benchmark result
uses: actions/upload-artifact@v4
with:
name: benchmark-result
path: |
./benchmark-result.txt
./benchmark-result-pr.txt
./benchmark-result-main.txt
overwrite: true
- name: Post benchmark result comment
if: github.event_name == 'issue_comment'
uses: actions/github-script@v7
with:
github-token: ${{ secrets.TSCIRCUIT_BOT_GITHUB_TOKEN }}
script: |
const fs = require('node:fs')
const maxLength = 60000
const truncate = (s, max) => s.length > max ? `${s.slice(0, max)}\n\n...truncated...` : s
const prText = fs.existsSync('benchmark-result-pr.txt')
? fs.readFileSync('benchmark-result-pr.txt', 'utf8').trim()
: fs.readFileSync('benchmark-result.txt', 'utf8').trim()
const mainText = fs.existsSync('benchmark-result-main.txt')
? fs.readFileSync('benchmark-result-main.txt', 'utf8').trim()
: '(not available)'
const body = [
'## π Autorouting Benchmark Results',
'',
'<details>',
'<summary>π PR Results</summary>',
'',
'```',
truncate(prText, maxLength),
'```',
'</details>',
'',
'<details open>',
'<summary>π Main Branch Results</summary>',
'',
'```',
truncate(mainText, maxLength),
'```',
'</details>',
'',
`π¦ Artifact: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}`,
].join('\n')
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: Number('${{ steps.parse.outputs.status_comment_id }}'),
body,
})