LegionForge/dev-rig
GitHub: LegionForge/dev-rig
一套面向 Python 项目的共享 CI 安全工作流和开发工具集,帮助团队在多个项目中统一实施代码质量检查、安全扫描、依赖审计和合规管理。
Stars: 0 | Forks: 0
# LegionForge dev-rig
用于 LegionForge 项目的共享 CI 流水线、pre-commit 钩子和 pytest fixtures。
## 包含内容
| 路径 | 用途 |
|---|---|
| `.github/workflows/lint.yml` | 可复用 CI 作业:ruff + bandit + mypy |
| `.github/workflows/test.yml` | 可复用 CI 作业:pytest + 覆盖率强制检查 |
| `.github/workflows/sast.yml` | 可复用 CI 作业:semgrep (p/python + p/fastapi) + CodeQL |
| `.github/workflows/audit.yml` | 可复用 CI 作业:pip-audit CVE 扫描 + pip-licenses 合规检查 |
| `.github/workflows/secrets.yml` | 可复用 CI 作业:gitleaks 密钥扫描 |
| `.github/workflows/sbom.yml` | 可复用 CI 作业:CycloneDX SBOM 生成 |
| `.pre-commit-hooks.yaml` | 通过 pre-commit 使用的钩子定义 |
| `.pre-commit-config.yaml` | 复制到新项目中的默认配置(包含 gitleaks) |
| `SECURITY.md` | 漏洞披露策略模板 — 复制并修改 |
| `src/legionforge_dev_rig/fixtures/` | 共享 pytest fixtures(httpx mock 等) |
| `examples/` | 模板 conftest.py 和示例测试 |
## 接入新项目
### 1 — 将 dev-rig 安装为开发依赖
在发布到 PyPI 之前,请从本地克隆路径以可编辑模式进行安装:
```
# 从消费项目的根目录
pip install -e "../../LegionForge-dev-rig/dev-rig"
# 或者一旦发布:
pip install legionforge-dev-rig
```
添加到 `pyproject.toml`:
```
[project.optional-dependencies]
dev = [
# ... project deps ...
"legionforge-dev-rig",
]
```
### 2 — 复制 pre-commit 配置
```
cp ../../LegionForge-dev-rig/dev-rig/.pre-commit-config.yaml .
```
调整 mypy 钩子下的 `additional_dependencies` 以匹配项目的运行时依赖,然后执行:
```
pre-commit install
pre-commit run --all-files # validate clean baseline
```
### 3 — 接入 CI
从 llm-valet 中的 `ci.yml` 注释复制调用块,或使用此模板:
```
# .github/workflows/ci.yml
name: CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main]
jobs:
lint:
uses: LegionForge/dev-rig/.github/workflows/lint.yml@main
with:
source-dirs: "my_package" # ← your source directories
test:
uses: LegionForge/dev-rig/.github/workflows/test.yml@main
with:
coverage-source: "my_package" # ← package name for --cov
coverage-threshold: 80
sast:
uses: LegionForge/dev-rig/.github/workflows/sast.yml@main
with:
source-dirs: "my_package/"
permissions:
security-events: write
audit:
uses: LegionForge/dev-rig/.github/workflows/audit.yml@main
```
### 4 — 将共享 fixtures 添加到 tests/conftest.py
```
# tests/conftest.py
from legionforge_dev_rig.fixtures import mock_http_client, respx_mock_base_url
__all__ = ["mock_http_client", "respx_mock_base_url"]
```
随后 fixtures 将在所有测试中可用,无需导入。有关用法请参见 `examples/test_provider_http_example.py`。
## 更新开发套件
当您添加或更改可复用工作流或 fixture 时:
1. 在 `pyproject.toml` 中更新版本号
2. 为发布打标签:`git tag v0.x.0 && git push --tags`
3. 在接入的项目中,更新 `.pre-commit-config.yaml` 的 `rev:` 以及 CI 调用中的 `@main` 引用
要在所有项目中一次性拉取最新的钩子:
```
pre-commit autoupdate
```
## 工具版本
| 工具 | 最低版本 | 配置位置 |
|---|---|---|
| ruff | 0.4 | `pyproject.toml [tool.ruff]` |
| bandit | 1.7 | `pyproject.toml [tool.bandit]` |
| mypy | 1.10 | `pyproject.toml [tool.mypy]` |
| pip-audit | 2.7 | 无配置 — 针对已安装的包运行 |
| semgrep | 1.70 | 作为 CLI 参数传递的规则集 |
| pytest-cov | 5 | `pyproject.toml [tool.pytest.ini_options]` |
| pre-commit | 3.7 | `.pre-commit-config.yaml` |
标签:Bandit, CodeQL, CycloneDX, DevSecOps, GitHub Actions, gitleaks, httpx, LegionForge, Libemu, Licenses合规, Mypy, pip-audit, pre-commit, pytest, Python, Ruff, SAST, SBOM, Semgrep, WordPress安全扫描, 上游代理, 人工智能安全, 依赖审计, 合规性, 安全基线, 安全规则引擎, 安全评估工具, 工作流模板, 教学环境, 无后门, 模板项目, 测试夹具, 盲注攻击, 硬件无关, 自动笔记, 跌倒检测, 软件物料清单, 运行时操纵, 逆向工具, 静态应用安全测试