From 0ae774cf9dc881917849c6763bce483b5ea1a83ba85d987665661b9dd9bc484b Mon Sep 17 00:00:00 2001 From: Nicolas Belouin Date: Mon, 19 Jan 2026 13:16:09 +0100 Subject: [PATCH] Make wait_obs script more reliable Signed-off-by: Nicolas Belouin --- .obs/wait_obs.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/.obs/wait_obs.py b/.obs/wait_obs.py index 001ce7c..9d8d3e6 100644 --- a/.obs/wait_obs.py +++ b/.obs/wait_obs.py @@ -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() -- 2.51.1