From 33128c38194f9038e591f491c59d7271b827ddd3 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 12 Feb 2024 13:29:16 +0100 Subject: [PATCH 1/3] add function to determine comment id for a job and use it - adds function `determine_pr_comment_id` which reads the attribute `pr_comment_id` from the job's metadata file (all current bot instances already provide that attribute when creating the job's metadata file) - the function is then used when successful jobs are determined (in function `determine_successful_jobs`) and the comment id is added to a dictionary that contains information for each job - another function (`determine_tarballs_to_deploy`) adds the comment id to a dictionary storing information about jobs/tarballs to deploy --- tasks/deploy.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tasks/deploy.py b/tasks/deploy.py index 39b85a7b..02f940b0 100644 --- a/tasks/deploy.py +++ b/tasks/deploy.py @@ -26,6 +26,7 @@ from tasks.build import CFG_DIRNAME, JOB_CFG_FILENAME, JOB_REPO_ID, JOB_REPOSITORY from tasks.build import get_build_env_cfg from tools import config, pr_comments, run_cmd +from tools.job_metadata import read_job_metadata_from_file BUCKET_NAME = "bucket_name" @@ -74,6 +75,26 @@ def determine_job_dirs(pr_number): return job_directories +def determine_pr_comment_id(job_dir): + """ + Determines pr_comment_id by reading _bot_job{JOBID}.metadata in job_dir. + + Args: + job_dir (string): working directory of the job + + Returns: + (int): id of comment corresponding to job in pull request or -1 + """ + # assumes that last part of job_dir encodes the job's id + job_id = os.path.basename(os.path.normpath(job_dir)) + job_metadata_file = os.path.join(job_dir, f"_bot_job{job_id}.metadata") + job_metadata = read_job_metadata_from_file(job_metadata_file) + if job_metadata and "pr_comment_id" in job_metadata: + return int(job_metadata["pr_comment_id"]) + else: + return -1 + + def determine_slurm_out(job_dir): """ Determine path to job stdout/err output file for a given job directory. @@ -371,10 +392,13 @@ def determine_successful_jobs(job_dirs): for job_dir in job_dirs: slurm_out = determine_slurm_out(job_dir) eessi_tarballs = determine_eessi_tarballs(job_dir) + pr_comment_id = determine_pr_comment_id(job_dir) + if check_build_status(slurm_out, eessi_tarballs): log(f"{funcname}(): SUCCESSFUL build in '{job_dir}'") successes.append({'job_dir': job_dir, 'slurm_out': slurm_out, + 'pr_comment_id': pr_comment_id, 'eessi_tarballs': eessi_tarballs}) else: log(f"{funcname}(): FAILED build in '{job_dir}'") @@ -448,6 +472,7 @@ def determine_tarballs_to_deploy(successes, upload_policy): if deploy: to_be_deployed[build_target] = {"job_dir": s["job_dir"], + "pr_comment_id": job["pr_comment_id"], "timestamp": timestamp} return to_be_deployed From c3b2d6da351c2b01da9add8d38570381be552405 Mon Sep 17 00:00:00 2001 From: Thomas Roeblitz Date: Mon, 12 Feb 2024 13:40:40 +0100 Subject: [PATCH 2/3] replaced one letter variable name with more descriptive name --- tasks/deploy.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasks/deploy.py b/tasks/deploy.py index 02f940b0..367c5785 100644 --- a/tasks/deploy.py +++ b/tasks/deploy.py @@ -427,9 +427,9 @@ def determine_tarballs_to_deploy(successes, upload_policy): log(f"{funcname}(): num successful jobs {len(successes)}") to_be_deployed = {} - for s in successes: + for job in successes: # all tarballs for successful job - tarballs = s["eessi_tarballs"] + tarballs = job["eessi_tarballs"] log(f"{funcname}(): num tarballs {len(tarballs)}") # full path to first tarball for successful job @@ -462,7 +462,7 @@ def determine_tarballs_to_deploy(successes, upload_policy): else: deploy = True elif upload_policy == "once": - uploaded = uploaded_before(build_target, s["job_dir"]) + uploaded = uploaded_before(build_target, job["job_dir"]) if uploaded is None: deploy = True else: @@ -471,7 +471,7 @@ def determine_tarballs_to_deploy(successes, upload_policy): f"{indent_fname}has been uploaded through '{uploaded}'") if deploy: - to_be_deployed[build_target] = {"job_dir": s["job_dir"], + to_be_deployed[build_target] = {"job_dir": job["job_dir"], "pr_comment_id": job["pr_comment_id"], "timestamp": timestamp} From 68e739d4f9aad3644dff1f0700cc2e5b1a9df3fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bob=20Dr=C3=B6ge?= Date: Tue, 13 Feb 2024 09:38:02 +0100 Subject: [PATCH 3/3] determines -> determine (to be consistent with other docstrings) --- tasks/deploy.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/deploy.py b/tasks/deploy.py index 367c5785..1287e2a5 100644 --- a/tasks/deploy.py +++ b/tasks/deploy.py @@ -77,7 +77,7 @@ def determine_job_dirs(pr_number): def determine_pr_comment_id(job_dir): """ - Determines pr_comment_id by reading _bot_job{JOBID}.metadata in job_dir. + Determine pr_comment_id by reading _bot_job{JOBID}.metadata in job_dir. Args: job_dir (string): working directory of the job