@@ -574,20 +574,68 @@ def monitor_github_pr_checks(
574574 f"No GitHub Actions PR check workflows found after waiting { max_wait_minutes } minutes"
575575 )
576576
577+ def trigger_recommit (
578+ self ,
579+ project_dir : Path ,
580+ ) -> None :
581+ """Create a commit with file change to re-trigger GitHub Actions workflows.
582+
583+ Sometimes when a repo is created and pushed too quickly, GitHub Actions
584+ workflows don't get triggered. This creates a file change in the app/
585+ directory to ensure path-based workflow filters are triggered.
586+ """
587+ logger .info ("\n 🔄 Creating commit with file change to re-trigger workflows..." )
588+
589+ try :
590+ # Add a trigger file in app/ directory to match path filters
591+ trigger_file = project_dir / "app" / "_ci_trigger.py"
592+ with open (trigger_file , "w" , encoding = "utf-8" ) as f :
593+ f .write (f'''"""CI trigger file - created at { time .time ()} ."""\n ''' )
594+
595+ run_command (["git" , "add" , "." ], cwd = project_dir )
596+ run_command (
597+ ["git" , "commit" , "-m" , "chore: trigger CI workflows" ],
598+ cwd = project_dir ,
599+ )
600+ run_command (
601+ ["git" , "push" , "origin" , "main" ],
602+ cwd = project_dir ,
603+ )
604+ logger .info ("✅ Commit pushed to re-trigger workflows" )
605+ # Give GitHub a moment to process the push
606+ time .sleep (10 )
607+ except subprocess .CalledProcessError as e :
608+ logger .warning (f"Failed to create recommit: { e } " )
609+
577610 def monitor_github_actions_deployment (
578611 self ,
579612 repo_owner : str ,
580613 repo_name : str ,
581614 environment : str ,
582615 max_wait_minutes : int = 10 ,
616+ project_dir : Path | None = None ,
617+ retry_with_recommit : bool = True ,
583618 ) -> None :
584- """Monitor GitHub Actions workflow runs for deployment"""
619+ """Monitor GitHub Actions workflow runs for deployment.
620+
621+ Args:
622+ repo_owner: GitHub repository owner
623+ repo_name: GitHub repository name
624+ environment: Deployment environment (staging/production)
625+ max_wait_minutes: Maximum time to wait for deployment
626+ project_dir: Path to project directory (needed for recommit)
627+ retry_with_recommit: If True, create a file change commit to retry if no
628+ workflow is found after initial waiting period
629+ """
585630 logger .info (f"\n 🔍 Monitoring GitHub Actions { environment } deployment..." )
586631
587- start_time = time .time ()
632+ overall_start_time = time .time ()
588633 deployment_found = False
634+ recommit_triggered = False
635+ # Time to wait before triggering a recommit (2 minutes)
636+ recommit_threshold_seconds = 120
589637
590- while (time .time () - start_time ) < (max_wait_minutes * 60 ):
638+ while (time .time () - overall_start_time ) < (max_wait_minutes * 60 ):
591639 try :
592640 # Get recent workflow runs
593641 result = run_command (
@@ -694,6 +742,22 @@ def monitor_github_actions_deployment(
694742 f"GitHub Actions deployment failed: { conclusion } "
695743 )
696744
745+ # Check if we should trigger a recommit to retry
746+ elapsed_seconds = time .time () - overall_start_time
747+ if (
748+ retry_with_recommit
749+ and not recommit_triggered
750+ and project_dir is not None
751+ and elapsed_seconds > recommit_threshold_seconds
752+ ):
753+ logger .info (
754+ f"⚠️ No deployment workflow found after { int (elapsed_seconds )} s, "
755+ "attempting to re-trigger with file change commit..."
756+ )
757+ self .trigger_recommit (project_dir )
758+ recommit_triggered = True
759+ continue
760+
697761 logger .info ("⏳ No active deployment workflows found, waiting..." )
698762 time .sleep (30 )
699763
@@ -704,6 +768,7 @@ def monitor_github_actions_deployment(
704768 if not deployment_found :
705769 raise Exception (
706770 f"No GitHub Actions { environment } deployment workflows found after waiting { max_wait_minutes } minutes"
771+ + (" (recommit was attempted)" if recommit_triggered else "" )
707772 )
708773
709774 def monitor_github_workflow_run (
@@ -1444,13 +1509,15 @@ def dummy_function():
14441509 repo_owner = github_username ,
14451510 repo_name = project_name ,
14461511 environment = "staging" ,
1512+ project_dir = new_project_dir ,
14471513 )
14481514 time .sleep (5 )
1449- # Monitor production deployment
1515+ # Monitor production deployment (no recommit needed, staging already ran)
14501516 self .monitor_github_actions_deployment (
14511517 repo_owner = github_username ,
14521518 repo_name = project_name ,
14531519 environment = "production" ,
1520+ retry_with_recommit = False ,
14541521 )
14551522
14561523 logger .info ("\n ✅ E2E deployment test completed successfully!" )
0 commit comments