Merged
test(ci): add code gate #261
test(ci): add code gate #261
Merged
zouziqiangAdd on 17 days ago
zouziqiang
zouziqiang
17 days ago

当前PR是否有AI参与:

[x] 否

[ ] 是
__1. AI Agent 平台:
__2. AI 模型:
__3. Prompt上下文 :

参考:openEuler社区《生成式AI工具使用与开源贡献政策》

PR功能描述 / 为什么需要这个合入**:

该PR关联的issue

(格式为fixes #<issue号>, 或者resolves #<issue号>): fixes #

希望检视人员了解:

likedislike
Pull Request has been successfully merged by openeuler-ci-bot.
(Thank you for zouziqiang's contribution.)
zouziqiangzouziqiang
17 days ago Created pull request, commit 6c5f7b15
atomgit-bot
atomgit-bot
17 days ago Comments:

变更摘要

本 PR 新增了一个独立的接口门禁脚本 check_interface.sh,用于在两个 git ref(分支、tag 或 commit)之间自动检测接口约定的变更。脚本通过环境变量 BASE、TARGET 或两个位置参数确定比较范围,不 clone 仓库、不修改当前工作区,按 8 个阶段依次执行:解析 ref、准备工具、收集变更文件、proto 接口检查、OpenAPI 接口检查、生成文件检查、生成 proto 检查、生成代码检查,并统一汇总失败与异常后以 0、1、2 退出。整体目标是把接口的新增、删除、不兼容修改以及生成物未同步等情况都作为门禁失败,交由人工确认。

主要改动

  • 门禁主流程与退出码约定: 新增 stage_begin/stage_end/stage 阶段框架、FAILURES/ERRORS 汇总数组与 cleanup trap,按 8 个阶段串行执行并输出各阶段耗时,正常通过返回 0、接口变更返回 1、参数或工具错误返回 2。
  • 工具自动安装与缓存复用: 通过 ensure_tools、resolve_tool、install_tool 使用 go install 安装 buf(v1.75.0)和 oasdiff(v1.35.0)到 XDG_CACHE_HOME/~/.cache/临时目录下的工具缓存目录,按版本命名并在 --version 校验通过后复用。
  • proto 接口兼容性检查: check_proto_module 为每个 proto 目录生成临时 buf 模块(stage_proto_module 仅复制目录下直接 proto 文件),在 buf.yaml 中配置 breaking.use: FILE 并排除 FILE_SAME_GO_PACKAGE 等代码生成类 option;同时做正向与反向两次 buf breaking,正向捕获删除与不兼容修改、反向捕获纯新增,并由 report_proto_findings 输出文件与行号。
  • OpenAPI 接口检查: check_openapi 用 is_openapi_ref 识别 openapi: 声明的 YAML,通过 oasdiff changelog --fail-on INFO --severity-levels 比较,使用 severity 文件把 api-tag-added/api-tag-removed 置为 NONE 使仅改 tag 不触发失败,并由 report_oasdiff_findings 与 locate_line 还原文件、行号和中文原因。
  • 生成文件与生成代码一致性校验: check_generated_files 依据 // Code generated ... DO NOT EDIT. 识别生成文件并回溯来源(source: 注释、同目录 generate.go、sqlc 的 .sql),来源未变即判失败;check_generated_proto 与 check_generated_openapi 在临时 git worktree 中按目录锁定插件版本(如 protoc-gen-go v1.28.1/v1.36.6、protoc-gen-go-grpc v1.6.1、protoc-gen-connect-go v1.21.1)重新执行 buf generate 和 go generate,忽略注释与版本行后比对 diff。
likedislike
Incorrect?
atomgit-bot
atomgit-bot
17 days ago Comments:

代码审查

审查结论

改动文件覆盖情况

  • check_interface.sh(新增 1400 行):已逐段审查(参数解析、耗时统计、工具安装、proto breaking、oasdiff、生成文件检测、buf generate 回放、go generate 比对、汇总退出码),共发现 8 个问题,见下。

问题清单(按优先级)

  • P2 ×2:插件安装失败被 || return 0 / || true 静默吞掉,生成检查不执行但门禁给出"通过"(第1128-1129 行,及 1137/1144/1145/1173);is_openapi_ref 只看前 40 行,长头部注释的 OpenAPI 文件被判为"非 OpenAPI"而跳过比较(第544-545 行)。
  • P3 ×6:生成文件来源仅按 basename 匹配导致同名 proto 误判(777-784);for tok in $line 未关闭 glob 导致来源路径被展开/拆分(827-833);第8阶段用全 worktree 的 git status 比对,误把第7阶段残留归因为 OpenAPI 不一致(1231-1239);resolve_tool 优先使用 PATH 中任意版本、绕过版本锁定(275-278);共享缓存目录用固定名中间产物与日志,并发门禁互相覆盖(242-250);头部用法注释脚本名与文件名不一致(5-7)。

未发现的问题类型:set -euo pipefail 已启用;rm -rf 各处均有非空/-d 保护(TMP_DIR 来自 mktemp -d);cd 全部在命令替换的子 shell 内,不污染主 shell;git diff/git show 路径均正确引用;ERRORS/FAILURES 未被管道子 shell 吞掉(report_proto_gen_diff 用 here-string 而非管道,写法正确);调用点参数顺序与函数签名逐一核对一致,未发现张冠李戴的实参错位。

整体风险判断:脚本结构清晰、错误处理大体到位,但存在两处门禁静默放行的口子(工具安装失败当通过、OpenAPI 文件识别窗口过窄),与"接口变更一律拦截"的 PR 目标直接冲突,建议合入前至少修复这两个 P2;其余 P3 属于归因准确性与并发健壮性问题,可以后续跟进。

另外:本 PR 只新增了脚本,diff 中没有任何 workflow/CI 配置引用 check_interface.sh,若门禁需要真正生效,还需确认流水线侧的接入是否存在。

类型 数量
🔴 阻塞 0
🟡 建议 2

💬 仅评论

likedislike
Incorrect?
openeuler-ci-botopeneuler-ci-botCollaborators
17 days ago Set weibaohui,yangzhao_kl,jimmieme,duguhaotian,wonleing,zmr_2020,gaodaweiky,lu-wei-army,feijianqiang,zhaoyifan28 as approver
openeuler-ci-botopeneuler-ci-botCollaborators
17 days ago Added label: sig/sig-CloudNative
openeuler-ci-bot
openeuler-ci-botCollaborators
17 days ago Comments:

Welcome To openEuler Community

Hey @zouziqiang , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands. You can self-configure the PR merge rules for this repository. For more details, please refer to Here.

Contact Guide

If you have any questions, please contact the SIG: sig-CloudNative ,
and any of the maintainers: @duguhaotian, @feijianqiang, @gaodaweiky, @jimmieme, @lu-wei-army, @weibaohui, @wonleing, @yangzhao_kl, @zhaoyifan28, @zmr_2020 ,
and any of the committers: @feijianqiang, @zhourenjianz .

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
17 days ago Added label: openeuler-cla/yes
openeuler-botopeneuler-botCollaborators
17 days ago Added label: ci_processing
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:

门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/KASandbox/570

likedislike
openeuler-botopeneuler-botCollaborators
17 days ago Removed label: ci_processing
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:
Check Name Build Result 详情 Build Details
check_package_license ✅SUCCESS #570
check_sca ✅SUCCESS
x86_64 check_build ✅SUCCESS #573
aarch64 check_build ✅SUCCESS #589
DT check_build ✅SUCCESS #586
check_interface check_build ✅SUCCESS #17
likedislike
openeuler-botopeneuler-botCollaborators
17 days ago Added label: ci_successful
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:
likedislike
atomgit-bot
atomgit-bot17 days agoStart code review2
check_interface.sh
Outdated
@@ -0,0 +542,4 @@
542+ 
543+ git cat-file -e "${ref}:${path}" 2>/dev/null || return 1
544+ head="$(git show "${ref}:${path}" 2>/dev/null | sed -n '1,40p' || true)"
545+ printf '%s\n' "$head" | grep -E "^openapi:[[:space:]]*[\"']?[0-9]" >/dev/null
atomgit-bot
atomgit-bot17 days agoComments:

🟡 Medium Priority

证据链:第544 行 head="$(git show "${ref}:${path}" 2>/dev/null | sed -n '1,40p' || true)",第545 行再从中 grep ^openapi:。第714-719 行用该函数设置 base_openapi/head_openapi,第729-731 行在两者都为 0 时走 else info "[openapi] 跳过(不是 OpenAPI 规范): $f" 并继续,本阶段既不产生 FAILURES 也不产生 ERRORS。

失败模式:若某个契约 YAML 顶部有超过 40 行的 license/说明注释块(或 %YAML 指令 + 大段注释),openapi: 落在第 40 行之后,is_openapi_ref 返回 1,该文件被判定为"不是 OpenAPI",于是本可被 oasdiff 抓出的接口新增/删除/修改完全不比较,第5阶段报"通过",整体 exit 0。这是门禁的静默漏检(第8阶段的 go generate 比对只在路径命中第1256-1268 行的固定白名单时才兜底,且只查生成物是否同步,不查接口是否变更)。触发条件具体(头部注释 > 40 行),失败模式明确(接口变更未被门禁发现)。

建议:放宽扫描窗口(或直接对整文件做一次 grep,YAML 规范要求 openapi 是顶层键,全文件匹配不会产生误判),例如把 sed -n '1,40p' 改为 sed -n '1,200p',或改用 grep -m1 -E '^openapi:' 直接扫全文。

Suggestions
545
+ head="$(git show "${ref}:${path}" 2>/dev/null || true)"
545
546
  printf '%s\n' "$head" | grep -E "^openapi:[[:space:]]*[\"']?[0-9]" >/dev/null
Apply suggestion
likedislike
Incorrect?
System
System MessageSystem
17 days ago Comments:

changed this line on 0e2217d2 view diff detail

likedislike
atomgit-bot
atomgit-bot17 days agoStart code review2
check_interface.sh
Outdated
@@ -0,0 +1126,4 @@
1126+ if [ "$envd" -eq 1 ]; then
1127+ info "[generated/proto] 重新生成 envd spec(go ${PROTO_GO_VERSION} + connect ${PROTO_CONNECT_VERSION})"
1128+ gobin="$(install_proto_plugin protoc-gen-go google.golang.org/protobuf/cmd/protoc-gen-go "$PROTO_GO_VERSION")" || return 0
1129+ connectbin="$(install_proto_plugin protoc-gen-connect-go connectrpc.com/connect/cmd/protoc-gen-connect-go "$PROTO_CONNECT_VERSION")" || return 0
atomgit-bot
atomgit-bot17 days agoComments:

🟡 Medium Priority

证据链:新增代码第1128/1129、1137、1144/1145 行以 gobin="$(install_proto_plugin ...)" || return 0 的形式调用插件安装;第1173 行 generate_cri_proto "$job" || true 内部第1041/1042 行同样 || return 1。而 install_proto_plugin(927-954 行)失败时只执行 bad " - $name 安装失败..." 打印到 stderr 并 return 1,不会 ERRORS+=(...);对比同一文件里 prepare_generation_worktree(1197 行)、run_buf_generate(986 行)、run_go_generate(1215 行)失败都会写入 ERRORS。

失败模式:CI 容器里 go install 拉不到模块(GOPROXY 不可达)、Go 版本过旧导致 GOTOOLCHAIN 下载失败、或缓存目录不可写时,check_generated_proto 直接 return 0 返回,既不产生 FAILURES 也不产生 ERRORS,脚本继续走完第8阶段并最终 exit 0 打印"接口门禁检查通过"(1372-1400 行)。即:proto 生成物检查根本没执行,门禁却给出通过结论,这正是本 PR 要防的场景。同时因为 || return 0 提前返回,后面 legacy/orchestrator/cri 各组也一并被跳过。触发条件明确(插件安装失败 + 其余检查无问题),不是纯猜想。

建议:在 install_proto_plugin 的失败分支里(950-953 行)先 ERRORS+=("安装 proto 插件失败: $name $version") 再 return 1;调用点不要用 return 0 静默跳过,改为 || return 0 时也留下 ERRORS(或统一改成 || { return 0; } 前先记录)。第1137、1144、1145 行以及 generate_cri_proto 内的 || return 1(配合第1173 行 || true)同样需要记录 ERRORS,使工具安装失败最终以退出码 2 报"异常",而不是被当作通过。

likedislike
Incorrect?
System
System MessageSystem
17 days ago Comments:

changed this line on 0e2217d2 view diff detail

likedislike
zouziqiangzouziqiang
17 days ago Pre merge succeeded (commit_id: a37c3a04c10e0fe9b8a733863b369e77aa8c111b)
5 event messages are collapsed here。 See more
openeuler-ci-botopeneuler-ci-botCollaborators
17 days ago Removed label: ci_successful
openeuler-ci-bot
openeuler-ci-botCollaborators
17 days ago Comments:

CLA Signature Pass

zouziqiang, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
openeuler-ci-bot
openeuler-ci-botCollaborators
17 days ago Comments:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci_successful.

likedislike
openeuler-botopeneuler-botCollaborators
17 days ago Added label: ci_processing
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:

门禁正在运行, 您可以通过以下链接查看实时门禁检查结果.
若您对门禁结果含义不清晰或者遇到问题不知如何解决,可参考门禁指导手册
门禁入口及编码规范检查: multiarch/openeuler/trigger/KASandbox/571

likedislike
openeuler-botopeneuler-botCollaborators
17 days ago Removed label: ci_processing
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:
Check Name Build Result 详情 Build Details
check_package_license ✅SUCCESS #571
check_sca ✅SUCCESS
x86_64 check_build ✅SUCCESS #574
aarch64 check_build ✅SUCCESS #590
DT check_build ✅SUCCESS #587
check_interface check_build ✅SUCCESS #20
likedislike
openeuler-botopeneuler-botCollaborators
17 days ago Added label: ci_successful
openeuler-bot
openeuler-botCollaborators
17 days ago Comments:
likedislike
zhourenjian
zhourenjianCollaborators
11 days ago Comments:

/lgtm
/approve

likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
11 days ago Added label: approvedlgtm
openeuler-ci-bot
openeuler-ci-botCollaborators
11 days ago Comments:

Review Code Feedback

  • The label lgtm, approved was added to this pull request. It means that zhourenjianz reviewed the code changes. 👋
Tips
  • If this pull request is not merged while all conditions are met, comment /check-pr to try again. 😄
likedislike
openeuler-ci-botopeneuler-ci-botCollaborators
11 days ago Merged pull request, merge node SHA: bd9a592270622505bec81d86e88ce18dd2c32e95