|
1 | 1 | """ |
2 | | -Run the full server, UI and frontend suites on develop and version-16 every hour, and post a status on the |
| 2 | +Run the full server, UI and frontend suites on develop and version-16 after each push to develop and every |
| 3 | +three hours, and post a status on the |
3 | 4 | pull requests waiting to land there. Pull requests skip those suites, so this status is how they |
4 | 5 | see the branch: failing while the latest full run on it failed, unless the pull request carries |
5 | 6 | the fix label and the failing suites passed on it. |
|
12 | 13 | python branch_status.py pr <number> # one pull request |
13 | 14 | python branch_status.py commit <sha> # the pull requests whose head is this commit |
14 | 15 | python branch_status.py alert <run> # tell Raven when this full run failed, and which pull requests may have caused it |
15 | | - python branch_status.py alerts # tell Raven of every full run that failed since the last hourly check |
| 16 | + python branch_status.py alerts # wait for the full runs, then tell Raven of each suite whose latest run failed |
16 | 17 |
|
17 | 18 | The alert posts to the Raven incoming webhook in RAVEN_WEBHOOK_URL, or prints the message when it is unset. |
18 | 19 | """ |
@@ -223,7 +224,9 @@ def start(force): |
223 | 224 | for workflow in SUITES: |
224 | 225 | last = next(iter(branch_runs(workflow, branch)), None) |
225 | 226 | if not force and last: |
226 | | - if last["status"] != "completed" or last["head_sha"] == head: |
| 227 | + # Full runs of a suite on a branch share a concurrency group: a new one waits for the |
| 228 | + # running one, so a commit that lands mid-run is not left for the next check. |
| 229 | + if last["head_sha"] == head: |
227 | 230 | continue |
228 | 231 | changes = gh(f"repos/{REPO}/compare/{last['head_sha']}...{head}")["files"] |
229 | 232 | files = [ |
@@ -283,7 +286,7 @@ def alert(run_id): |
283 | 286 | if run["event"] != "workflow_dispatch" or branch not in BRANCHES or workflow not in SUITES: |
284 | 287 | return |
285 | 288 | state, job_url = suite_result(run, workflow) |
286 | | - if state != "failure": |
| 289 | + if state != "failure" or told(run): |
287 | 290 | return |
288 | 291 |
|
289 | 292 | earlier = [r for r in branch_runs(workflow, branch) if r["created_at"] < run["created_at"]] |
@@ -323,25 +326,56 @@ def alert(run_id): |
323 | 326 | ) |
324 | 327 | with urllib.request.urlopen(request, timeout=30): |
325 | 328 | print(f"Raven told: {suite} failed on {branch}") |
| 329 | + mark_told(run, job_url) |
| 330 | + |
| 331 | + |
| 332 | +# How long a check waits for the full runs to finish. The UI suite alone may take an hour. |
| 333 | +ALERT_WAIT = 80 * 60 |
326 | 334 |
|
327 | 335 |
|
328 | 336 | def alert_failures(): |
329 | | - """Tell Raven of the full runs that finished failing since the previous hourly check. Runs this |
330 | | - workflow starts with its own token finish without a workflow_run event, so the next check finds |
331 | | - them instead. Each run falls between two checks once, so it is told once.""" |
332 | | - checks = gh( |
333 | | - f"repos/{REPO}/actions/workflows/branch-status.yml/runs", params={"event": "schedule", "per_page": 5} |
334 | | - )["workflow_runs"] |
335 | | - this = os.environ.get("GITHUB_RUN_ID") |
336 | | - previous = next((check for check in checks if str(check["id"]) != this), None) |
337 | | - if not previous: |
338 | | - return |
339 | | - since = previous["run_started_at"] |
| 337 | + """Wait for the full runs on the tested branches to finish, then tell Raven of each suite whose |
| 338 | + latest run failed. Runs this workflow starts with its own token finish without a workflow_run |
| 339 | + event, so the check that started them waits for them instead.""" |
| 340 | + deadline = time.time() + ALERT_WAIT |
| 341 | + time.sleep(30) # A run just dispatched takes a moment to show in the list. |
| 342 | + while time.time() < deadline and any( |
| 343 | + run["status"] != "completed" |
| 344 | + for branch in BRANCHES |
| 345 | + for workflow in SUITES |
| 346 | + for run in branch_runs(workflow, branch)[:5] |
| 347 | + ): |
| 348 | + time.sleep(60) |
340 | 349 | for branch in BRANCHES: |
341 | 350 | for workflow in SUITES: |
342 | | - for run in branch_runs(workflow, branch): |
343 | | - if run["status"] == "completed" and run["updated_at"] >= since: |
344 | | - alert(run["id"]) |
| 351 | + run = latest_finished(workflow, branch) |
| 352 | + if run: |
| 353 | + alert(run["id"]) |
| 354 | + |
| 355 | + |
| 356 | +def latest_finished(workflow, branch): |
| 357 | + return next((r for r in branch_runs(workflow, branch) if suite_result(r, workflow)[0] != "pending"), None) |
| 358 | + |
| 359 | + |
| 360 | +def told_context(run): |
| 361 | + return f"Raven alert: {SUITES[os.path.basename(run['path'])]}" |
| 362 | + |
| 363 | + |
| 364 | +def told(run): |
| 365 | + """Was Raven told of this suite failing on this commit? Each check looks at the latest runs |
| 366 | + again, so a failure would be told once per check without this mark.""" |
| 367 | + statuses = gh(f"repos/{REPO}/commits/{run['head_sha']}/status")["statuses"] |
| 368 | + return any(status["context"] == told_context(run) for status in statuses) |
| 369 | + |
| 370 | + |
| 371 | +def mark_told(run, job_url): |
| 372 | + fields = { |
| 373 | + "state": "failure", |
| 374 | + "context": told_context(run), |
| 375 | + "description": "The team was told on Raven", |
| 376 | + "target_url": job_url, |
| 377 | + } |
| 378 | + gh(f"repos/{REPO}/statuses/{run['head_sha']}", method="POST", body=fields) |
345 | 379 |
|
346 | 380 |
|
347 | 381 | def refresh(): |
|
0 commit comments