feat: 新增生产部署脚本

This commit is contained in:
Daniel
2026-04-28 11:55:04 +08:00
parent 4ee41e3534
commit 975a9e88f6

View File

@@ -4,15 +4,33 @@ set -euo pipefail
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$PROJECT_ROOT"
TARGET_BRANCH="${1:-$(git rev-parse --abbrev-ref HEAD)}"
resolve_default_branch() {
local current
current="$(git branch --show-current 2>/dev/null || true)"
if [[ -n "$current" ]]; then
echo "$current"
return
fi
local remote_head
remote_head="$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null || true)"
if [[ -n "$remote_head" ]]; then
echo "${remote_head#origin/}"
return
fi
echo "main"
}
TARGET_BRANCH="${1:-$(resolve_default_branch)}"
echo "==> Deploy directory: $PROJECT_ROOT"
echo "==> Target branch: $TARGET_BRANCH"
if [[ -n "$(git status --porcelain)" ]]; then
echo "Error: working tree is not clean."
echo "Please commit/stash local changes before deployment."
exit 1
STASH_NAME="auto-deploy-$(date +%Y%m%d-%H%M%S)"
echo "==> Working tree is not clean, auto stashing: $STASH_NAME"
git stash push -u -m "$STASH_NAME" >/dev/null
fi
echo "==> Fetching remote updates..."