2024-01-04 15:35:09 +00:00
|
|
|
import os
|
2024-07-12 13:10:13 +00:00
|
|
|
import re
|
2024-07-11 11:37:26 +00:00
|
|
|
import subprocess
|
2024-05-16 16:23:35 +00:00
|
|
|
from contextlib import contextmanager
|
2024-01-04 15:35:09 +00:00
|
|
|
from pathlib import Path
|
2024-07-12 13:10:13 +00:00
|
|
|
from typing import Any, Iterator, List, Union, Optional
|
2024-01-04 15:35:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WithIter(type):
|
|
|
|
def __iter__(cls):
|
|
|
|
return (v for k, v in cls.__dict__.items() if not k.startswith("_"))
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
def cd(path: Union[Path, str]) -> Iterator[None]:
|
|
|
|
oldpwd = os.getcwd()
|
|
|
|
os.chdir(path)
|
|
|
|
try:
|
|
|
|
yield
|
|
|
|
finally:
|
|
|
|
os.chdir(oldpwd)
|
2024-02-02 17:10:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
def is_hex(s):
|
|
|
|
try:
|
|
|
|
int(s, 16)
|
|
|
|
return True
|
|
|
|
except ValueError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2024-02-04 19:12:37 +00:00
|
|
|
def normalize_string(string: str) -> str:
|
2024-06-02 16:25:14 +00:00
|
|
|
res = string.lower()
|
|
|
|
for r in ((" ", "_"), ("(", "_"), (")", "_"), (",", "_"), ("/", "_"), ("-", "_")):
|
|
|
|
res = res.replace(*r)
|
|
|
|
return res
|
2024-02-04 19:12:37 +00:00
|
|
|
|
|
|
|
|
2024-02-02 17:10:47 +00:00
|
|
|
class GHActions:
|
|
|
|
@staticmethod
|
2024-02-04 19:12:37 +00:00
|
|
|
def print_in_group(group_name: str, lines: Union[Any, List[Any]]) -> None:
|
2024-02-02 17:10:47 +00:00
|
|
|
lines = list(lines)
|
|
|
|
print(f"::group::{group_name}")
|
|
|
|
for line in lines:
|
|
|
|
print(line)
|
|
|
|
print("::endgroup::")
|
2024-07-11 11:37:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Shell:
|
|
|
|
@classmethod
|
|
|
|
def run_strict(cls, command):
|
2024-07-15 16:18:15 +00:00
|
|
|
res = subprocess.run(
|
|
|
|
command,
|
2024-07-11 11:37:26 +00:00
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
text=True,
|
|
|
|
check=True,
|
|
|
|
)
|
2024-07-15 16:18:15 +00:00
|
|
|
return res.stdout.strip()
|
2024-07-11 11:37:26 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def run(cls, command):
|
|
|
|
res = ""
|
|
|
|
result = subprocess.run(
|
|
|
|
command,
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
text=True,
|
|
|
|
check=False,
|
|
|
|
)
|
|
|
|
if result.returncode == 0:
|
|
|
|
res = result.stdout
|
|
|
|
return res.strip()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def check(cls, command):
|
|
|
|
result = subprocess.run(
|
|
|
|
command + " 2>&1",
|
|
|
|
shell=True,
|
|
|
|
stdout=subprocess.PIPE,
|
|
|
|
stderr=subprocess.PIPE,
|
|
|
|
text=True,
|
|
|
|
check=False,
|
|
|
|
)
|
|
|
|
return result.returncode == 0
|
2024-07-12 13:10:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Utils:
|
|
|
|
@staticmethod
|
|
|
|
def get_failed_tests_number(description: str) -> Optional[int]:
|
|
|
|
description = description.lower()
|
|
|
|
|
|
|
|
pattern = r"fail:\s*(\d+)\s*(?=,|$)"
|
|
|
|
match = re.search(pattern, description)
|
|
|
|
if match:
|
|
|
|
return int(match.group(1))
|
|
|
|
return None
|
2024-07-13 18:15:47 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_killed_with_oom():
|
|
|
|
if Shell.check(
|
|
|
|
"sudo dmesg -T | grep -q -e 'Out of memory: Killed process' -e 'oom_reaper: reaped process' -e 'oom-kill:constraint=CONSTRAINT_NONE'"
|
|
|
|
):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def clear_dmesg():
|
|
|
|
Shell.run("sudo dmesg --clear ||:")
|