Important
收藏项目 以便创建插件仓库~⭐️
- 点击 创建仓库
⚠️ 重要: 前往仓库Settings->Actions->General-> 最下方Workflow permissions, 勾选Read and write permissions,然后点击Save按钮- 在
Add file菜单中选择Create new file, 在新文件名处输入LICENSE, 此时在右侧会出现一个Choose a license template按钮, 点击此按钮选择开源协议模板, 然后在最下方提交新文件到主分支(这会触发一个工作流,生成新的README,并修改pyproject.toml等文件中的插件名称)
- 依赖管理:
uv(自动创建虚拟环境) - 任务编排:
just - 代码质量:
ruff(格式化 + 静态检查)、basedpyright(类型检查) - 测试:
pytest+pytest-xdist(并行)+pytest-cov - 提交规范:
commitizen、pre-commit/prek - 变更日志:
git-cliff
uv sync --all-groups -p 3.12just test # 单元测试(含覆盖率,自动并行)
just lint # 代码检查 + 格式化(ruff check/format)
just check # 类型检查(basedpyright)
just hooks # 安装 pre-commit / prek 钩子
just update # 更新钩子版本(prek autoupdate)
just changelog # 生成最新 changelog(git-cliff)
just bump # 根据 commit 自动升版本并更新锁文件(cz + uv lock)Note
模板库中自带了一个 Release 工作流, 你可以使用此工作流发布你的插件到 PyPI
配置 PyPI Trusted Publisher
配置文档: https://docs.pypi.org/trusted-publishers/adding-a-publisher/- PyPI Project Name: nonebot-plugin-template
- Owner: Your GitHub username
- Repository name: nonebot-plugin-template
- Workflow name: release.yml
- Environment name: release
使用 Commitizen 更新版本号,并触发 Release 工作流 (推荐)
确保已安装 just,然后执行:
just bump该操作会:
- 根据 conventional commits 自动确定版本号
- 更新
pyproject.toml中的版本号和CHANGELOG.md - 更新
uv.lock中的版本号 - 创建一个带
v*tag 的提交
也可以手动指定版本递增:
uv run cz bump --increment patch/minor/major
接下来推送提交和 tag:
git push origin main --tags触发 Release 工作流 (手动)
更新版本号
uv version --bump patchpossible values: major, minor, patch, stable, alpha, beta, rc, post, dev
提交并推送...
从本地推送任意 tag 即可触发。
创建 tag:
git tag v*推送本地所有 tag:
git push origin --tagsImportant
不会使用 uv ?
不会看文档去
安装 uv
windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"curl:
curl -LsSf https://astral.sh/uv/install.sh | shpipx:
pipx install uv安装所有依赖(自动创建 venv 虚拟环境, -p 指定 python 版本):
uv sync --all-groups -p 3.12添加其他依赖, 例如 koishi(bushi
uv add koishiNote
pre-commit / prek 使用方法
提交前检查
安装 pre-commit
uv tool install pre-commit或安装 prek (推荐)
On Linux / macOS:
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.2.13/prek-installer.sh | shOn Windows:
powershell -ExecutionPolicy ByPass -c "irm https://github.com/j178/prek/releases/download/v0.2.13/prek-installer.ps1 | iex"安装钩子
pre-commit install
prek install添加到暂存区
git add <待提交文件>仓库地址: