ci(gates): 覆盖率总闸与全量 cppcheck 移到远端 CI 强制(提交期实跑 48 根)
用户裁定 2026-10-28:慢钩子不再压在每个 git commit 上,由远端 CI 强制;本地等价入口 = scripts/ci_local.py 的 manual 段。 实测三根耗时:cppcheck 20.5 s、test-cppcheck 38.1 s、 test-coverage 105.2 s,合计 ~165 s ≈ 一次带代码提交耗时的 三分之二(test-coverage 的 files: 覆盖 App/,改一行就跑光 40 套)。 - .pre-commit-config.yaml:cppcheck / test-cppcheck / test-coverage 加 stages: [manual] + 理由注释;替换掉 test-coverage 上方「没写 stages → 所有阶段都跑、输出出现两次」 的旧坑注释(固定 manual 后不再有这一坑)。 - .gitea/workflows/ci.yml:static-gates job 在静态门禁步之后 新增「手动阶段门禁(覆盖率总闸 + 全量 cppcheck)」步, if: always(),逐根 --hook-stage manual(pre_commit run 不支持 多 id),日志 ci-artifacts/manual-stage.log + 归档 + STEP_SUMMARY, rc≠0 即失败;run 块纯 ASCII。 - scripts/ci_local.py:新增 MANUAL_STAGE_HOOKS 与 run_manual_stage() (静态段之后默认跑),删 run_coverage() 死代码,--coverage 降级为兼容别名。 - AGENTS.md + 12 篇 docs/scripts/README:三数同源口径改为 声明 51 / 提交期 --all-files 实跑 47 / +gitlint = 48, 其余 3 根在 manual 阶段;历史测量数字只加「当时」不回改。 验证:pre-commit run --all-files = 47 Passed / 0 Failed rc=0; manual 三根 Passed(test-coverage line 89.8% func 93.2% 41/41 套); ci_local.py --static-only 全绿;check_doc_links --all --sections-strict rc=0、mojibake / bom-drift / id-check-new rc=0; ci.yml yaml.safe_load 通过。未改任何 .c/.h,故未跑 @build。
This commit is contained in:
@@ -198,14 +198,16 @@ python tools/font_gen/extract_cn.py # 任意 python3:
|
||||
|
||||
| 项 | 要求 | 说明 |
|
||||
|---|---|---|
|
||||
| pre-commit | 已安装并 `pre-commit install` | 提交门禁(pre-commit + commit-msg 两类钩子) |
|
||||
| cppcheck | 在 PATH 中 | 本地钩子直接调 `cppcheck --enable=warning,performance,portability,style`(`language: system`) |
|
||||
| pre-commit | 已安装并 `pre-commit install` | 提交门禁(`pre-commit` 阶段 47 根 + commit-msg 阶段 `gitlint`,一次提交实跑 48 根) |
|
||||
| cppcheck | 在 PATH 中 | 钩子直接调 `cppcheck --enable=warning,performance,portability,style`(`language: system`)。⚠ `cppcheck` / `test-cppcheck` / `test-coverage` 三根带 `stages: [manual]`:`git commit` 不跑,由远端 CI 的「手动阶段门禁」步与 `scripts/ci_local.py` 的 manual 段跑(CI runner 缺 cppcheck 则该步失败) |
|
||||
| python | 在 PATH 中 | 本地钩子调 `scripts/check_mojibake.py`(U+FFFD 乱码)、`scripts/check_coding_standard.py`(规范 V1.0,纯标准库) |
|
||||
| **MSVC `cl.exe`** | **装了 VS 即有(§2.3)** | **`watchdog-unit-test` 钩子必需**:改 `App/util/task_watchdog.*` 或 `test/host/watchdog/**` 时触发,用 `cl.exe` 离线编译真实源码跑单测。**未装 VS 时该钩子报环境错误(退出码 2)→ 拦截提交** |
|
||||
| gitlint | 随 pre-commit 自动拉取 | commit message 格式(宽松规则,兼容中文标题) |
|
||||
|
||||
> 检查范围仅项目自有代码;`Lib/`、`Middlewares/`、`Drivers/BSP/UI`、`lftpd`、`dhara`、`test/` 等被排除。
|
||||
> 全库扫描:`pre-commit run --all-files`。详见 `docs/代码规范/pre-commit使用说明.md`、`docs/代码规范/cppcheck使用说明.md`。
|
||||
> 全库扫描:`pre-commit run --all-files`(提交期 47 根);三根 manual 钩子逐根复跑:
|
||||
> `& '.venv\Scripts\python.exe' -m pre_commit run --all-files --hook-stage manual <hook-id>`(一次只能一个 id)。
|
||||
> 详见 `docs/代码规范/pre-commit使用说明.md`、`docs/代码规范/cppcheck使用说明.md`。
|
||||
>
|
||||
> ⚠ **新增主机侧纯逻辑单测钩子(2026-10-01)后,"装了 VS"从"仅模拟器需要"升级为"提交门禁需要"**:
|
||||
> 只要装了 VS(§2.3)就自动具备,无需额外安装;但**完全未装 VS 的机器在改动看门狗相关文件时会被钩子拦截**。
|
||||
@@ -325,7 +327,9 @@ uv tool install pre-commit
|
||||
winget install cppcheck # 2.21.0(安装位置任意;入 PATH 或用 DTU_CPPCHECK 指向)
|
||||
# ★ 重开终端(PATH 才生效),然后:
|
||||
pre-commit install
|
||||
pre-commit run --all-files # 首次全库基线扫描
|
||||
pre-commit run --all-files # 首次全库基线扫描(提交期 47 根)
|
||||
# manual 阶段三根(cppcheck / test-cppcheck / test-coverage,提交期不跑)逐根跑,一次一个 id:
|
||||
& '.venv\Scripts\python.exe' -m pre_commit run --all-files --hook-stage manual cppcheck
|
||||
```
|
||||
|
||||
> 手动下载:uv → https://astral.sh/uv/ (一行安装 `powershell -c "irm https://astral.sh/uv/install.ps1 | iex"`)· pre-commit → https://pre-commit.com/ · cppcheck 2.21.0 → https://github.com/CppQA/cppcheck/releases (2.21.0 tag 的 Windows x64 zip,解压至任意目录并加入 PATH,或用 `DTU_CPPCHECK` 指向 `cppcheck.exe`)
|
||||
@@ -363,7 +367,7 @@ pre-commit run --all-files # 首次全库基线扫描
|
||||
& '.venv\Scripts\python.exe' simulator\tests\check_content_pages.py # PASS(基准 ref/*.bin 已入库,无需先生成)
|
||||
& '.venv\Scripts\python.exe' .dsh\skills\serial-assistant\scripts\serial_tool.py selftest # → SELFTEST PASS
|
||||
& '.venv\Scripts\python.exe' test\host\watchdog\run_unit_test.py # 主机侧单测 → 39/39 PASSED(退出码 0)
|
||||
pre-commit run --all-files
|
||||
pre-commit run --all-files # 提交期 47 根(manual 三根另跑:--hook-stage manual <id>,或直接 ci_local.py)
|
||||
```
|
||||
|
||||
**搭建清单汇总**(随步骤逐项打勾):
|
||||
|
||||
Reference in New Issue
Block a user