bin/ci_run_n_monitor: automatically pick MR pipelines when they exist
authorEric Engestrom <eric@igalia.com>
Mon, 11 Sep 2023 13:58:17 +0000 (14:58 +0100)
committerMarge Bot <emma+marge@anholt.net>
Tue, 12 Sep 2023 17:42:34 +0000 (17:42 +0000)
When an MR has been created, we usually want to run the jobs in the MR
pipeline so that reviewers see that things work as expected.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25153>

bin/ci/ci_run_n_monitor.py
bin/ci/gitlab_common.py

index 4dc4e78..778f5ff 100755 (executable)
@@ -315,10 +315,13 @@ if __name__ == "__main__":
             pipe = cur_project.pipelines.get(pipeline_id)
             REV = pipe.sha
         else:
-            cur_project = get_gitlab_project(gl, args.project)
             if not REV:
                 REV = check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
-            pipe = wait_for_pipeline(cur_project, REV)
+            cur_project = gl.projects.get("mesa/mesa")
+            pipe = wait_for_pipeline(cur_project, REV, timeout=10)
+            if not pipe:
+                cur_project = get_gitlab_project(gl, args.project)
+                pipe = wait_for_pipeline(cur_project, REV)
 
         print(f"Revision: {REV}")
         print(f"Pipeline: {pipe.web_url}")
index 99ebc0e..4b16878 100644 (file)
@@ -30,13 +30,17 @@ def read_token(token_arg: Optional[str]) -> str:
     )
 
 
-def wait_for_pipeline(project, sha: str):
+def wait_for_pipeline(project, sha: str, timeout=None):
     """await until pipeline appears in Gitlab"""
     print(f"⏲ for the pipeline to appear in {project.path_with_namespace}..", end="")
+    start_time = time.time()
     while True:
         pipelines = project.pipelines.list(sha=sha)
         if pipelines:
             print("", flush=True)
             return pipelines[0]
         print("", end=".", flush=True)
+        if timeout and time.time() - start_time > timeout:
+            print(" not found", flush=True)
+            return None
         time.sleep(1)