@@ -34,7 +34,7 @@ class DependencyManager(Enum):
3434 UNKNOWN = auto ()
3535
3636
37- def install_github_actions (override_formatter_check : bool = False ) -> None :
37+ def install_github_actions (override_formatter_check : bool = False , * , skip_confirm : bool = False ) -> None :
3838 try :
3939 config , _config_file_path = parse_config_file (override_formatter_check = override_formatter_check )
4040
@@ -100,12 +100,15 @@ def install_github_actions(override_formatter_check: bool = False) -> None:
100100 console .print (benchmark_panel )
101101 console .print ()
102102
103- benchmark_questions = [
104- inquirer .Confirm ("benchmark_mode" , message = "Run GitHub Actions in benchmark mode?" , default = True )
105- ]
103+ if skip_confirm :
104+ benchmark_mode = True
105+ else :
106+ benchmark_questions = [
107+ inquirer .Confirm ("benchmark_mode" , message = "Run GitHub Actions in benchmark mode?" , default = True )
108+ ]
106109
107- benchmark_answers = inquirer .prompt (benchmark_questions , theme = CodeflashTheme ())
108- benchmark_mode = benchmark_answers ["benchmark_mode" ] if benchmark_answers else False
110+ benchmark_answers = inquirer .prompt (benchmark_questions , theme = CodeflashTheme ())
111+ benchmark_mode = benchmark_answers ["benchmark_mode" ] if benchmark_answers else False
109112
110113 # Show prompt only if workflow doesn't exist locally
111114 actions_panel = Panel (
@@ -121,26 +124,28 @@ def install_github_actions(override_formatter_check: bool = False) -> None:
121124 console .print (actions_panel )
122125 console .print ()
123126
124- creation_questions = [
125- inquirer .Confirm (
126- "confirm_creation" ,
127- message = "Set up GitHub Actions for continuous optimization? We'll open a pull request with the workflow file." ,
128- default = True ,
129- )
130- ]
127+ if skip_confirm :
128+ confirm_creation = True
129+ else :
130+ creation_questions = [
131+ inquirer .Confirm (
132+ "confirm_creation" ,
133+ message = "Set up GitHub Actions for continuous optimization? We'll open a pull request with the workflow file." ,
134+ default = True ,
135+ )
136+ ]
137+
138+ creation_answers = inquirer .prompt (creation_questions , theme = CodeflashTheme ())
139+ confirm_creation = bool (creation_answers and creation_answers ["confirm_creation" ])
131140
132- creation_answers = inquirer .prompt (creation_questions , theme = CodeflashTheme ())
133- if not creation_answers or not creation_answers ["confirm_creation" ]:
141+ if not confirm_creation :
134142 skip_panel = Panel (
135143 Text ("⏩️ Skipping GitHub Actions setup." , style = "yellow" ), title = "⏩️ Skipped" , border_style = "yellow"
136144 )
137145 console .print (skip_panel )
138146 ph ("cli-github-workflow-skipped" )
139147 return
140- ph (
141- "cli-github-optimization-confirm-workflow-creation" ,
142- {"confirm_creation" : creation_answers ["confirm_creation" ]},
143- )
148+ ph ("cli-github-optimization-confirm-workflow-creation" , {"confirm_creation" : confirm_creation })
144149
145150 # Generate workflow content AFTER user confirmation
146151 logger .info ("[github_workflow.py:install_github_actions] User confirmed, generating workflow content..." )
@@ -423,6 +428,11 @@ def install_github_actions(override_formatter_check: bool = False) -> None:
423428 f"🚀 Codeflash is now configured to automatically optimize new Github PRs!{ LF } "
424429 )
425430
431+ if skip_confirm :
432+ click .echo ("Add your CODEFLASH_API_KEY as a GitHub secret before running this workflow." )
433+ ph ("cli-github-workflow-created" )
434+ return
435+
426436 # Show GitHub secrets setup panel (needed in both cases - PR created via API or local file)
427437 try :
428438 existing_api_key = get_codeflash_api_key ()
@@ -555,8 +565,11 @@ def get_github_action_working_directory(toml_path: Path, git_root: Path) -> str:
555565def detect_project_language_for_workflow (project_root : Path ) -> str :
556566 """Detect the primary language of the project for workflow generation.
557567
558- Returns: 'python', 'javascript', 'typescript', or 'java '
568+ Returns: 'python', 'javascript', 'typescript', 'java', or 'go '
559569 """
570+ if (project_root / "go.mod" ).exists ():
571+ return "go"
572+
560573 # Check for Java build tools first (pom.xml or build.gradle)
561574 if (
562575 (project_root / "pom.xml" ).exists ()
@@ -693,9 +706,9 @@ def generate_dynamic_workflow_content(
693706 # Detect project language
694707 project_language = detect_project_language_for_workflow (Path .cwd ())
695708
696- # For JavaScript/TypeScript and Java projects, use static template customization
709+ # For JavaScript/TypeScript, Java, and Go projects, use static template customization
697710 # (AI-generated steps are currently Python-only)
698- if project_language in ("javascript" , "typescript" , "java" ):
711+ if project_language in ("javascript" , "typescript" , "java" , "go" ):
699712 return customize_codeflash_yaml_content (optimize_yml_content , config , git_root , benchmark_mode )
700713
701714 # Python project - try AI-generated steps
@@ -824,6 +837,9 @@ def customize_codeflash_yaml_content(
824837 if project_language in ("javascript" , "typescript" ):
825838 return _customize_js_workflow_content (optimize_yml_content , git_root , benchmark_mode )
826839
840+ if project_language == "go" :
841+ return _customize_go_workflow_content (optimize_yml_content , git_root , benchmark_mode )
842+
827843 # Python project (default)
828844 return _customize_python_workflow_content (optimize_yml_content , git_root , benchmark_mode )
829845
@@ -948,3 +964,38 @@ def _customize_java_workflow_content(optimize_yml_content: str, git_root: Path)
948964 # Install dependencies command
949965 install_deps = get_java_dependency_installation_commands (build_tool )
950966 return optimize_yml_content .replace ("{{ install_dependencies_command }}" , install_deps )
967+
968+
969+ def _customize_go_workflow_content (optimize_yml_content : str , git_root : Path , benchmark_mode : bool = False ) -> str :
970+ """Customize workflow content for Go projects."""
971+ from codeflash .cli_cmds .init_go import get_go_dependency_installation_commands , get_go_runtime_setup_steps
972+
973+ project_root = Path .cwd ()
974+
975+ if project_root == git_root :
976+ working_dir = ""
977+ else :
978+ rel_path = str (project_root .relative_to (git_root ))
979+ working_dir = f"""defaults:
980+ run:
981+ working-directory: ./{ rel_path } """
982+
983+ optimize_yml_content = optimize_yml_content .replace ("Optimize new Python code" , "Optimize new Go code" )
984+ optimize_yml_content = optimize_yml_content .replace ("{{ working_directory }}" , working_dir )
985+
986+ python_setup = get_dependency_manager_installation_string (DependencyManager .PIP )
987+ go_setup = get_go_runtime_setup_steps ()
988+ setup_runtime = f"""{ python_setup }
989+ { go_setup } """
990+ optimize_yml_content = optimize_yml_content .replace ("{{ setup_runtime_environment }}" , setup_runtime )
991+
992+ install_deps = f"""|
993+ python -m pip install --upgrade pip
994+ pip install codeflash
995+ { get_go_dependency_installation_commands ()} """
996+ optimize_yml_content = optimize_yml_content .replace ("{{ install_dependencies_command }}" , install_deps )
997+
998+ codeflash_cmd = "codeflash"
999+ if benchmark_mode :
1000+ codeflash_cmd += " --benchmark"
1001+ return optimize_yml_content .replace ("{{ codeflash_command }}" , codeflash_cmd )
0 commit comments