Skip to content

Commit c991345

Browse files
kristapraticol0lawrence
authored andcommitted
add test samples tracking (Azure#38502)
* add test samples tracking * add samples tracking to csv/html/md reports * fix for catastrophic pipeline failure
1 parent 39064fa commit c991345

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

scripts/repo_health_status_report/output_health_report.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class TestsPipelineResult(typing.TypedDict, total=False):
108108
link: str
109109
result: DEVOPS_BUILD_STATUS
110110
tests: CheckStatus
111+
samples: CheckStatus
111112

112113

113114
class CIPipelineResult(typing.TypedDict, total=False):
@@ -152,6 +153,7 @@ class LibraryStatus(typing.TypedDict, total=False):
152153
sphinx: Status
153154
sdk_owned: bool
154155
tests: Status
156+
samples: Status
155157
ci: Status
156158

157159

@@ -224,6 +226,18 @@ def skip_package(package_name: str) -> bool:
224226
)
225227

226228

229+
def samples_enabled(package_path: pathlib.Path) -> bool:
230+
tests_yaml = package_path.parent / "tests.yml"
231+
if not tests_yaml.exists():
232+
return False
233+
with open(tests_yaml, "r") as file:
234+
parameters = file.read()
235+
236+
if "TestSamples=.*/true" in parameters:
237+
return True
238+
return False
239+
240+
227241
def get_dataplane(
228242
include_sdk_owned: bool = True,
229243
) -> dict[ServiceDirectory, dict[LibraryName, LibraryStatus]]:
@@ -336,6 +350,7 @@ def record_all_pipeline(
336350
{
337351
"result": status,
338352
"tests": CheckStatus(status=status),
353+
"samples": CheckStatus(status=status),
339354
}
340355
)
341356
)
@@ -367,7 +382,7 @@ def record_all_library(details: LibraryStatus, status: CHECK_STATUS) -> None:
367382
details["sphinx"] = Status(status=status, link=None)
368383
details["ci"] = Status(status=status, link=None)
369384
details["tests"] = Status(status=status, link=None)
370-
385+
details["samples"] = Status(status=status, link=None)
371386

