Make wait_obs script more reliable #370

Merged
nbelouin merged 1 commits from nbelouin/Factory:improve_wait_obs into main 2026-01-19 16:25:23 +01:00

View File

@@ -6,6 +6,7 @@ import sys
from collections import Counter
def get_buildstatus(project: str) -> ET.Element:
for _ in range(5):
try:
@@ -17,8 +18,17 @@ def get_buildstatus(project: str) -> ET.Element:
continue
print("Failed to get buildstatus from OBS")
def do_wait(project:str, commit:str) -> ET.Element:
def do_wait(project: str, commit: str) -> ET.Element:
last_state = None
waiting_states = (
"blocked",
"scheduled",
"dispatching",
"building",
"signing",
"finished",
)
while True:
time.sleep(5)
status = get_buildstatus(project)
@@ -33,17 +43,25 @@ def do_wait(project:str, commit:str) -> ET.Element:
else:
last_state = status.get("state")
scminfo = { e.text for e in status.findall(".//scminfo") }
scminfo = {e.text for e in status.findall(".//scminfo")}
if len(scminfo) != 1 or scminfo.pop() != commit:
print("Waiting for OBS to sync with SCM")
continue
if not all([ e.get('state') == "published" and e.get('dirty') is None for e in status.findall("./result")]):
if not all(
[
e.get("state") == "published" # Only consider if all packages are published
and e.get("dirty") is None # Exclude states needing recalculation
and e.get("code") not in waiting_states # Exclude transient/waiting states
for e in status.findall("./result")
] + [ e.get("code") not in waiting_states for e in status.findall("./status") ]
):
print("Waiting for OBS to finish building")
continue
return status
def print_results(status: ET.Element) -> bool:
results = {}
failed = []
@@ -51,15 +69,15 @@ def print_results(status: ET.Element) -> bool:
repo = results.get(e.get("repository"), {})
repo[e.get("arch")] = e
results[e.get("repository")] = repo
for repo in results.keys():
print(f"{repo}:")
depth=1
depth = 1
for arch in results[repo].keys():
counts = Counter()
if repo != "charts":
print(f"\t{arch}:")
depth=2
depth = 2
for package in results[repo][arch].findall("./status"):
if package.get("code") in ["excluded", "disabled"]:
continue
@@ -70,9 +88,9 @@ def print_results(status: ET.Element) -> bool:
else:
failed.append(f"{package.get('package')} ({arch})")
counts[package.get("code")] += 1
for (code, count) in counts.items():
print("\t"*depth, f"{code}: {count}")
for code, count in counts.items():
print("\t" * depth, f"{code}: {count}")
failed.sort()
if failed:
print("\nPackages failing: ")
@@ -80,6 +98,7 @@ def print_results(status: ET.Element) -> bool:
print("\t", fail)
return len(failed)
def main():
project = os.environ.get("OBS_PROJECT")
sha = os.environ.get("GIT_SHA")
@@ -87,5 +106,6 @@ def main():
status = do_wait(project, sha)
sys.exit(print_results(status))
if __name__ == "__main__":
main()