Files
MusicBot/.gitea/workflows/ci.yml
T
snowy-yang 0145b7b01a
代码测试 / ruff + pyright + pytest (push) Failing after 2s
新增 Gitea Actions 代码测试流水线
沿用 SDK 仓库实跑验证过的形态:container 锁 python:3.13-slim(runner
默认镜像工具链不明,曾 7s 即死)、不走 actions/checkout 改从 Gitea
archive 接口拉源码 tarball(runner 对 github 连通性不稳)、关键步骤
成败上报 commit status(日志匿名不可读,status 远程可读;GITEA_TOKEN
未配置时静默降级)。检查项 ruff + pyright + pytest(本地全绿),
uv sync 针对依赖里的 GitHub archive 源失败自动重试 3 次。
2026-09-24 21:55:48 +08:00

71 lines
3.0 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
name: 代码测试
on:
push:
branches: [main]
pull_request:
workflow_dispatch:
jobs:
test:
name: ruff + pyright + pytest
runs-on: ubuntu-latest
# 固定官方 python 镜像:保证 python3.13 + pip 在场(runner 默认镜像
# 工具链不明,SDK 仓库实测任务曾 7s 即死);runner 不支持 container
# 时回落宿主机 python,此时 uv 经下方镜像变量自行下载 CPython
container: python:3.13-slim
steps:
# 不用 actions/checkout、不用 git:runner 对 github 连通性不稳
# (SDK 仓库 probe 实测),改走 Gitea archive 接口拉源码 tarball;
# 每步结果写进 commit status(日志匿名不可读,status 远程可读,
# GITEA_TOKEN 未配置时静默降级,不影响流程)
- name: 拉源码、装依赖并执行测试
env:
TOKEN: ${{ secrets.GITEA_TOKEN }}
UV_PYTHON_INSTALL_MIRROR: https://registry.npmmirror.com/-/binary/python-build-standalone
run: |
set -e
SERVER="${GITHUB_SERVER_URL:-https://gitea.4i.hk}"
note() {
curl -s -m 10 -X POST \
-H "Authorization: token $TOKEN" \
-H 'Content-Type: application/json' \
-d "{\"state\":\"$3\",\"context\":\"ci/$1\",\"description\":\"$2\"}" \
"$SERVER/api/v1/repos/$GITHUB_REPOSITORY/statuses/$GITHUB_SHA" \
-o /dev/null
}
trap 'note error "步骤意外失败,详见 Actions 日志" failure' ERR
curl -sL "$SERVER/api/v1/repos/$GITHUB_REPOSITORY/archive/$GITHUB_SHA.tar.gz" -o src.tgz \
&& mkdir src && tar -xzf src.tgz -C src --strip-components=1 && cd src \
|| { note fetch "archive 拉取失败" failure; exit 1; }
note fetch ok success
pip install uv >/dev/null 2>&1 \
|| { note pip "pip 安装 uv 失败" failure; exit 1; }
note pip ok success
# qqbotsdk 依赖解析自 GitHub archive(uv.lock 锁定内容 hash),
# runner 到 github 时通时不通,sync 失败自动重试
sync_ok=""
for _ in 1 2 3; do
if uv sync >/dev/null 2>&1; then sync_ok=1; break; fi
sleep 5
done
[ -n "$sync_ok" ] || { note sync "uv sync 失败(已重试 3 次)" failure; exit 1; }
note sync ok success
uv run ruff check musicbot tests \
|| { note ruff "ruff check 未通过" failure; exit 1; }
note ruff ok success
# pyright 需要 node:镜像里没有就装 Debian 的(保底 pyright 自带下载)
command -v node >/dev/null 2>&1 || { apt-get update -qq && apt-get install -y -qq nodejs; } || true
uv run pyright \
|| { note pyright "pyright 未通过" failure; exit 1; }
note pyright ok success
uv run pytest -q \
|| { note pytest "pytest 未通过" failure; exit 1; }
note pytest ok success