Skip to content

Commit

Permalink
add function to determine comment id for a job and use it
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
truib committed Feb 12, 2024
1 parent 7d822c4 commit 33128c3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tasks/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}'")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 33128c3

Please sign in to comment.