@@ -362,14 +362,18 @@ def main():
362362 # Initialize S3 client
363363 s3_client = boto3 .client ("s3" )
364364
365- # Statistics
365+ # Statistics and tracking
366366 stats = {
367367 "current_tagged" : 0 ,
368368 "orphaned_tagged" : 0 ,
369369 "orphaned_deleted" : 0 ,
370370 "errors" : 0 ,
371371 }
372372
373+ # Track orphaned directories for detailed reporting
374+ orphaned_directories = []
375+ current_directories = []
376+
373377 logger .info ("Starting tagging analysis..." )
374378
375379 for results_dir in s3_results_dirs :
@@ -393,6 +397,14 @@ def main():
393397 s3_client , s3_bucket , results_dir , tags , dry_run
394398 ):
395399 stats ["current_tagged" ] += 1
400+ current_directories .append (
401+ {
402+ "path" : results_dir ,
403+ "pipeline" : release_info ["pipeline" ],
404+ "version" : release_info ["version" ],
405+ "sha" : release_info ["sha" ][:12 ] + "..." ,
406+ }
407+ )
396408 logger .info (f"✅ Tagged current release: { results_dir } " )
397409 else :
398410 stats ["errors" ] += 1
@@ -412,6 +424,22 @@ def main():
412424 s3_client , s3_bucket , results_dir , tags , dry_run
413425 ):
414426 stats ["orphaned_tagged" ] += 1
427+ # Extract SHA from directory name for reporting
428+ sha_part = (
429+ results_dir .split ("/results-" )[- 1 ]
430+ if "/results-" in results_dir
431+ else "unknown"
432+ )
433+ orphaned_directories .append (
434+ {
435+ "path" : results_dir ,
436+ "pipeline" : pipeline_name ,
437+ "sha" : sha_part [:12 ] + "..."
438+ if len (sha_part ) > 12
439+ else sha_part ,
440+ "will_be_deleted" : enable_deletion ,
441+ }
442+ )
415443 logger .warning (f"🗑️ Tagged orphaned directory: { results_dir } " )
416444
417445 # Optionally delete if enabled
@@ -428,16 +456,73 @@ def main():
428456 stats ["errors" ] += 1
429457
430458 # Print final summary
431- logger .info ("=" * 60 )
459+ logger .info ("=" * 80 )
432460 logger .info ("S3 RESULTS TAGGING SUMMARY" )
433- logger .info ("=" * 60 )
434- logger .info (f"Current releases tagged: { stats ['current_tagged' ]} " )
435- logger .info (f"Orphaned directories tagged: { stats ['orphaned_tagged' ]} " )
461+ logger .info ("=" * 80 )
462+ logger .info ("📊 STATISTICS:" )
463+ logger .info (f" • Current releases tagged: { stats ['current_tagged' ]} " )
464+ logger .info (f" • Orphaned directories tagged: { stats ['orphaned_tagged' ]} " )
436465 if enable_deletion :
437- logger .info (f"Orphaned directories deleted: { stats ['orphaned_deleted' ]} " )
438- logger .info (f"Errors encountered: { stats ['errors' ]} " )
439- logger .info (f"Mode: { 'DRY RUN' if dry_run else 'LIVE' } " )
440- logger .info ("=" * 60 )
466+ logger .info (f" • Orphaned directories deleted: { stats ['orphaned_deleted' ]} " )
467+ logger .info (f" • Errors encountered: { stats ['errors' ]} " )
468+ logger .info (f" • Mode: { 'DRY RUN' if dry_run else 'LIVE' } " )
469+
470+ # Print current directories (if not too many)
471+ if current_directories :
472+ logger .info (f"\n ✅ CURRENT RELEASE DIRECTORIES ({ len (current_directories )} ):" )
473+ if len (current_directories ) <= 10 :
474+ for dir_info in current_directories [:10 ]:
475+ logger .info (
476+ f" • { dir_info ['pipeline' ]} v{ dir_info ['version' ]} ({ dir_info ['sha' ]} )"
477+ )
478+ else :
479+ for dir_info in current_directories [:5 ]:
480+ logger .info (
481+ f" • { dir_info ['pipeline' ]} v{ dir_info ['version' ]} ({ dir_info ['sha' ]} )"
482+ )
483+ logger .info (
484+ f" ... and { len (current_directories ) - 5 } more current releases"
485+ )
486+
487+ # Print orphaned directories with details
488+ if orphaned_directories :
489+ logger .info (
490+ f"\n 🗑️ ORPHANED DIRECTORIES TO BE TAGGED ({ len (orphaned_directories )} ):"
491+ )
492+ logger .info (
493+ " These directories will be tagged with 'deleteme=true' for cleanup:"
494+ )
495+ for dir_info in orphaned_directories :
496+ deletion_status = (
497+ "🗑️ WILL BE DELETED"
498+ if dir_info ["will_be_deleted" ]
499+ else "🏷️ TAGGED ONLY"
500+ )
501+ logger .info (
502+ f" • { dir_info ['path' ]} ({ dir_info ['sha' ]} ) - { deletion_status } "
503+ )
504+
505+ if not enable_deletion :
506+ logger .info (
507+ "\n 💡 NOTE: Deletion is disabled. Use --enable-deletion to actually remove orphaned directories."
508+ )
509+
510+ # Group by pipeline for easier reading
511+ pipeline_counts = {}
512+ for dir_info in orphaned_directories :
513+ pipeline = dir_info ["pipeline" ]
514+ pipeline_counts [pipeline ] = pipeline_counts .get (pipeline , 0 ) + 1
515+
516+ if len (pipeline_counts ) > 1 :
517+ logger .info ("\n 📋 ORPHANED DIRECTORIES BY PIPELINE:" )
518+ for pipeline , count in sorted (pipeline_counts .items ()):
519+ logger .info (f" • { pipeline } : { count } orphaned directories" )
520+ else :
521+ logger .info (
522+ "\n ✨ No orphaned directories found - all results directories are current!"
523+ )
524+
525+ logger .info ("=" * 80 )
441526
442527 # Exit with error code if there were significant issues
443528 if stats ["errors" ] > len (s3_results_dirs ) * 0.1 : # More than 10% errors
0 commit comments