Merge branch 'dev' into test
This commit is contained in:
@@ -1,6 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
# Post-commit hook: 本地提交后自动执行 Web 预发布脚本。
|
|
||||||
|
|
||||||
set -eu
|
|
||||||
|
|
||||||
bash scripts/release/pre_release_web.sh
|
|
||||||
+14
-50
@@ -5,13 +5,19 @@
|
|||||||
export NVM_DIR="$HOME/.nvm"
|
export NVM_DIR="$HOME/.nvm"
|
||||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
|
||||||
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
||||||
|
# pnpm
|
||||||
|
export PNPM_HOME="/root/.local/share/pnpm"
|
||||||
|
case ":$PATH:" in
|
||||||
|
*":$PNPM_HOME:"*) ;;
|
||||||
|
*) export PATH="$PNPM_HOME:$PATH" ;;
|
||||||
|
esac
|
||||||
|
# pnpm end
|
||||||
|
|
||||||
# 全局变量统一声明。具体值由各步骤函数写入。
|
# 全局变量统一声明。具体值由各步骤函数写入。
|
||||||
REPO_TOPLEVEL=""
|
REPO_TOPLEVEL=""
|
||||||
LOG_FILE=""
|
LOG_FILE=""
|
||||||
CURRENT_BRANCH=""
|
CURRENT_BRANCH=""
|
||||||
START_PORT=""
|
START_PORT=""
|
||||||
PM2_APP_NAME=""
|
|
||||||
BUILD_EXIT=0
|
BUILD_EXIT=0
|
||||||
STOP_WAIT_SECONDS=3
|
STOP_WAIT_SECONDS=3
|
||||||
STOP_VERIFY_RETRIES=3
|
STOP_VERIFY_RETRIES=3
|
||||||
@@ -81,21 +87,16 @@ select_port_by_branch() {
|
|||||||
case "$CURRENT_BRANCH" in
|
case "$CURRENT_BRANCH" in
|
||||||
main)
|
main)
|
||||||
START_PORT=9185
|
START_PORT=9185
|
||||||
PM2_APP_NAME="cozsweet-main"
|
|
||||||
;;
|
;;
|
||||||
test|dev)
|
test|dev)
|
||||||
START_PORT=9135
|
START_PORT=9135
|
||||||
PM2_APP_NAME="cozsweet-$CURRENT_BRANCH"
|
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
START_PORT=9135
|
START_PORT=9135
|
||||||
PM2_APP_NAME="cozsweet-$CURRENT_BRANCH"
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
export START_PORT
|
export START_PORT
|
||||||
export PM2_APP_NAME
|
|
||||||
echo "=== start port: $START_PORT ===" >> "$LOG_FILE"
|
echo "=== start port: $START_PORT ===" >> "$LOG_FILE"
|
||||||
echo "=== pm2 app: $PM2_APP_NAME ===" >> "$LOG_FILE"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@@ -187,41 +188,11 @@ stop_existing_next() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_existing_pm2() {
|
|
||||||
echo "=== stop existing pm2 app $PM2_APP_NAME @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
|
||||||
|
|
||||||
if ! command -v pm2 >/dev/null 2>&1; then
|
|
||||||
echo "=== pm2 command not found; install pm2 before deployment ===" >> "$LOG_FILE"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if pm2 describe "$PM2_APP_NAME" >/dev/null 2>&1; then
|
|
||||||
pm2 delete "$PM2_APP_NAME" >> "$LOG_FILE" 2>&1 || true
|
|
||||||
echo "=== pm2 app deleted: $PM2_APP_NAME ===" >> "$LOG_FILE"
|
|
||||||
else
|
|
||||||
echo "=== no pm2 app found: $PM2_APP_NAME ===" >> "$LOG_FILE"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "" >> "$LOG_FILE"
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
launch_next() {
|
launch_next() {
|
||||||
echo "=== pm2 LAUNCH app=$PM2_APP_NAME port=$START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
echo "=== start LAUNCH port=$START_PORT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||||
|
PORT="$START_PORT" nohup pnpm run start >> "$LOG_FILE" 2>&1 &
|
||||||
export PORT="$START_PORT"
|
START_PID=$!
|
||||||
pm2 start pnpm --name "$PM2_APP_NAME" -- run start >> "$LOG_FILE" 2>&1
|
echo "=== start PID=$START_PID @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
||||||
PM2_EXIT=$?
|
|
||||||
echo "=== pm2 START EXIT_CODE=$PM2_EXIT @ $(date +%Y-%m-%dT%H:%M:%S%z) ===" >> "$LOG_FILE"
|
|
||||||
|
|
||||||
if [ "$PM2_EXIT" -ne 0 ]; then
|
|
||||||
echo "=== pm2 START FAILED ===" >> "$LOG_FILE"
|
|
||||||
return "$PM2_EXIT"
|
|
||||||
fi
|
|
||||||
|
|
||||||
pm2 save >> "$LOG_FILE" 2>&1 || true
|
|
||||||
echo "=== realtime logs: pm2 logs $PM2_APP_NAME ===" >> "$LOG_FILE"
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@@ -249,17 +220,10 @@ main() {
|
|||||||
exit $BUILD_EXIT # build 失败 → 不启 start(避免用旧 .next 跑新代码)
|
exit $BUILD_EXIT # build 失败 → 不启 start(避免用旧 .next 跑新代码)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! stop_existing_pm2; then
|
if ! stop_existing_next; then
|
||||||
exit 1 # pm2 不可用 → 不启动新服务
|
exit 1 # 端口未释放 → 不启动新服务,避免 EADDRINUSE
|
||||||
fi
|
|
||||||
|
|
||||||
# if ! stop_existing_next; then
|
|
||||||
# exit 1 # 端口未释放 → 不启动新服务,避免 EADDRINUSE
|
|
||||||
# fi
|
|
||||||
|
|
||||||
if ! launch_next; then
|
|
||||||
exit 1 # pm2 启动失败
|
|
||||||
fi
|
fi
|
||||||
|
launch_next # 再启新
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
Reference in New Issue
Block a user