@@ -236,15 +236,14 @@ def append_artefact_to_upload_log(artefact, job_dir):
236236 upload_log .write (f"{ job_plus_artefact } \n " )
237237
238238
239- def upload_artefact (job_dir , artefact , timestamp , repo_name , pr_number , pr_comment_id ):
239+ def upload_artefact (job_dir , artefact , repo_name , pr_number , pr_comment_id ):
240240 """
241241 Upload artefact to an S3 bucket.
242242
243243 Args:
244244 job_dir (string): path to the job directory
245245 artefact (string): can be any filename that contains the payload, e.g., for
246246 EESSI it could have the format eessi-VERSION-COMPONENT-OS-ARCH-TIMESTAMP.tar.zstd
247- timestamp (int): timestamp of the artefact
248247 repo_name (string): repository of the pull request
249248 pr_number (int): number of the pull request
250249 pr_comment_id (int): id of the pull request comment
@@ -517,6 +516,33 @@ def determine_successful_jobs(job_dirs):
517516 return successes
518517
519518
519+ def parse_artefact_filename (filename ):
520+ """
521+ Determines components of an artefact's filename: prefix, timestamp, suffix
522+
523+ Args:
524+ filename (string): name of artefact with format A-B-C-...-N-TIMESTAMP.tar(.gz|.zstd|...)
525+
526+ Returns:
527+ tuple: (prefix, timestamp, suffix) or None if pattern doesn't match
528+ """
529+ funcname = sys ._getframe ().f_code .co_name
530+
531+ # capture everything before the last dash, then unix timestamp, then suffix
532+ pattern = r'^(.+)-(\d{10,})(\..+)$'
533+
534+ match = re .match (pattern , filename )
535+ if match :
536+ log (f"{ funcname } (): parsing '{ filename } ' matched" )
537+ prefix = match .group (1 )
538+ timestamp = match .group (2 )
539+ suffix = match .group (3 )
540+ return prefix , timestamp , suffix
541+
542+ log (f"{ funcname } (): parsing '{ filename } ' did NOT match" )
543+ return None
544+
545+
520546def determine_artefacts_to_deploy (successes , upload_policy ):
521547 """
522548 Determine artefacts to deploy depending on upload policy
@@ -551,21 +577,25 @@ def determine_artefacts_to_deploy(successes, upload_policy):
551577 artefact_base = os .path .basename (artefact )
552578 log (f"{ funcname } (): artefact filename: '{ artefact_base } '" )
553579
554- # artefact name format: PAYLOAD-TIMESTAMP.tar.gz
555- # remove "-TIMESTAMP.tar.gz" (last element when splitting along '-')
556- payload = "-" .join (artefact_base .split ("-" )[:- 1 ])
557- log (f"{ funcname } (): artefact payload '{ payload } '" )
580+ # artefact name format: PAYLOAD-TIMESTAMP.tar(.gz|.zstd|...)
581+ parse_result = parse_artefact_filename (artefact_base )
582+ if parse_result :
583+ prefix , timestamp , suffix = parse_result
584+ payload = prefix
585+ timestamp_int = int (timestamp )
558586
559- # timestamp in the filename
560- timestamp = int (artefact_base .split ("-" )[- 1 ][:- 7 ])
561- log (f"{ funcname } (): artefact timestamp { timestamp } " )
587+ log (f"{ funcname } (): artefact '{ artefact_base } ' parsed successfully" )
588+ log (f"{ funcname } (): payload={ payload } , timestamp={ timestamp_int } , suffix={ suffix } " )
589+ else :
590+ log (f"{ funcname } (): artefact '{ artefact_base } ' parsing failed" )
591+ continue
562592
563593 deploy = False
564594 if upload_policy == "all" :
565595 deploy = True
566596 elif upload_policy == "latest" :
567597 if payload in to_be_deployed :
568- if to_be_deployed [payload ]["timestamp" ] < timestamp :
598+ if to_be_deployed [payload ]["timestamp" ] < timestamp_int :
569599 # current one will be replaced
570600 deploy = True
571601 else :
@@ -580,9 +610,12 @@ def determine_artefacts_to_deploy(successes, upload_policy):
580610 f"{ indent_fname } has been uploaded through '{ uploaded } '" )
581611
582612 if deploy :
583- to_be_deployed [artefact ] = {"job_dir" : job ["job_dir" ],
584- "pr_comment_id" : job ["pr_comment_id" ],
585- "timestamp" : timestamp }
613+ to_be_deployed [payload ] = {"job_dir" : job ["job_dir" ],
614+ "pr_comment_id" : job ["pr_comment_id" ],
615+ "artefact" : artefact ,
616+ "payload" : payload ,
617+ "timestamp" : timestamp_int ,
618+ "suffix" : suffix }
586619
587620 return to_be_deployed
588621
@@ -649,8 +682,8 @@ def deploy_built_artefacts(pr, event_info):
649682 # 4) call function to deploy a single artefact per software subdir
650683 repo_name = pr .base .repo .full_name
651684
652- for artefact , job in to_be_deployed .items ():
685+ for job in to_be_deployed .values ():
653686 job_dir = job ['job_dir' ]
654- timestamp = job ['timestamp' ]
655687 pr_comment_id = job ['pr_comment_id' ]
656- upload_artefact (job_dir , artefact , timestamp , repo_name , pr .number , pr_comment_id )
688+ artefact = job ['artefact' ]
689+ upload_artefact (job_dir , artefact , repo_name , pr .number , pr_comment_id )
0 commit comments