如何在 2025 年向 Gunicorn 官方提交一个 PR 并通过 DCO 检查?
解读
面试官想确认三件事:
- 你是否熟悉 Gunicorn 2025 年的官方协作流程(GitHub 已强制启用 DCO 签名 与 双因子身份验证)。
- 你是否能在国内网络环境下完成 合规的 Git 配置、镜像加速、issue 关联 与 CI 通过。
- 你是否理解 DCO 与 CLA 的区别,并能在命令行一次性通过检查,避免“push -f”污染历史。
知识点
- DCO(Developer Certificate of Origin):每条 commit 必须有
Signed-off-by:行,证明你有权提交。 - GitHub 镜像:国内使用
ghproxy.com或gitclone.com加速git clone https://github.com/benoitc/gunicorn.git。 - pre-commit 钩子:Gunicorn 2025 年仓库自带
.pre-commit-config.yaml,强制运行ruff、mypy、dco-check。 - issue 模板:必须引用
Fix #xxxx或Relates to #xxxx,否则 CI 机器人自动关闭 PR。 - worker 类型回归测试:提交代码后,CI 会在
ubuntu-24.04、alpine-3.20、python-3.13矩阵下跑tox -e py313-sync,py313-uvloop,py313-gevent。 - 国内 GPG 签名:若使用 GPG,需把公钥上传到 GitHub 并配置
git config --global gpg.program gpg2,否则 DCO bot 会报 “Unsigned commit”。 - rebase 策略:Gunicorn 官方要求一个 feature 一个 commit,禁止 merge commit,必须使用
git rebase -i压缩。
答案
步骤如下,全部在境内可复现:
-
环境准备
- 安装 Python 3.13、git ≥ 2.45、tox ≥ 4.0、pre-commit ≥ 3.7。
- 配置 Git 用户:
git config --global user.name "Li Lei" git config --global user.email "lilei@example.com" git config --global core.autocrlf input git config --global commit.gpgsign true # 若已启用 GPG - 通过
ghproxy.com加速克隆:git clone https://hub.gitclone.com/https://github.com/benoitc/gunicorn.git cd gunicorn
-
创建分支并开发
- 基于最新
main创建功能分支:git checkout -b fix-2025-dco-demo - 编写代码,确保新增单元测试位于
tests/workers/test_sync.py,覆盖率不低于 95%。
- 基于最新
-
本地质量门禁
- 安装钩子:
pre-commit install --hook-type commit-msg - 运行检查:
tox -e lint,type,test - 若 DCO 钩子报错,用
git commit --amend --signoff补签。
- 安装钩子:
-
提交并推送
- 单 commit 提交:
git add . git commit -s -m "worker: fix fd leak on reload Relates to #2345 Signed-off-by: Li Lei <lilei@example.com>" - 推送:
git push origin fix-2025-dco-demo
- 单 commit 提交:
-
创建 PR
- 在 GitHub 页面勾选 “Allow edits by maintainers”,模板中填写:
- 问题描述
- 复现步骤
- 测试脚本
- 回归结果截图文本
- 确认 “Commits” 标签页每条都有 Verified 与 Signed-off-by。
- 在 GitHub 页面勾选 “Allow edits by maintainers”,模板中填写:
-
CI 通过
- 等待 GitHub Actions 全部绿灯,若出现
alpine-3.20镜像拉取超时,可在 PR 评论/retry-ci触发重跑。 - 若 DCO bot 仍报错,本地
git rebase HEAD~1 --signoff后git push -f。
- 等待 GitHub Actions 全部绿灯,若出现
-
维护人评审
- 响应 review 意见,48 小时内 force-push 更新;每次更新仍保持单 commit 并含 signoff。
- 评审通过后,维护人使用
Squash and merge入库,DCO 状态必须为 ✅。
拓展思考
- 企业内网场景:若公司代码需同步到内部 GitLab,可在
.git/config中增加pushInsteadOf映射,保证对外 PR 的 commit-id 与内部一致,满足审计。 - 大文件处理:Gunicorn 2025 年已启用 Git LFS 存储
tests/fixtures/large-body.bin,国内用户需配置git lfs clone https://hub.gitclone.com/...避免超时。 - 安全加固:建议把 DCO 签名与国产商用密码算法结合,使用
sm2密钥做 GPG 签名,既合规又能通过 GitHub 验证。 - 自动化:可写 GitHub App 监听
pull_request.opened,自动评论/ok-to-test与 DCO 状态,减少维护人手工操作。