mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-01 01:10:21 +08:00
fix: downgrade python-ripgrep version to 0.0.8 in dependencies (#7514)
* fix: downgrade python-ripgrep version to 0.0.8 in dependencies * fix: update smoke test workflow to support multiple OS and Python versions
This commit is contained in:
49
.github/workflows/smoke_test.yml
vendored
49
.github/workflows/smoke_test.yml
vendored
@@ -13,10 +13,23 @@ on:
|
||||
|
||||
jobs:
|
||||
smoke-test:
|
||||
name: Run smoke tests
|
||||
runs-on: ubuntu-latest
|
||||
name: Smoke test (${{ matrix.os }}, Python ${{ matrix.python-version }})
|
||||
runs-on: ${{ matrix.os }}
|
||||
timeout-minutes: 10
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
- macos-latest
|
||||
- windows-latest
|
||||
python-version:
|
||||
- '3.10'
|
||||
- '3.11'
|
||||
- '3.12'
|
||||
- '3.13'
|
||||
- '3.14'
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v6
|
||||
@@ -26,33 +39,21 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.12'
|
||||
|
||||
- name: Install UV package manager
|
||||
python-version: ${{ matrix.python-version }}
|
||||
cache: 'pip'
|
||||
cache-dependency-path: requirements.txt
|
||||
|
||||
- name: Install uv
|
||||
run: |
|
||||
pip install uv
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install uv
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
uv sync
|
||||
uv pip install --system -r requirements.txt
|
||||
timeout-minutes: 15
|
||||
|
||||
- name: Run smoke tests
|
||||
run: |
|
||||
uv run main.py &
|
||||
APP_PID=$!
|
||||
|
||||
echo "Waiting for application to start..."
|
||||
for i in {1..60}; do
|
||||
if curl -f http://localhost:6185 > /dev/null 2>&1; then
|
||||
echo "Application started successfully!"
|
||||
kill $APP_PID
|
||||
exit 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Application failed to start within 30 seconds"
|
||||
kill $APP_PID 2>/dev/null || true
|
||||
exit 1
|
||||
python scripts/smoke_startup_check.py
|
||||
timeout-minutes: 2
|
||||
|
||||
@@ -64,7 +64,7 @@ dependencies = [
|
||||
"python-socks>=2.8.0",
|
||||
"pysocks>=1.7.1",
|
||||
"packaging>=24.2",
|
||||
"python-ripgrep==0.0.9",
|
||||
"python-ripgrep==0.0.8",
|
||||
]
|
||||
|
||||
[dependency-groups]
|
||||
|
||||
@@ -53,4 +53,4 @@ shipyard-python-sdk>=0.2.4
|
||||
shipyard-neo-sdk>=0.2.0
|
||||
packaging>=24.2
|
||||
qrcode>=8.2
|
||||
python-ripgrep==0.0.9
|
||||
python-ripgrep==0.0.8
|
||||
116
scripts/smoke_startup_check.py
Normal file
116
scripts/smoke_startup_check.py
Normal file
@@ -0,0 +1,116 @@
|
||||
"""Cross-platform startup smoke check for AstrBot."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
HEALTH_URL = "http://127.0.0.1:6185"
|
||||
STARTUP_TIMEOUT_SECONDS = 60
|
||||
REQUEST_TIMEOUT_SECONDS = 2
|
||||
|
||||
|
||||
def _tail(path: Path, lines: int = 80) -> str:
|
||||
try:
|
||||
content = path.read_text(encoding="utf-8", errors="replace").splitlines()
|
||||
except OSError as exc:
|
||||
return f"Unable to read smoke log: {exc}"
|
||||
return "\n".join(content[-lines:])
|
||||
|
||||
|
||||
def _is_ready() -> bool:
|
||||
try:
|
||||
with urllib.request.urlopen( # noqa: S310
|
||||
HEALTH_URL,
|
||||
timeout=REQUEST_TIMEOUT_SECONDS,
|
||||
) as response:
|
||||
return response.status < 400
|
||||
except (OSError, urllib.error.URLError):
|
||||
return False
|
||||
|
||||
|
||||
def _stop_process(proc: subprocess.Popen[bytes]) -> None:
|
||||
if proc.poll() is not None:
|
||||
return
|
||||
|
||||
proc.terminate()
|
||||
try:
|
||||
proc.wait(timeout=10)
|
||||
except subprocess.TimeoutExpired:
|
||||
proc.kill()
|
||||
proc.wait(timeout=10)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
env = os.environ.copy()
|
||||
env.setdefault("PYTHONUTF8", "1")
|
||||
env.setdefault("TESTING", "true")
|
||||
|
||||
smoke_root = Path(tempfile.mkdtemp(prefix="astrbot-smoke-root-"))
|
||||
env["ASTRBOT_ROOT"] = str(smoke_root)
|
||||
log_path = smoke_root / "smoke.log"
|
||||
webui_dir = smoke_root / "webui"
|
||||
webui_dir.mkdir()
|
||||
(webui_dir / "index.html").write_text(
|
||||
"<!doctype html><title>AstrBot</title>",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
with log_path.open("wb") as log_file:
|
||||
proc = subprocess.Popen(
|
||||
[
|
||||
sys.executable,
|
||||
str(REPO_ROOT / "main.py"),
|
||||
"--webui-dir",
|
||||
str(webui_dir),
|
||||
],
|
||||
cwd=REPO_ROOT,
|
||||
stdout=log_file,
|
||||
stderr=subprocess.STDOUT,
|
||||
env=env,
|
||||
)
|
||||
|
||||
print(f"Starting smoke test on {HEALTH_URL}")
|
||||
deadline = time.monotonic() + STARTUP_TIMEOUT_SECONDS
|
||||
try:
|
||||
while time.monotonic() < deadline:
|
||||
if _is_ready():
|
||||
print("Smoke test passed")
|
||||
return 0
|
||||
|
||||
return_code = proc.poll()
|
||||
if return_code is not None:
|
||||
print(
|
||||
f"AstrBot exited before becoming healthy. Exit code: {return_code}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(_tail(log_path), file=sys.stderr)
|
||||
return 1
|
||||
|
||||
time.sleep(1)
|
||||
|
||||
print(
|
||||
"Smoke test failed: health endpoint did not become ready in time.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
print(_tail(log_path), file=sys.stderr)
|
||||
return 1
|
||||
finally:
|
||||
_stop_process(proc)
|
||||
try:
|
||||
log_path.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
shutil.rmtree(smoke_root, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user