2024-03-22 16:45:26 +00:00
|
|
|
"""
|
|
|
|
Helper functions for communication with GitHub.
|
|
|
|
|
|
|
|
Allowing for interaction with the test results, e.g. with UI tests.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from pathlib import Path
|
|
|
|
from typing import Any, Iterable, Iterator
|
|
|
|
|
|
|
|
import requests
|
|
|
|
|
2024-09-10 13:36:26 +00:00
|
|
|
from trezorlib import models
|
|
|
|
|
2024-03-22 16:45:26 +00:00
|
|
|
AnyDict = dict[Any, Any]
|
|
|
|
|
|
|
|
HERE = Path(__file__).parent
|
|
|
|
|
|
|
|
LIST_RUNS_TEMPLATE = "https://api.github.com/repos/trezor/trezor-firmware/actions/workflows/{workflow}/runs?branch={branch}"
|
|
|
|
FIXTURES_TEMPLATE = "https://data.trezor.io/dev/firmware/ui_report/{run}/{model}-{lang}-{job}/fixtures.results.json"
|
|
|
|
|
2024-09-10 13:36:26 +00:00
|
|
|
MODELS = [model.internal_name for model in models.TREZORS]
|
2024-11-05 15:21:20 +00:00
|
|
|
CORE_LANGUAGES = ["en", "cs", "de", "es", "fr", "it", "pt", "tr"]
|
|
|
|
CORE_JOBS = ["core_device_test", "core_click_test", "core_persistence_test"]
|
|
|
|
LEGACY_LANGUAGES = ["en"]
|
|
|
|
LEGACY_JOBS = ["legacy_device_test"]
|
|
|
|
|
|
|
|
|
|
|
|
def get_last_run(branch_name: str, workflow: str) -> int | None:
|
|
|
|
response = requests.get(
|
|
|
|
LIST_RUNS_TEMPLATE.format(branch=branch_name, workflow=workflow)
|
|
|
|
)
|
|
|
|
response.raise_for_status()
|
|
|
|
try:
|
|
|
|
return response.json()["workflow_runs"][0]["id"]
|
|
|
|
except IndexError:
|
|
|
|
print(f"No workflow runs found for {workflow}")
|
|
|
|
return None
|
2024-03-22 16:45:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_branch_ui_fixtures_results(
|
|
|
|
branch_name: str,
|
|
|
|
only_jobs: Iterable[str] | None,
|
|
|
|
exclude_jobs: Iterable[str] | None,
|
2024-06-06 13:58:19 +00:00
|
|
|
run_id: int | None,
|
2024-03-22 16:45:26 +00:00
|
|
|
) -> dict[str, AnyDict]:
|
|
|
|
print(f"Checking branch {branch_name}")
|
|
|
|
|
2024-11-05 15:21:20 +00:00
|
|
|
core_run_id = run_id or get_last_run(branch_name, "core.yml")
|
|
|
|
legacy_run_id = run_id or get_last_run(branch_name, "legacy.yml")
|
2024-03-22 16:45:26 +00:00
|
|
|
|
|
|
|
def yield_key_value() -> Iterator[tuple[str, AnyDict]]:
|
|
|
|
for model in MODELS:
|
2024-11-05 15:21:20 +00:00
|
|
|
if model == "T1B1":
|
|
|
|
run_id = legacy_run_id
|
|
|
|
jobs = LEGACY_JOBS
|
|
|
|
languages = LEGACY_LANGUAGES
|
|
|
|
else:
|
|
|
|
run_id = core_run_id
|
|
|
|
jobs = CORE_JOBS
|
|
|
|
languages = CORE_LANGUAGES
|
|
|
|
|
|
|
|
if run_id is None:
|
|
|
|
continue
|
|
|
|
|
|
|
|
for lang in languages:
|
|
|
|
for job in jobs:
|
2024-03-22 16:45:26 +00:00
|
|
|
job_instance = f"{model}-{lang}-{job}"
|
|
|
|
|
|
|
|
if only_jobs and all(
|
|
|
|
(job not in job_instance) for job in only_jobs
|
|
|
|
):
|
|
|
|
continue
|
|
|
|
if exclude_jobs and any(
|
|
|
|
(job in job_instance) for job in exclude_jobs
|
|
|
|
):
|
|
|
|
continue
|
|
|
|
|
|
|
|
response = requests.get(
|
|
|
|
FIXTURES_TEMPLATE.format(
|
|
|
|
run=run_id, model=model, lang=lang, job=job
|
|
|
|
)
|
|
|
|
)
|
|
|
|
if response.status_code != 200:
|
|
|
|
print(
|
|
|
|
f"Failed to get fixtures for {job_instance}: {response.status_code}"
|
|
|
|
)
|
|
|
|
continue
|
|
|
|
yield job_instance, response.json()
|
|
|
|
|
|
|
|
return dict(yield_key_value())
|