372387
def get_ci_result(service: str, pipeline_id: int | None, pipelines: dict[ServiceDirectory, PipelineResults]) -> None:
373388
if not pipeline_id:
@@ -393,6 +408,9 @@ def get_ci_result(service: str, pipeline_id: int | None, pipelines: dict[Service
393408
pipelines[service]["ci"].update({"result": result["result"]})
394409
build_id = result["id"]
395410
timeline_response = httpx.get(get_build_timeline_url(build_id), headers=AUTH_HEADERS)
411+
if timeline_response.status_code != 200:
412+
record_all_pipeline("tests", pipelines[service], "UNKNOWN")
413+
return
396414
timeline_result = json.loads(timeline_response.text)
397415

398416
for task in timeline_result["records"]:
@@ -432,11 +450,16 @@ def get_tests_result(service: str, pipeline_id: int | None, pipelines: dict[Serv
432450
pipelines[service]["tests"].update({"result": result["result"]})
433451
build_id = result["id"]
434452
timeline_response = httpx.get(get_build_timeline_url(build_id), headers=AUTH_HEADERS)
453+
if timeline_response.status_code != 200:
454+
record_all_pipeline("tests", pipelines[service], "UNKNOWN")
455+
return
435456
timeline_result = json.loads(timeline_response.text)
436457

437458
for task in timeline_result["records"]:
438459
if "Run Tests" in task["name"]:
439460
record_test_result(task, "tests", pipelines[service]["tests"])
461+
if "Test Samples" in task["name"]:
462+
record_test_result(task, "samples", pipelines[service]["tests"])
440463

441464

442465
def get_tests_weekly_result(service: str, pipeline_id: int | None, pipelines: dict[ServiceDirectory, PipelineResults]) -> None:
@@ -459,6 +482,9 @@ def get_tests_weekly_result(service: str, pipeline_id: int | None, pipelines: di
459482
pipelines[service]["tests_weekly"].update({"result": result["result"]})
460483
build_id = result["id"]
461484
timeline_response = httpx.get(get_build_timeline_url(build_id), headers=AUTH_HEADERS)
485+
if timeline_response.status_code != 200:
486+
record_all_pipeline("tests", pipelines[service], "UNKNOWN")
487+
return
462488
timeline_result = json.loads(timeline_response.text)
463489

464490
for task in timeline_result["records"]:
@@ -506,6 +532,25 @@ def report_test_result(
506532
library_details[test_type] = Status(status="UNKNOWN", link=pipeline[test_type].get("link"))
507533

508534

535+
def report_samples_result(
536+
check: typing.Literal["samples"],
537+
pipeline: PipelineResults,
538+
library_details: LibraryStatus,
539+
) -> None:
540+
enabled = samples_enabled(library_details["path"])
541+
if not enabled:
542+
library_details[check] = Status(status="DISABLED", link=None)
543+
return
544+
545+
ci_check = pipeline["tests"][check]["status"]
546+
if ci_check == "succeeded":
547+
library_details[check] = Status(status="PASS", link=pipeline["tests"]["link"])
548+
elif ci_check == "failed":
549+
library_details[check] = Status(status="FAIL", link=pipeline["tests"]["link"])
550+
else:
551+
library_details[check] = Status(status="UNKNOWN", link=pipeline["tests"].get("link"))
552+
553+
509554
def report_check_result(
510555
check: CheckTypes,
511556
pipeline: PipelineResults,
@@ -558,6 +603,7 @@ def report_status(
558603
details["type_check_samples"] = (
559604
"ENABLED" if is_check_enabled(str(details["path"]), "type_check_samples") else "DISABLED"
560605
)
606+
report_samples_result("samples", pipelines[service_directory], details)
561607
details["sdk_owned"] = details["path"].name in SDK_TEAM_OWNED
562608
report_test_result("tests", pipelines[service_directory], details)
563609
report_test_result("ci", pipelines[service_directory], details)
@@ -687,6 +733,7 @@ def write_to_csv(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStat
687733
"Sphinx",
688734
"Tests - CI",
689735
"Tests - Live",
736+
"Tests - Samples",
690737
"SLA - Questions",
691738
"SLA - Bugs",
692739
"Total customer-reported issues",
@@ -696,6 +743,7 @@ def write_to_csv(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStat
696743
"Sphinx_link",
697744
"Tests - CI_link",
698745
"Tests - Live_link",
746+
"Tests - Samples_link",
699747
"SLA - Questions_link",
700748
"SLA - Bugs_link",
701749
"Total customer-reported issues_link",
@@ -718,6 +766,7 @@ def write_to_csv(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStat
718766
details["sphinx"]["status"],
719767
details["ci"]["status"],
720768
details["tests"]["status"],
769+
details["samples"]["status"],
721770
details.get("sla", {}).get("question", {}).get("num", 0),
722771
details.get("sla", {}).get("bug", {}).get("num", 0),
723772
details.get("customer_issues", {}).get("num", 0),
@@ -727,6 +776,7 @@ def write_to_csv(libraries: dict[ServiceDirectory, dict[LibraryName, LibraryStat
727776
details["sphinx"].get("link", ""),
728777
details["ci"].get("link", ""),
729778
details["tests"].get("link", ""),
779+
details["samples"].get("link", ""),
730780
details.get("sla", {}).get("question", {}).get("link", ""),
731781
details.get("sla", {}).get("bug", {}).get("link", ""),
732782
details.get("customer_issues", {}).get("link", ""),
@@ -751,6 +801,7 @@ def write_to_markdown(libraries: dict[ServiceDirectory, dict[LibraryName, Librar
751801
"Sphinx",
752802
"Tests - CI",
753803
"Tests - Live",
804+
"Tests - Samples",
754805
"SLA - Questions / Bugs",
755806
"Total customer-reported issues",
756807
]
@@ -795,6 +846,8 @@ def write_to_markdown(libraries: dict[ServiceDirectory, dict[LibraryName, Librar
795846
+ (f" ([link]({details['ci']['link']}))" if details["ci"]["link"] is not None else ""),
796847
details["tests"]["status"]
797848
+ (f" ([link]({details['tests']['link']}))" if details["tests"]["link"] is not None else ""),
849+
details["samples"]["status"]
850+
+ (f" ([link]({details['samples']['link']}))" if details["samples"]["link"] is not None else ""),
798851
sla_str,
799852
str(details.get("customer_issues", {}).get("num", 0))
800853
+ (

0 commit comments

Comments
 (0)