refactor(deploy): parameterize git remote in deploy scripts

Replace hardcoded GIT_REMOTE variable with a function parameter so the
shared deploy library can push to either the production or test remote
from the same script. Rename push_to_server to push_to_remote and update
both deploy_web.sh and deploy_web_test.sh to pass the appropriate remote.
This commit is contained in:
2026-06-12 14:39:09 +08:00
parent e2abe03a33
commit c39a8f5f80
3 changed files with 15 additions and 16 deletions
+13 -14
View File
@@ -1,21 +1,20 @@
#!/bin/bash #!/bin/bash
# Git remote 名(在仓库根目录配置): # 推送指定分支到指定远端
# git remote add server root@8.166.137.51:/root/frontend/cozsweet
GIT_REMOTE="test"
# 推送指定分支到服务器
# 期望服务器端 post-receive hook 已就位;本脚本只做 git push,不负责构建/启动 # 期望服务器端 post-receive hook 已就位;本脚本只做 git push,不负责构建/启动
push_to_server() { # 调用方:deploy_web.shproduction)→ push_to_remote "production" "main"
local branch="$1" # deploy_web_test.shtest)→ push_to_remote "test" "test"
push_to_remote() {
local remote="$1"
local branch="$2"
if [ -z "$branch" ]; then if [ -z "$remote" ] || [ -z "$branch" ]; then
echo "错误: 未指定分支名" echo "错误: 未指定 remote 或 branch"
return 1 return 1
fi fi
echo "==========================================" echo "=========================================="
echo "git push $GIT_REMOTE $branch ..." echo "git push $remote $branch ..."
echo "==========================================" echo "=========================================="
local current=$(git branch --show-current 2>/dev/null || echo "unknown") local current=$(git branch --show-current 2>/dev/null || echo "unknown")
@@ -24,13 +23,13 @@ push_to_server() {
fi fi
# 检查 remote 是否存在 # 检查 remote 是否存在
if ! git remote get-url "$GIT_REMOTE" >/dev/null 2>&1; then if ! git remote get-url "$remote" >/dev/null 2>&1; then
echo "错误: git remote '$GIT_REMOTE' 未配置" echo "错误: git remote '$remote' 未配置"
echo " 请运行: git remote add $GIT_REMOTE root@8.166.137.51:/root/frontend/cozsweet" echo " 请运行: git remote add $remote <URL>"
return 1 return 1
fi fi
git push "$GIT_REMOTE" "$branch" git push "$remote" "$branch"
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
echo "==========================================" echo "=========================================="
+1 -1
View File
@@ -9,7 +9,7 @@ source "$SCRIPT_DIR/_deploy_lib.sh"
# 主函数 # 主函数
main() { main() {
push_to_server "main" push_to_remote "production" "main"
NEW_VERSION=$(bump_version) NEW_VERSION=$(bump_version)
purge_cdn_cache purge_cdn_cache
} }
+1 -1
View File
@@ -9,7 +9,7 @@ source "$SCRIPT_DIR/_deploy_lib.sh"
# 主函数 # 主函数
main() { main() {
push_to_server "test" push_to_remote "test" "test"
purge_cdn_cache purge_cdn_cache
} }