fix(runner): surface harbor repair runner label
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 0s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Failing after 28s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped

This commit is contained in:
Your Name
2026-06-30 21:06:23 +08:00
parent 58aac02e5c
commit 47eae00ce8
2 changed files with 103 additions and 6 deletions

View File

@@ -11,6 +11,7 @@ import urllib.request
from dataclasses import dataclass
from pathlib import Path
from typing import Any
from urllib.parse import unquote
DEFAULT_ACTIONS_URL = "https://gitea.wooo.work/wooo/awoooi/actions"
@@ -45,6 +46,11 @@ _RUN_STATUS_RE = re.compile(r'<span data-tooltip-content="([^"]+)">')
_RUN_BODY_RE = re.compile(r"<span><b>([^<]+)</b>:</span>\s*([^<]+)", re.S)
_RUN_COMMIT_RE = re.compile(r"/wooo/awoooi/commit/([0-9a-f]{40})")
_RUN_NAME_RE = re.compile(r"^(?P<workflow>.+)\s+#(?P<run_id>\d+)$")
_WORKFLOW_FILTER_ITEM_RE = re.compile(
r'<a class="item" href="\?workflow=(?P<workflow>[^"&]+)[^"]*">'
r"(?P<body>.*?)</a>",
re.S,
)
_NO_MATCHING_LABEL_RE = re.compile(
r"No matching online runner with label:\s*(?P<label>[A-Za-z0-9_.:-]+)"
)
@@ -136,6 +142,17 @@ def parse_visible_runs(actions_html: str) -> list[dict[str, str]]:
return visible_runs
def parse_workflow_no_matching_labels(actions_html: str) -> dict[str, str]:
labels: dict[str, str] = {}
for match in _WORKFLOW_FILTER_ITEM_RE.finditer(actions_html):
label_match = _NO_MATCHING_LABEL_RE.search(match.group("body"))
if not label_match:
continue
workflow = html.unescape(unquote(match.group("workflow"))).strip()
labels[workflow] = label_match.group("label")
return labels
def _visible_run_from_parts(
*,
raw_status: str,
@@ -180,10 +197,18 @@ def build_readback(
latest_cd_tests_log_text: str = "",
) -> dict[str, Any]:
visible_runs = parse_visible_runs(actions_html)
workflow_no_matching_labels = parse_workflow_no_matching_labels(actions_html)
no_matching = next(
(run for run in visible_runs if run["no_matching_runner_label"]),
{},
)
workflow_no_matching = next(
(
{"workflow": workflow, "no_matching_runner_label": label}
for workflow, label in workflow_no_matching_labels.items()
),
{},
)
latest_cd_run = next(
(run for run in visible_runs if run.get("workflow") == "cd.yaml"),
{},
@@ -278,6 +303,10 @@ def build_readback(
latest_cd_visible_blocked = latest_cd_run.get("status", "") == "Blocked"
harbor_110_repair_status = latest_harbor_110_repair_run.get("status", "")
harbor_110_repair_run_id = latest_harbor_110_repair_run.get("run_id", "")
harbor_110_repair_no_matching_runner_label = (
latest_harbor_110_repair_run.get("no_matching_runner_label", "")
or workflow_no_matching_labels.get("harbor-110-local-repair.yaml", "")
)
harbor_110_repair_waiting = harbor_110_repair_status == "Waiting"
harbor_110_repair_running = harbor_110_repair_status == "Running"
harbor_110_repair_blocked = harbor_110_repair_status == "Blocked"
@@ -327,13 +356,15 @@ def build_readback(
"cd_run_jobs_stale_or_mismatched": cd_jobs_stale_or_mismatched,
"latest_visible_no_matching_runner_run_id": no_matching.get("run_id", ""),
"latest_visible_no_matching_runner_workflow": no_matching.get(
"workflow", ""
"workflow", workflow_no_matching.get("workflow", "")
),
"latest_visible_no_matching_runner_kind": no_matching.get("kind", ""),
"latest_visible_no_matching_runner_status": no_matching.get("status", ""),
"latest_visible_no_matching_runner_label": no_matching.get(
"no_matching_runner_label", ""
"no_matching_runner_label",
workflow_no_matching.get("no_matching_runner_label", ""),
),
"workflow_no_matching_runner_labels": workflow_no_matching_labels,
"latest_visible_cd_run_id": latest_cd_run.get("run_id", ""),
"latest_visible_cd_run_status": latest_cd_run.get("status", ""),
"latest_visible_cd_run_blocked": latest_cd_visible_blocked,
@@ -379,7 +410,7 @@ def build_readback(
latest_harbor_110_repair_run.get("commit_sha", "")
),
"latest_visible_harbor_110_repair_no_matching_runner_label": (
latest_harbor_110_repair_run.get("no_matching_runner_label", "")
harbor_110_repair_no_matching_runner_label
),
"latest_visible_harbor_110_repair_waiting": harbor_110_repair_waiting,
"latest_visible_harbor_110_repair_running": harbor_110_repair_running,
@@ -431,7 +462,8 @@ def build_readback(
"latest_visible_cd_host_pressure_refused": tests_log_classifier[
"host_pressure_refused"
],
"no_matching_online_runner_visible": bool(no_matching),
"no_matching_online_runner_visible": bool(no_matching)
or bool(workflow_no_matching_labels),
"top_visible_runs": visible_runs[:10],
}
return {
@@ -461,6 +493,10 @@ def build_readback(
if tests_log_classifier["host_pressure_blocked_or_waiting"]
else "harbor_110_repair_jobs_stale_or_mismatched"
if harbor_110_repair_jobs_stale_or_mismatched
else "blocked_harbor_110_repair_no_matching_runner"
if harbor_110_repair_no_matching_runner_label
else "blocked_no_matching_online_runner"
if workflow_no_matching
else "harbor_110_repair_waiting_for_runner_or_queue"
if harbor_110_repair_waiting
else "harbor_110_repair_running"
@@ -501,7 +537,8 @@ def build_readback(
"current_main_cd_host_pressure_refused": tests_log_classifier[
"host_pressure_refused"
],
"no_matching_online_runner_visible": bool(no_matching),
"no_matching_online_runner_visible": bool(no_matching)
or bool(workflow_no_matching_labels),
"harbor_110_repair_run_visible": bool(latest_harbor_110_repair_run),
"harbor_110_repair_run_status": harbor_110_repair_status,
"harbor_110_repair_waiting": harbor_110_repair_waiting,
@@ -511,7 +548,7 @@ def build_readback(
harbor_110_repair_waiting_after_cd_harbor_blocker
),
"harbor_110_repair_no_matching_runner_label": (
latest_harbor_110_repair_run.get("no_matching_runner_label", "")
harbor_110_repair_no_matching_runner_label
),
"harbor_110_repair_jobs_total_count": harbor_jobs_total_count,
"harbor_110_repair_jobs_names": sorted(harbor_job_names),

View File

@@ -125,6 +125,18 @@ def _actions_html_cd_running_harbor_repair_waiting() -> str:
"""
def _actions_html_harbor_repair_waiting_with_workflow_no_matching() -> str:
return """
<div class="menu">
<a class="item" href="?workflow=cd.yaml&actor=0&status=0">cd.yaml
</a>
<a class="item" href="?workflow=harbor-110-local-repair.yaml&actor=0&status=0">harbor-110-local-repair.yaml
<span data-tooltip-content="No matching online runner with label: awoooi-host"></span>
</a>
</div>
""" + _actions_html_cd_running_harbor_repair_waiting()
def _actions_html_failed_cd_run() -> str:
return """
<div class="flex-list run-list">
@@ -376,6 +388,54 @@ def test_build_readback_prioritizes_harbor_repair_jobs_stale_status() -> None:
assert payload["readback"]["latest_visible_harbor_110_repair_waiting"] is True
def test_build_readback_surfaces_harbor_110_repair_no_matching_runner() -> None:
module = _load_module()
payload = module.build_readback(
actions_html=_actions_html_harbor_repair_waiting_with_workflow_no_matching(),
actions_list_http_status=401,
actions_list_payload={"message": "token is required"},
cd_jobs_http_status=200,
cd_jobs_payload={"jobs": [], "total_count": 0},
)
assert payload["status"] == "blocked_harbor_110_repair_no_matching_runner"
assert payload["readback"]["latest_visible_harbor_110_repair_run_id"] == "4060"
assert (
payload["readback"][
"latest_visible_harbor_110_repair_no_matching_runner_label"
]
== "awoooi-host"
)
assert payload["readback"]["workflow_no_matching_runner_labels"] == {
"harbor-110-local-repair.yaml": "awoooi-host"
}
assert payload["readback"]["no_matching_online_runner_visible"] is True
assert (
payload["rollups"]["harbor_110_repair_no_matching_runner_label"]
== "awoooi-host"
)
def test_build_readback_prioritizes_harbor_repair_jobs_stale_over_no_matching() -> None:
module = _load_module()
payload = module.build_readback(
actions_html=_actions_html_harbor_repair_waiting_with_workflow_no_matching(),
actions_list_http_status=401,
actions_list_payload={"message": "token is required"},
cd_jobs_http_status=200,
cd_jobs_payload={"jobs": [], "total_count": 0},
harbor_110_repair_jobs_http_status=200,
harbor_110_repair_jobs_payload=_harbor_110_repair_stale_code_review_jobs(),
)
assert payload["status"] == "harbor_110_repair_jobs_stale_or_mismatched"
assert (
payload["readback"]["latest_visible_harbor_110_repair_no_matching_runner_label"]
== "awoooi-host"
)
assert payload["readback"]["harbor_110_repair_jobs_stale_or_mismatched"] is True
def test_build_readback_classifies_harbor_public_route_blocker() -> None:
module = _load_module()
payload = module.build_readback(