forked from nv-action/vllm-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_adapter.py
More file actions
298 lines (281 loc) · 8.4 KB
/
github_adapter.py
File metadata and controls
298 lines (281 loc) · 8.4 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
298
from __future__ import annotations
import json
import os
import subprocess
class GitHubCliAdapter:
def __init__(self, runner=None):
self._runner = runner or self._run
def list_open_pr_numbers(self, repo: str, label: str = "main2main") -> list[int]:
output = self._runner(
[
"gh",
"pr",
"list",
"--repo",
repo,
"--state",
"open",
"--label",
label,
"--json",
"number",
]
)
prs = json.loads(output)
return [int(pr["number"]) for pr in prs]
list_open_main2main_pr_numbers = list_open_pr_numbers
def get_pr_context(self, repo: str, pr_number: int) -> dict[str, object]:
output = self._runner(
[
"gh",
"pr",
"view",
str(pr_number),
"--repo",
repo,
"--json",
"number,headRefOid,headRefName,body,labels,state",
]
)
raw = json.loads(output)
return {
"pr_number": raw["number"],
"head_sha": raw["headRefOid"],
"branch": raw["headRefName"],
"state": raw["state"],
"labels": [label["name"] for label in raw["labels"]],
"body": raw["body"],
}
def get_registration_metadata(self, repo: str, pr_number: int):
from main2main_orchestrator import parse_registration_comment
injected_comment = os.environ.get("MAIN2MAIN_TEST_REGISTRATION_COMMENT")
if injected_comment:
return parse_registration_comment(injected_comment)
output = self._runner(
[
"gh",
"api",
f"repos/{repo}/issues/{pr_number}/comments",
]
)
comments = json.loads(output)
for comment in reversed(comments):
body = comment.get("body", "")
if not isinstance(body, str):
continue
if "main2main-register" not in body:
continue
return parse_registration_comment(body)
raise ValueError(f"registration metadata comment not found for PR #{pr_number}")
def dispatch_fixup(
self,
*,
repo: str,
pr_number: int,
branch: str,
head_sha: str,
run_id: str,
run_url: str,
conclusion: str,
phase: str,
old_commit: str,
new_commit: str,
dispatch_token: str,
) -> None:
self._runner(
[
"gh",
"workflow",
"run",
"main2main_auto.yaml",
"--repo",
repo,
"-f",
"mode=fixup",
"-f",
f"pr_number={pr_number}",
"-f",
f"branch={branch}",
"-f",
f"head_sha={head_sha}",
"-f",
f"run_id={run_id}",
"-f",
f"run_url={run_url}",
"-f",
f"conclusion={conclusion}",
"-f",
f"phase={phase}",
"-f",
f"old_commit={old_commit}",
"-f",
f"new_commit={new_commit}",
"-f",
f"dispatch_token={dispatch_token}",
]
)
def find_latest_fixup_run(
self,
*,
repo: str,
dispatch_token: str,
) -> dict[str, str] | None:
output = self._runner(
[
"gh",
"run",
"list",
"--repo",
repo,
"--workflow",
"main2main_auto.yaml",
"--json",
"databaseId,status,conclusion,url,event,displayTitle",
"-L",
"20",
]
)
runs = json.loads(output)
for run in runs:
if run.get("event") != "workflow_dispatch":
continue
if dispatch_token not in str(run.get("displayTitle") or ""):
continue
return {
"run_id": str(run["databaseId"]),
"status": str(run["status"]),
"conclusion": str(run.get("conclusion") or ""),
"run_url": str(run["url"]),
}
return None
def get_workflow_run(self, *, repo: str, run_id: str) -> dict[str, str]:
output = self._runner(
[
"gh",
"run",
"view",
run_id,
"--repo",
repo,
"--json",
"databaseId,status,conclusion,url",
]
)
raw = json.loads(output)
return {
"run_id": str(raw["databaseId"]),
"status": str(raw["status"]),
"conclusion": str(raw.get("conclusion") or ""),
"run_url": str(raw["url"]),
}
def mark_pr_ready(self, repo: str, pr_number: int) -> None:
self._runner(
[
"gh",
"pr",
"ready",
str(pr_number),
"--repo",
repo,
]
)
def create_manual_review_issue(self, *, repo: str, title: str, body: str) -> str:
return self._runner(
[
"gh",
"issue",
"create",
"--repo",
repo,
"--title",
title,
"--label",
"main2main",
"--body",
body,
]
).strip()
def wait_for_e2e_full(self, *, repo: str, head_sha: str) -> dict[str, str] | None:
output = self._runner(
[
"gh",
"run",
"list",
"--repo",
repo,
"--workflow",
"pr_test_full.yaml",
"--json",
"databaseId,workflowName,headSha,status,conclusion,url,createdAt",
"-L",
"20",
]
)
runs = json.loads(output)
matching_runs = []
for run in runs:
if run.get("workflowName") != "E2E-Full":
continue
if run.get("headSha") != head_sha:
continue
matching_runs.append(run)
if not matching_runs:
return None
if any(run.get("status") != "completed" for run in matching_runs):
return None
latest_run = max(
matching_runs,
key=lambda run: (
str(run.get("createdAt") or ""),
int(run.get("databaseId") or 0),
),
)
if latest_run.get("status") != "completed":
return None
return {
"run_id": str(latest_run["databaseId"]),
"head_sha": str(latest_run["headSha"]),
"conclusion": str(latest_run["conclusion"]),
"run_url": str(latest_run["url"]),
}
def get_fixup_outcome(self, *, repo: str, run_id: str, phase: str):
from main2main_orchestrator import parse_fixup_job_output
output = self._runner(
[
"gh",
"run",
"view",
run_id,
"--repo",
repo,
"--json",
"jobs",
]
)
raw = json.loads(output)
jobs = raw.get("jobs", [])
fixup_job = next((job for job in jobs if job.get("name") == "fixup"), None)
if fixup_job is None:
raise ValueError(f"fixup job not found in run {run_id}")
job_output = self._runner(
[
"gh",
"run",
"view",
run_id,
"--repo",
repo,
"--job",
str(fixup_job["databaseId"]),
]
)
return parse_fixup_job_output(job_output, phase=phase)
@staticmethod
def _run(args: list[str]) -> str:
completed = subprocess.run(
args,
check=True,
capture_output=True,
text=True,
)
return completed.stdout