Sync Python deps on fast updates when needed
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
set -euo pipefail
|
||||
|
||||
# 快速更新脚本:适合已经完成首次部署后的日常代码更新。
|
||||
# 只做 git 更新、前端 build、重启用户级服务;不检查/安装系统依赖,不重装 Python/npm 依赖。
|
||||
# 只做 git 更新、前端 build、重启用户级服务;不检查/安装系统依赖。
|
||||
# 如果 pyproject.toml 在本次更新中变化,会额外同步一次 Python 依赖。
|
||||
# 如果本次改动包含依赖、systemd 模板或部署脚本变化,请使用 scripts/deploy-ubuntu.sh。
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
||||
@@ -49,6 +50,18 @@ resolve_npm_bin() {
|
||||
printf "%s\n" "${npm_bin}"
|
||||
}
|
||||
|
||||
sync_python_dependencies_if_needed() {
|
||||
if [[ "${PYTHON_DEPS_CHANGED}" != "1" ]]; then
|
||||
return
|
||||
fi
|
||||
local python_bin="${ROOT_DIR}/.venv/bin/python"
|
||||
if [[ ! -x "${python_bin}" ]]; then
|
||||
fail "缺少项目 Python 虚拟环境:${python_bin}。请执行 bash scripts/deploy-ubuntu.sh。"
|
||||
fi
|
||||
log "检测到 pyproject.toml 变化,同步 Python 依赖"
|
||||
"${python_bin}" -m pip install -e .
|
||||
}
|
||||
|
||||
cd "${ROOT_DIR}"
|
||||
[[ -d .git ]] || fail "${ROOT_DIR} 不是 git 仓库。"
|
||||
|
||||
@@ -67,10 +80,18 @@ if [[ -n "$(git status --porcelain)" ]]; then
|
||||
fail "工作区有未提交改动。请先处理后再快速更新。"
|
||||
fi
|
||||
|
||||
PYTHON_DEPS_CHANGED=0
|
||||
before_rev="$(git rev-parse HEAD)"
|
||||
log "拉取代码:origin/${BRANCH}"
|
||||
git fetch origin
|
||||
git checkout "${BRANCH}"
|
||||
git pull --ff-only origin "${BRANCH}"
|
||||
after_rev="$(git rev-parse HEAD)"
|
||||
if [[ "${before_rev}" != "${after_rev}" ]] && ! git diff --quiet "${before_rev}" "${after_rev}" -- pyproject.toml; then
|
||||
PYTHON_DEPS_CHANGED=1
|
||||
fi
|
||||
|
||||
sync_python_dependencies_if_needed
|
||||
|
||||
log "构建前端"
|
||||
cd "${ROOT_DIR}/frontend/app"
|
||||
|
||||
Reference in New Issue
Block a user