From 941d92408ee53820cb37f294df3c20c799a569fa Mon Sep 17 00:00:00 2001 From: Eric Engestrom Date: Mon, 11 Sep 2023 14:58:17 +0100 Subject: [PATCH] bin/ci_run_n_monitor: automatically pick MR pipelines when they exist 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: --- bin/ci/ci_run_n_monitor.py | 7 +++++-- bin/ci/gitlab_common.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/bin/ci/ci_run_n_monitor.py b/bin/ci/ci_run_n_monitor.py index 4dc4e78..778f5ff 100755 --- a/bin/ci/ci_run_n_monitor.py +++ b/bin/ci/ci_run_n_monitor.py @@ -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}") diff --git a/bin/ci/gitlab_common.py b/bin/ci/gitlab_common.py index 99ebc0e..4b16878 100644 --- a/bin/ci/gitlab_common.py +++ b/bin/ci/gitlab_common.py @@ -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) -- 2.7.4