|
| 1 | +# NoneFlow 项目指南 |
| 2 | + |
| 3 | +NoneFlow 是一个基于 NoneBot2 框架开发的 GitHub Actions 工作流管理机器人,用于自动化处理 NoneBot 生态中的插件、适配器和机器人发布流程。 |
| 4 | + |
| 5 | +## 技术栈 |
| 6 | + |
| 7 | +- **Python**: 3.14.3+ |
| 8 | +- **框架**: NoneBot2 (异步机器人框架) |
| 9 | +- **适配器**: nonebot-adapter-github |
| 10 | +- **验证**: Pydantic v2 |
| 11 | +- **包管理**: uv |
| 12 | +- **容器**: Docker |
| 13 | +- **GitHub API**: githubkit |
| 14 | + |
| 15 | +## 项目结构 |
| 16 | + |
| 17 | +```text |
| 18 | +. |
| 19 | +├── bot.py # 主入口,初始化 NoneBot 并处理 GitHub Actions 事件 |
| 20 | +├── pyproject.toml # 项目配置、依赖和工具设置 |
| 21 | +├── action.yml # GitHub Action 定义 |
| 22 | +├── src/ |
| 23 | +│ ├── plugins/ |
| 24 | +│ │ └── github/ # GitHub 事件处理插件 |
| 25 | +│ │ ├── plugins/ |
| 26 | +│ │ │ ├── publish/ # 发布处理(Plugin/Adapter/Bot) |
| 27 | +│ │ │ ├── remove/ # 移除处理 |
| 28 | +│ │ │ ├── resolve/ # 冲突解决 |
| 29 | +│ │ │ └── config/ # 配置处理 |
| 30 | +│ │ ├── handlers/ # GitHub API 处理器 |
| 31 | +│ │ ├── depends/ # 依赖注入函数 |
| 32 | +│ │ └── config.py # 插件配置 |
| 33 | +│ └── providers/ |
| 34 | +│ ├── validation/ # 数据验证模块 |
| 35 | +│ ├── docker_test/ # Docker 插件测试 |
| 36 | +│ ├── store_test/ # 商店测试 |
| 37 | +│ └── models.py # 数据模型定义 |
| 38 | +├── tests/ # 测试代码 |
| 39 | +├── docker/ # Dockerfile 定义 |
| 40 | +│ ├── noneflow.dockerfile # NoneFlow 主镜像 |
| 41 | +│ └── nonetest.dockerfile # 插件测试镜像 |
| 42 | +└── examples/ # GitHub Actions 工作流示例 |
| 43 | +``` |
| 44 | + |
| 45 | +## 构建与运行 |
| 46 | + |
| 47 | +### 本地开发环境 |
| 48 | + |
| 49 | +项目使用 `uv` 作为包管理器: |
| 50 | + |
| 51 | +```bash |
| 52 | +# 安装依赖 |
| 53 | +uv sync |
| 54 | + |
| 55 | +# 运行测试 |
| 56 | +uv run poe test |
| 57 | + |
| 58 | +# 创建快照 |
| 59 | +uv run poe snapshot-create |
| 60 | + |
| 61 | +# 修复快照 |
| 62 | +uv run poe snapshot-fix |
| 63 | +``` |
| 64 | + |
| 65 | +## 测试 |
| 66 | + |
| 67 | +测试使用 pytest 框架,配置如下: |
| 68 | + |
| 69 | +```bash |
| 70 | +# 运行所有测试(并行) |
| 71 | +uv run poe test |
| 72 | + |
| 73 | +# 等同于 |
| 74 | +pytest --cov=src --cov-report xml --junitxml=./junit.xml -n auto |
| 75 | +``` |
| 76 | + |
| 77 | +测试用例应按目录和多个文件组织,不要使用测试类。 |
| 78 | + |
| 79 | +### 测试结构 |
| 80 | + |
| 81 | +- `tests/conftest.py`: 全局测试配置和 fixtures |
| 82 | +- `tests/plugins/github/`: GitHub 插件测试 |
| 83 | +- `tests/providers/`: Provider 模块测试 |
| 84 | +- `tests/constant.py`: 测试常量 |
| 85 | + |
| 86 | +### 关键测试 Fixtures |
| 87 | + |
| 88 | +- `app`: NoneBot 应用实例 |
| 89 | +- `mocked_api`: 使用 respx 模拟的 HTTP API(PyPI、GitHub、商店数据) |
| 90 | +- `mock_datetime`: 固定时间戳,确保测试一致性 |
| 91 | + |
| 92 | +## 代码风格 |
| 93 | + |
| 94 | +项目使用 Ruff 进行代码格式化和 lint: |
| 95 | + |
| 96 | +- **行长度**: 88 字符 |
| 97 | +- **目标 Python 版本**: 3.13+ |
| 98 | +- **导入排序**: isort 规则启用 |
| 99 | +- **类型检查**: Pyright (standard 模式) |
| 100 | + |
| 101 | +## 版本管理 |
| 102 | + |
| 103 | +使用 `bump-my-version` 管理版本号: |
| 104 | + |
| 105 | +```bash |
| 106 | +# 显示当前版本和可升级版本 |
| 107 | +uv run poe show-bump |
| 108 | + |
| 109 | +# 升级版本(自动修改 pyproject.toml、CHANGELOG.md、uv.lock) |
| 110 | +uv run poe bump |
| 111 | +``` |
| 112 | + |
| 113 | +## 开发注意事项 |
| 114 | + |
| 115 | +1. **GitHub App 权限**: 需要 `contents:write`、`issues:write`、`pull_requests:write` 等权限 |
| 116 | +2. **Docker 测试**: 插件测试需要 Docker 环境,测试时会拉取插件代码并在隔离环境中运行 |
| 117 | +3. **并发控制**: 使用 `concurrency` 配置避免同一议题的并发处理 |
| 118 | +4. **Artifact 传递**: 通过 GitHub Actions Artifact 在不同工作流间传递数据 |
| 119 | + |
| 120 | +## 相关仓库 |
| 121 | + |
| 122 | +- [nonebot2](https://github.com/nonebot/nonebot2): NoneBot 主仓库 |
| 123 | +- [adapter-github](https://github.com/nonebot/adapter-github): GitHub 协议适配 |
| 124 | +- [githubkit](https://github.com/yanyongyu/githubkit): GitHub API |
| 125 | +- [registry](https://github.com/nonebot/registry): 商店注册表 |
| 126 | +- [noneflow-test](https://github.com/nonebot/noneflow-test): 测试仓库 |
0 commit comments