feat: add one-line deploy script (deploy-cli.sh)#7631
feat: add one-line deploy script (deploy-cli.sh)#7631EterUltimate wants to merge 3 commits intoAstrBotDevs:masterfrom
Conversation
- Add docs/scripts/deploy-cli.sh for one-command deployment (Linux/macOS/WSL) - Update docs/zh/deploy/astrbot/cli.md to reference local script - Replace non-existent https://astrbot.app/deploy.sh with raw.githubusercontent.com URL - Add local run tip and WSL-based Windows support
There was a problem hiding this comment.
Code Review
This pull request introduces a one-command deployment script (deploy-cli.sh) and updates the documentation to include instructions for its use across Linux, macOS, and Windows (via WSL). The script automates the process of checking for dependencies, installing the uv package manager, cloning the repository, and starting the application. Review feedback highlighted a portability issue with sort -V on macOS, a discrepancy between the script's Python version check and the project's actual requirements (3.12), and a logic flaw that could cause nested directory cloning if the script is run from within the repository.
| if [ "$(printf '%s\n' "3.10" "$PY_VER" | sort -V | head -n1)" != "3.10" ]; then | ||
| err "Python 版本过低: $PY_VER,需要 >= 3.10" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
此处使用的 sort -V (version sort) 是 GNU 扩展,在 macOS 默认的 BSD sort 中并不支持,会导致脚本在 macOS 上运行失败。此外,脚本检查的是 Python >= 3.10,但 pyproject.toml 中定义的 requires-python 是 >=3.12。由于后续 uv sync 会严格遵守 pyproject.toml 的约束,建议将检查版本提升至 3.12,并使用 Python 自身进行版本比较以提高兼容性。
| if [ "$(printf '%s\n' "3.10" "$PY_VER" | sort -V | head -n1)" != "3.10" ]; then | |
| err "Python 版本过低: $PY_VER,需要 >= 3.10" | |
| exit 1 | |
| fi | |
| if ! $PY -c 'import sys; exit(0 if sys.version_info >= (3, 12) else 1)'; then | |
| err "Python 版本过低: $PY_VER,需要 >= 3.12" | |
| exit 1 | |
| fi |
| INSTALL_DIR="${1:-AstrBot}" | ||
| if [ ! -d "$INSTALL_DIR/.git" ]; then | ||
| info "正在克隆 AstrBot 仓库到 $INSTALL_DIR ..." | ||
| git clone --depth=1 https://github.com/AstrBotDevs/AstrBot.git "$INSTALL_DIR" | ||
| else | ||
| info "目录 $INSTALL_DIR 已存在,跳过克隆" | ||
| fi | ||
| cd "$INSTALL_DIR" |
There was a problem hiding this comment.
当按照文档建议在已克隆的仓库目录内运行此脚本时(例如 cd AstrBot; bash docs/scripts/deploy-cli.sh),脚本会因为在当前目录下找不到 ./AstrBot/.git 而尝试再次克隆,导致出现嵌套目录(如 AstrBot/AstrBot)。建议增加对当前目录是否已是项目根目录的检测。
| INSTALL_DIR="${1:-AstrBot}" | |
| if [ ! -d "$INSTALL_DIR/.git" ]; then | |
| info "正在克隆 AstrBot 仓库到 $INSTALL_DIR ..." | |
| git clone --depth=1 https://github.com/AstrBotDevs/AstrBot.git "$INSTALL_DIR" | |
| else | |
| info "目录 $INSTALL_DIR 已存在,跳过克隆" | |
| fi | |
| cd "$INSTALL_DIR" | |
| if [ -f "main.py" ] && [ -d ".git" ]; then | |
| info "检测到已在项目目录中,跳过克隆" | |
| else | |
| INSTALL_DIR="${1:-AstrBot}" | |
| if [ ! -d "$INSTALL_DIR/.git" ]; then | |
| info "正在克隆 AstrBot 仓库到 $INSTALL_DIR ..." | |
| git clone --depth=1 https://github.com/AstrBotDevs/AstrBot.git "$INSTALL_DIR" | |
| else | |
| info "目录 $INSTALL_DIR 已存在,跳过克隆" | |
| fi | |
| cd "$INSTALL_DIR" | |
| fi |
There was a problem hiding this comment.
Hey - I've found 2 issues, and left some high level feedback:
- When the script is run from an already-cloned repo (as shown in the "本地运行脚本" example),
INSTALL_DIR="${1:-AstrBot}"combined withif [ ! -d "$INSTALL_DIR/.git" ]will cause a nestedAstrBot/AstrBotclone; consider detecting an existing.gitin the current directory and skipping theINSTALL_DIRcloning logic in that case. - The script currently hardcodes the GitHub repo URL and default directory name; consider allowing these to be overridden via environment variables or flags so that forks or mirrors can reuse the same deployment script.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When the script is run from an already-cloned repo (as shown in the "本地运行脚本" example), `INSTALL_DIR="${1:-AstrBot}"` combined with `if [ ! -d "$INSTALL_DIR/.git" ]` will cause a nested `AstrBot/AstrBot` clone; consider detecting an existing `.git` in the current directory and skipping the `INSTALL_DIR` cloning logic in that case.
- The script currently hardcodes the GitHub repo URL and default directory name; consider allowing these to be overridden via environment variables or flags so that forks or mirrors can reuse the same deployment script.
## Individual Comments
### Comment 1
<location path="docs/scripts/deploy-cli.sh" line_range="18-19" />
<code_context>
+# ── 1. 检测并安装依赖 ──
+info "正在检测运行环境..."
+
+if ! has git; then
+ err "未检测到 git,请先安装: https://git-scm.com/downloads"
+ exit 1
+fi
+
</code_context>
<issue_to_address>
**suggestion:** Consider checking for `curl` explicitly since the script depends on it for both the install and the recommended one-liner usage.
Currently only `git` and `python` are validated, but the script also relies on `curl` (for install and the one-liner). On systems without `curl`, users will just see `command not found`. Consider adding a `curl` check similar to the `git` check, with a clear error message and possibly guidance (e.g., how to install `curl` or an optional `wget` fallback).
```suggestion
# ── 1. 检测并安装依赖 ──
info "正在检测运行环境..."
if ! has git; then
err "未检测到 git,请先安装: https://git-scm.com/downloads"
exit 1
fi
if ! has curl; then
err "未检测到 curl,请先安装 curl 后重试(例如:macOS 使用 'brew install curl',Ubuntu/Debian 使用 'sudo apt install curl')。"
exit 1
fi
```
</issue_to_address>
### Comment 2
<location path="docs/scripts/deploy-cli.sh" line_range="55-56" />
<code_context>
+ok "uv $(uv --version)"
+
+# ── 2. 克隆仓库 ──
+INSTALL_DIR="${1:-AstrBot}"
+if [ ! -d "$INSTALL_DIR/.git" ]; then
+ info "正在克隆 AstrBot 仓库到 $INSTALL_DIR ..."
+ git clone --depth=1 https://github.com/AstrBotDevs/AstrBot.git "$INSTALL_DIR"
</code_context>
<issue_to_address>
**issue:** Cloning into an existing non-git directory will fail silently from the script's perspective; consider handling that case explicitly.
Right now you only check for `$INSTALL_DIR/.git`. If `$INSTALL_DIR` already exists but isn’t a git repo (e.g., user-created or used for other files), `git clone ... "$INSTALL_DIR"` will fail because the directory is non-empty and only surface as a git error. It would help to explicitly handle the case where `$INSTALL_DIR` exists without `.git` by either aborting with a clearer message, prompting for a different directory, or supporting a `--force`/env flag to overwrite or reuse it.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- Replace sort -V with Python-native version check (macOS BSD compat) - Bump Python requirement from >=3.10 to >=3.12 (match pyproject.toml) - Detect current directory as project root (avoid nested clone) - Handle existing non-git directory explicitly - Add curl dependency check - Support ASTRBOT_REPO and ASTRBOT_DIR env vars for forks/mirrors - Update cli.md version description to match
- Add deploy-cli.ps1 for Windows native environment (PowerShell 7+) - Update cli.md to document Windows one-liner deployment - Add local script execution instructions for both bash and ps1
概述
添加一行命令快速部署脚本,简化源码部署流程。
变更内容
新增
docs/scripts/deploy-cli.shuv sync-> 启动 AstrBot用法:
bash -c "$(curl -fsSL https://raw.githubusercontent.com/AstrBotDevs/AstrBot/master/docs/scripts/deploy-cli.sh)"修改
docs/zh/deploy/astrbot/cli.mddocs/scripts/deploy-cli.sh测试
bash -n deploy-cli.sh通过)Summary by Sourcery
Add a one-line deployment script for AstrBot and document its usage for Linux, macOS, WSL, and Windows users.
New Features:
Documentation: