@@ -3,17 +3,48 @@ name: mcpp-contributing
33description : Use when contributing to the mcpp project — submitting bug fixes, new features, code optimizations, documentation improvements, or any PR. Covers issue creation, branch conventions, build verification, CI requirements, and PR workflow using gh and git.
44---
55
6- # mcpp 项目开发贡献
6+ # mcpp 项目开发贡献规范
77
88## Overview
99
10- mcpp 项目的贡献流程:先创建 Issue → 实现改动 → 提交 PR → CI 通过 → Review 合入。
10+ mcpp 项目的贡献流程:先创建 Issue → 切分支 → 实现改动 → 提交 PR → CI 通过 → Review 合入。
1111
1212- 仓库:https://github.com/mcpp-community/mcpp
1313- 构建:` mcpp build ` (C++23 模块自举)
1414- 测试:` tests/e2e/ ` 下的 bash 脚本
1515- CI:GitHub Actions,base 为 ` main ` 的 PR 自动触发
1616
17+ ## 核心原则
18+
19+ ### 禁止直接 push main
20+
21+ ** 所有改动必须通过 PR 合入 main** ,无论改动大小。这包括:
22+ - 代码改动(feat / fix / refactor)
23+ - 文档改动(docs / skills / .agents/)
24+ - 配置改动(mcpp.toml / .xlings.json / CI workflow)
25+ - 版本号 bump(必须通过 PR,不能直接 push)
26+
27+ ** 唯一例外** :紧急 hotfix 需要 ` --admin ` 合入,但也必须先创建 PR。
28+
29+ 违规示例(不允许):
30+ ``` bash
31+ # ✗ 直接 push 到 main
32+ git commit -m " docs: add skill" && git push origin main
33+
34+ # ✗ 绕过分支保护
35+ git push origin feature:main
36+ ```
37+
38+ 正确做法:
39+ ``` bash
40+ # ✓ 始终走 PR 流程
41+ git checkout -b docs/add-release-skill
42+ git commit -m " docs: add release skill"
43+ git push -u origin docs/add-release-skill
44+ gh pr create --title " docs: add release skill" --body " ..."
45+ # 等 CI 通过后合入
46+ ```
47+
1748## 贡献流程
1849
1950### 1. 创建 Issue(必须)
@@ -66,20 +97,31 @@ gh issue create \
6697..."
6798```
6899
69- ### 2. 实现改动
100+ ### 2. 创建分支
70101
71- ** 分支 **
102+ ** 必须从最新 main 创建分支,禁止在 main 上直接开发。 **
72103
73104``` bash
74105git checkout main && git pull origin main
75106git checkout -b < type> /< short-description>
76- # type: feat / fix / refactor / test / docs
107+ # type: feat / fix / refactor / test / docs / chore
77108```
78109
110+ 分支命名规范:
111+ - ` feat/xxx ` — 新功能
112+ - ` fix/xxx ` — Bug 修复
113+ - ` refactor/xxx ` — 重构
114+ - ` test/xxx ` — 测试
115+ - ` docs/xxx ` — 文档
116+ - ` chore/xxx ` — 版本 bump、配置、依赖更新
117+
118+ ### 3. 实现改动
119+
79120** 开发要求**
80121- 遵循现有代码风格(查看相邻代码)
81122- 模块导入用 ` import std; ` 和 ` import mcpp.xxx; `
82123- 只改需要改的,不顺手重构不相关代码
124+ - 平台相关代码放在 ` src/platform/ ` 目录下
83125
84126** 构建验证**
85127
@@ -98,9 +140,9 @@ bash tests/e2e/<relevant-test>.sh # 相关测试
98140# 新功能应创建对应 E2E 测试
99141```
100142
101- ### 3 . 提交 PR
143+ ### 4 . 提交 PR
102144
103- ** 提交信息 ** :` feat: ` / ` fix: ` / ` refactor: ` / ` test: ` / ` docs: ` 前缀
145+ ** 提交信息前缀 ** :` feat: ` / ` fix: ` / ` refactor: ` / ` test: ` / ` docs: ` / ` chore: `
104146
105147``` bash
106148git push -u origin < branch>
@@ -116,7 +158,13 @@ Closes #<issue>
116158- [ ] E2E 测试通过"
117159```
118160
119- ### 4. CI 必须通过
161+ ** PR 要求** :
162+ - title 用英文,body 中英文均可
163+ - 关联 Issue(` Closes #N ` )
164+ - 包含 test plan
165+ - 一个 PR 只做一件事,不混入无关改动
166+
167+ ### 5. CI 必须通过
120168
121169CI 不通过的 PR 不会被合入。
122170
@@ -125,11 +173,68 @@ gh pr checks <pr-number> # 查看状态
125173gh run view < run-id> --log-failed # 查看失败日志
126174```
127175
128- CI 内容:mcpp 自举构建 + E2E 测试。只有 base 为 ` main ` 的 PR 触发。
176+ CI 包含三个平台:
177+ | Workflow | 平台 | 内容 |
178+ | ----------| ------| ------|
179+ | ` ci ` | Linux x86_64 | 自举构建 + E2E 测试 |
180+ | ` ci-macos ` | macOS ARM64 | 自举构建 + E2E 测试 |
181+ | ` ci-windows ` | Windows x86_64 | 自举构建 + E2E 测试 |
182+
183+ ** 三个平台全部通过才能合入。** 如果某个平台失败:
184+ 1 . 下载日志分析原因
185+ 2 . 修复后 push 到同一分支,CI 自动重跑
186+ 3 . 如果是 flaky test,在 PR 中说明
129187
130- ### 5 . Review & 合入
188+ ### 6 . Review & 合入
131189
132- 维护者 review → 反馈修改 → CI 重跑 → Squash merge。
190+ 维护者 review → 反馈修改 → CI 重跑 → Merge(保留 commit 历史)。
191+
192+ 合入方式:
193+ - 默认使用 ** Merge commit** (保留完整历史)
194+ - 单 commit 的 PR 也可用 ** Squash merge**
195+
196+ ## Agent 开发规范
197+
198+ Agent(Claude Code 等)在执行任务时,** 同样必须遵守 PR 流程** :
199+
200+ ### Agent 必须做的
201+ - 从最新 main 切新分支
202+ - 所有改动通过 PR 提交
203+ - 等 CI 通过后再请求合入
204+ - 合入前先确认 PR 无冲突
205+
206+ ### Agent 禁止做的
207+ - 直接 push 到 main(即使有 admin 权限)
208+ - 绕过 CI 检查合入
209+ - 在已合入的分支上继续开发(应切新分支)
210+ - 一个 PR 混入不相关的改动
211+
212+ ### Agent 的典型工作流
213+
214+ ``` bash
215+ # 1. 从最新 main 切分支
216+ git checkout main && git pull origin main
217+ git checkout -b < type> /< description>
218+
219+ # 2. 实现改动
220+ # ... edit files ...
221+
222+ # 3. 提交并推送
223+ git add < files>
224+ git commit -m " <type>: <description>"
225+ git push -u origin < type> /< description>
226+
227+ # 4. 创建 PR
228+ gh pr create --title " <type>: <description>" --body " ..."
229+
230+ # 5. 等 CI 通过
231+ # 每 60s 检查一次,失败则分析修复
232+ gh run list --branch < branch> --limit 3
233+
234+ # 6. CI 全部通过后,请求用户 review 合入
235+ # 或者用户授权后:
236+ gh pr merge < pr-number> --merge
237+ ```
133238
134239## 项目结构
135240
@@ -138,6 +243,17 @@ src/
138243├── cli.cppm ← 命令行入口
139244├── config.cppm ← 全局配置
140245├── manifest.cppm ← mcpp.toml 解析
246+ ├── platform/ ← 平台抽象层(所有平台相关代码)
247+ │ ├── platform.cppm ← 统一外观模块
248+ │ ├── common.cppm ← 平台常量与检测
249+ │ ├── process.cppm ← 进程执行(自动 stdin 保护)
250+ │ ├── fs.cppm ← 文件系统(exe 路径、文件锁)
251+ │ ├── shell.cppm ← Shell 引用
252+ │ ├── env.cppm ← 环境变量
253+ │ ├── terminal.cppm ← 终端检测
254+ │ ├── macos.cppm ← macOS 特有
255+ │ ├── linux.cppm ← Linux 特有
256+ │ └── windows.cppm ← Windows 特有
141257├── build/ ← 构建系统(ninja 后端)
142258├── pm/ ← 包管理子系统
143259├── toolchain/ ← 编译器检测管理
@@ -153,5 +269,7 @@ docs/ ← 用户文档
153269## 注意事项
154270
155271- C++23 模块项目,修改模块时注意 import 依赖顺序
272+ - 平台相关代码统一放 ` src/platform/ ` ,不在其他模块中直接使用 ` #if defined `
156273- E2E 测试应独立运行,不依赖网络
157274- 不确定方向时先在 Issue 讨论再动手
275+ - ** 永远走 PR 流程,不直接 push main**
0 commit comments