手动回滚部署(有分支有commit)
(config, manual_branch, manual_commit)
| 172 | return True, "" |
| 173 | |
| 174 | def manual_rollback_deploy(config, manual_branch, manual_commit): |
| 175 | """手动回滚部署(有分支有commit)""" |
| 176 | site_name = config.get('type_parm') |
| 177 | deploy_script = config.get('deploy_script', '') |
| 178 | |
| 179 | log(f"回滚代码: {site_name} -> {manual_branch} -> {manual_commit[:8]}") |
| 180 | |
| 181 | # 获取网站信息 |
| 182 | site_info = get_site_info(site_name) |
| 183 | if not site_info: |
| 184 | return False, "网站不存在或不是Git仓库" |
| 185 | |
| 186 | site_path = site_info['path'] |
| 187 | display_git_info(site_path) |
| 188 | |
| 189 | # 切换分支 |
| 190 | if not run_cmd(f"cd {site_path} && git checkout {manual_branch}"): |
| 191 | return False, f"切换到分支失败: {manual_branch}" |
| 192 | |
| 193 | # 回滚到指定commit |
| 194 | if not run_cmd(f"cd {site_path} && git reset --hard {manual_commit}"): |
| 195 | return False, "回滚失败" |
| 196 | |
| 197 | log(f"🚀 成功回退到commit: {manual_commit[:8]}!") |
| 198 | |
| 199 | # 执行部署脚本 |
| 200 | success, error_msg = execute_deploy_script(site_path, deploy_script) |
| 201 | if not success: |
| 202 | return False, error_msg |
| 203 | |
| 204 | # 修正权限 |
| 205 | run_cmd(f"chown -R www:www {site_path}") |
| 206 | log("部署完成", "✅") |
| 207 | |
| 208 | return True, "" |
| 209 | |
| 210 | def save_deploy_log(config, success, error_msg="", deploy_mode=1): |
| 211 | """保存部署日志到数据库(总是被调用)""" |
no test coverage detected