fix(deploy): harden webhook auto-release for CRLF, git reset, and prisma order
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+18
-2
@@ -13,7 +13,7 @@ LOG_FILE="${DEPLOY_LOG_FILE:-/var/log/dukang/deploy.log}"
|
||||
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
# shellcheck disable=SC1090
|
||||
source "$ENV_FILE"
|
||||
source <(sed 's/\r$//' "$ENV_FILE")
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$LOG_FILE")"
|
||||
@@ -49,7 +49,23 @@ if [[ "$LOCAL_SHA" == "$REMOTE_SHA" ]]; then
|
||||
fi
|
||||
|
||||
log "PULL $LOCAL_SHA -> $REMOTE_SHA"
|
||||
git pull --ff-only "$GIT_REMOTE" "$GIT_BRANCH"
|
||||
|
||||
# 保留生产密钥,避免 reset 覆盖
|
||||
ENV_BACKUP="$(mktemp)"
|
||||
API_ENV_BACKUP="$(mktemp)"
|
||||
API_ENV_PROD_BACKUP="$(mktemp)"
|
||||
cp "$ENV_FILE" "$ENV_BACKUP" 2>/dev/null || true
|
||||
cp "$APP_ROOT/server/dukang-api/.env" "$API_ENV_BACKUP" 2>/dev/null || true
|
||||
cp "$APP_ROOT/server/dukang-api/.env.production" "$API_ENV_PROD_BACKUP" 2>/dev/null || true
|
||||
|
||||
git checkout "$GIT_BRANCH"
|
||||
git reset --hard "$GIT_REMOTE/$GIT_BRANCH"
|
||||
|
||||
cp "$ENV_BACKUP" "$ENV_FILE" 2>/dev/null || true
|
||||
cp "$API_ENV_BACKUP" "$APP_ROOT/server/dukang-api/.env" 2>/dev/null || true
|
||||
cp "$API_ENV_PROD_BACKUP" "$APP_ROOT/server/dukang-api/.env.production" 2>/dev/null || true
|
||||
rm -f "$ENV_BACKUP" "$API_ENV_BACKUP" "$API_ENV_PROD_BACKUP"
|
||||
sed -i 's/\r$//' "$ENV_FILE" 2>/dev/null || true
|
||||
|
||||
# 修复 Windows 换行
|
||||
find "$APP_ROOT/deploy" -maxdepth 1 -name '*.sh' -exec sed -i 's/\r$//' {} + 2>/dev/null || true
|
||||
|
||||
Reference in New Issue
Block a user