中文+README
All checks were successful
CI / lint-and-build (push) Successful in 8s

This commit is contained in:
2026-06-14 12:08:27 +08:00
parent f9b32208e4
commit 26a5f99587
16 changed files with 376 additions and 80 deletions

View File

@@ -14,25 +14,25 @@ jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout
- name: 检出代码
uses: https://gitea.com/actions/checkout@v4
- name: Show target host info
- name: 显示目标主机信息
run: |
echo "deploying on: $(hostname)"
echo "user: $(id -un) ($(id -u))"
echo "ref: ${{ gitea.ref }}"
echo "deploy dir: $DEPLOY_DIR"
echo "部署主机: $(hostname)"
echo "执行用户: $(id -un) ($(id -u))"
echo "触发引用: ${{ gitea.ref }}"
echo "部署目录: $DEPLOY_DIR"
- name: Stop running instance (if any)
- name: 停止旧实例(若存在)
run: |
if [ -x "$DEPLOY_DIR/stop.sh" ]; then
sudo -n "$DEPLOY_DIR/stop.sh" || true
else
echo "no prior install at $DEPLOY_DIR, skipping stop"
echo "$DEPLOY_DIR 下未发现旧实例,跳过停止步骤"
fi
- name: Sync code to deploy dir
- name: 同步代码到部署目录
run: |
sudo -n /usr/bin/rsync -a --delete \
--exclude='.git' \
@@ -43,18 +43,18 @@ jobs:
./ "$DEPLOY_DIR/"
sudo -n chmod +x "$DEPLOY_DIR/setup.sh" "$DEPLOY_DIR/run.sh" "$DEPLOY_DIR/stop.sh"
- name: Setup venv and dependencies
- name: 安装 venv 与依赖
run: sudo -n "$DEPLOY_DIR/setup.sh"
- name: Start service
- name: 启动服务
run: sudo -n "$DEPLOY_DIR/run.sh"
- name: Verify pid is alive
- name: 校验进程存活
run: |
sleep 5
PID_FILE="$DEPLOY_DIR/.pid"
if [ ! -f "$PID_FILE" ]; then
echo "no .pid file at $PID_FILE" >&2
echo "未找到 pid 文件: $PID_FILE" >&2
sudo -n tail -n 50 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
fi
@@ -62,30 +62,30 @@ jobs:
echo "pid=$PID"
for i in 1 2 3; do
if [ -d "/proc/$PID" ]; then
echo "service running, pid=$PID (attempt $i)"
echo "服务运行中pid=$PID第 $i 次检查通过)"
exit 0
fi
echo "attempt $i: pid $PID not alive yet, retrying..."
echo "第 $i 次检查pid $PID 尚未存活,重试中..."
sleep 2
done
echo "pid $PID not alive after 3 attempts" >&2
echo "重试 3 次后 pid $PID 仍未存活" >&2
sudo -n tail -n 50 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
- name: HTTP health check
- name: HTTP 健康检查
run: |
for i in 1 2 3 4 5 6 7 8 9 10; do
if curl -fsS -o /dev/null "$HEALTH_URL"; then
echo "health check passed on attempt $i"
echo "第 $i 次健康检查通过"
exit 0
fi
echo "attempt $i failed, retrying..."
echo "第 $i 次健康检查失败,重试中..."
sleep 2
done
echo "health check failed: $HEALTH_URL unreachable" >&2
echo "健康检查失败:$HEALTH_URL 不可达" >&2
sudo -n tail -n 80 "$DEPLOY_DIR/logs/app.log" >&2 || true
exit 1
- name: Tail startup log
- name: 输出启动日志
if: always()
run: sudo -n tail -n 30 "$DEPLOY_DIR/logs/app.log" || true

View File

@@ -10,28 +10,20 @@ jobs:
lint-and-build:
runs-on: self-hosted
steps:
- name: Checkout
- name: 检出代码
uses: https://gitea.com/actions/checkout@v4
- name: Python syntax check
- name: Python 语法检查
run: |
python3 -m compileall -q collector web main.py
- name: Optional ruff lint
run: |
if command -v ruff >/dev/null 2>&1; then
ruff check collector web main.py || true
else
echo "ruff not installed, skipping"
fi
- name: Build venv (dry-run install)
- name: 构建 venv
run: |
python3 -m venv --system-site-packages .venv-ci
.venv-ci/bin/pip install --upgrade pip
.venv-ci/bin/pip install -r requirements.txt
.venv-ci/bin/python -c "import flask; print('flask', flask.__version__)"
- name: Cleanup
- name: 清理临时 venv
if: always()
run: rm -rf .venv-ci