|
|
|
@ -2,7 +2,6 @@ from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
import os
|
|
|
|
|
from dataclasses import asdict
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Iterator
|
|
|
|
@ -24,12 +23,16 @@ def load_cache_file() -> AnyDict:
|
|
|
|
|
|
|
|
|
|
def load_branches_cache() -> dict[str, BranchInfo]:
|
|
|
|
|
cache_dict = load_cache_file()["branches"]
|
|
|
|
|
return {key: BranchInfo(**value) for key, value in cache_dict.items()}
|
|
|
|
|
return {key: BranchInfo.from_dict(value) for key, value in cache_dict.items()}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_metadata_cache() -> AnyDict:
|
|
|
|
|
return load_cache_file()["metadata"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_cache(cache_dict: dict[str, BranchInfo]) -> None:
|
|
|
|
|
CACHE.update(cache_dict)
|
|
|
|
|
json_writable_cache_dict = {key: asdict(value) for key, value in CACHE.items()}
|
|
|
|
|
json_writable_cache_dict = {key: value.to_dict() for key, value in CACHE.items()}
|
|
|
|
|
content = {
|
|
|
|
|
"branches": json_writable_cache_dict,
|
|
|
|
|
"metadata": {
|
|
|
|
@ -71,12 +74,17 @@ def yield_recently_updated_gh_pr_branches() -> Iterator[BranchInfo]:
|
|
|
|
|
branch_name = pr["head"]["ref"]
|
|
|
|
|
print(f"Getting branch {branch_name}")
|
|
|
|
|
|
|
|
|
|
# Skip when we already have this commit in cache
|
|
|
|
|
# Skip when we already have this commit in cache (and pipeline is finished)
|
|
|
|
|
if branch_name in CACHE:
|
|
|
|
|
cache_info = CACHE[branch_name]
|
|
|
|
|
if cache_info.last_commit_sha == last_commit_sha:
|
|
|
|
|
print(f"Skipping, commit did not change - {last_commit_sha}")
|
|
|
|
|
continue
|
|
|
|
|
still_running = False
|
|
|
|
|
for job_info in cache_info.job_infos.values():
|
|
|
|
|
if job_info.status == "Running...":
|
|
|
|
|
still_running = True
|
|
|
|
|
if not still_running:
|
|
|
|
|
print(f"Skipping, commit did not change - {last_commit_sha}")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
# It can come from a fork - we do not have UI tests for it
|
|
|
|
|
if branch_name == "master":
|
|
|
|
@ -84,12 +92,21 @@ def yield_recently_updated_gh_pr_branches() -> Iterator[BranchInfo]:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
last_commit_timestamp = get_commit_ts(last_commit_sha)
|
|
|
|
|
last_commit_datetime = datetime.fromtimestamp(last_commit_timestamp).isoformat()
|
|
|
|
|
last_commit_datetime = datetime.fromtimestamp(last_commit_timestamp).strftime(
|
|
|
|
|
"%Y-%m-%d %H:%M"
|
|
|
|
|
)
|
|
|
|
|
pull_request_number = pr["number"]
|
|
|
|
|
pull_request_link = (
|
|
|
|
|
f"https://github.com/trezor/trezor-firmware/pull/{pull_request_number}"
|
|
|
|
|
)
|
|
|
|
|
branch_link = f"https://github.com/trezor/trezor-firmware/tree/{branch_name}"
|
|
|
|
|
|
|
|
|
|
yield BranchInfo(
|
|
|
|
|
name=branch_name,
|
|
|
|
|
pull_request_number=pr["number"],
|
|
|
|
|
branch_link=branch_link,
|
|
|
|
|
pull_request_number=pull_request_number,
|
|
|
|
|
pull_request_name=pr["title"],
|
|
|
|
|
pull_request_link=pull_request_link,
|
|
|
|
|
last_commit_sha=last_commit_sha,
|
|
|
|
|
last_commit_timestamp=last_commit_timestamp,
|
|
|
|
|
last_commit_datetime=last_commit_datetime,
|
|
|
|
|