Files
schemaCheck/docs/CI集成说明.md
2026-07-15 11:29:12 +08:00

182 lines
5.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 缓存序列化结构检测 — CI 集成说明
---
## 1. 集成概览
```text
开发者 push 代码(可含多个 commit
Gitea Actions 触发
浅克隆业务仓库 tipdepth=1+ 按需取 push 前 tipbefore
从 Nexus 下载 cache-schema-checker.jar
java -jar 执行(对比 before → after累计 diff
有结构变更 → 企微通知(按 Key 骨架;删除橙/新增绿)
mode=block 且含任意结构变更 → exit 1流水线失败
```
### 1.1 对比区间(重要)
| 参数 | 取值 | 含义 |
|------|------|------|
| `--old-sha` | `gitea.event.before` | 本次 push **前**的远端 tip |
| `--new-sha` | `gitea.sha` | 本次 push **后**的 tip |
一次 push 推了多个 commit 时,只跑 **一次** 检测,覆盖整次 push 的累计代码差,**不会**因为「变更发生在中间 commit、最后一个 commit 没改相关文件」而漏检。
不需要全量历史:工作树是当前 tip`before` 通过 `git fetch --depth 1 <sha>`(或 deepen取到即可。
边界:
- `before``0` / 空 → 新分支首次 push跳过
- `workflow_dispatch` 无 before → 回退 `HEAD~1`
- 中间 commit 改坏又被末 commit 改回 → 累计可能无告警(以最终结构为准)
- commit 计数:优先取 `gitea.event.commits` 长度;否则 deepen 到 `before` 为祖先后再 `git rev-list`(浅克隆下直接 `rev-list` 会少算)
---
## 2. 前置条件
| 项 | 说明 |
|----|------|
| Gitea Runner | 标签 `jdk11`,已安装 Java 11 |
| Nexus 私库 | 可访问 `http://192.168.3.25:18081/nexus/repository/maven-releases` |
| 工具 JAR | `com.codechecker:cache-schema-checker:1.0.0` 已发布 |
---
## 3. 业务仓库文件清单
`jnpf-java-cloud` 中新增:
```text
jnpf-java-cloud/
├── .gitea/
│ ├── workflows/
│ │ └── cache-schema-check.yaml # 流水线
│ └── config/
│ └── cache-schema-check-config.yaml # 检测配置
```
请以本仓库 `.gitea/workflows/cache-schema-check.yaml` 为模板同步到业务仓。
---
## 4. 流水线模板(要点)
完整可运行版本见:`.gitea/workflows/cache-schema-check.yaml`
核心逻辑摘要:
```bash
# 1) 浅拉 tip
git clone --depth 1 --single-branch --branch "$BRANCH" "$REPO_URL" .
git checkout -B "$BRANCH" "$NEW_SHA" # NEW_SHA = gitea.sha
# 2) OLD_SHA = gitea.event.before全 0 则跳过;手动触发回退 HEAD~1
# 3) 本地没有 OLD_SHA 时:
git fetch --depth 1 origin "$OLD_SHA" # 优先
# 或 git fetch --deepen N # 兜底
# 4) 执行
java -jar cache-schema-checker-1.0.0.jar \
--old-sha "$OLD_SHA" \
--new-sha "$NEW_SHA" \
...
```
---
## 5. 与现有流水线的关系
| 流水线 | 作用 | 关系 |
|--------|------|------|
| `demo.yaml` (AI代码质量分析) | AI Code Review | 并行,互不影响 |
| `code-check` (CodeChecker) | 通用变更检测 | **同模式**,可并列执行 |
| `cache-schema-check` | 缓存结构检测 | 新增 |
---
## 6. 工具发布流程redisCheck 仓库)
```bash
# 在 redisCheck 仓库根目录
mvn clean package -DskipTests
# 发布到 Nexus需配置 settings.xml
mvn clean deploy -DskipTests
```
发布产物:
```text
com/codechecker/cache-schema-checker/1.0.0/
├── cache-schema-checker-1.0.0.jar # 可执行 fat-jar
└── cache-schema-checker-1.0.0.pom
```
---
## 7. 退出码约定
| 退出码 | 含义 | 流水线表现 |
|--------|------|------------|
| 0 | 通过(含 notify 模式下的告警) / 跳过 | 绿色 |
| 1 | 阻断block 模式) | 红色 |
| 2 | 执行错误(配置缺失、无法取 before、jar 异常等) | 红色 |
---
## 8. 故障排查
| 现象 | 可能原因 | 处理 |
|------|----------|------|
| 新分支首次 push 跳过 | `before` 全 0 | 正常行为 |
| 无法获取 before / exit 2 | 浅克隆未取到对象、服务端禁 fetch SHA | 看日志中的 deepen确认 Gitea 允许按 SHA fetch |
| 下载 jar 失败 | Nexus 地址/版本错误 | 检查 env 变量 |
| 未收到企微 | Secret 未配 / notify.enabled=false / webhook_url 空 | 检查配置 |
| 大量误报 | 锁/计数器未过滤 | 补充 ignore.key_patterns |
| commit 数显示为 1实际多个 | 浅克隆下 `rev-list` 看不到中间提交 | 已修复:优先事件 `commits` 长度;并 deepen 到 before 为祖先 |
| 漏报(模式/模块) | W0x 未开 / include_modules 过窄 | 确认 W01~W05检查模块过滤 |
| 类型展开不完整 | 类型在依赖 jar 中 | 补充 `manual_mappings.value_type` |
---
## 9. 本地调试
模拟一次「多 commit push」的累计区间
```bash
# OLD = 推送前 tipNEW = 当前 tip可用 origin/branch@{1} 或显式 sha
OLD_SHA=$(git rev-parse origin/$(git branch --show-current)~3) # 示例:假设 ahead 3
NEW_SHA=$(git rev-parse HEAD)
java -jar /path/to/cache-schema-checker-1.0.0.jar \
--config .gitea/config/cache-schema-check-config.yaml \
--repo-root . \
--old-sha "$OLD_SHA" \
--new-sha "$NEW_SHA" \
--branch $(git branch --show-current) \
--modifier "$(git log -1 --format=%an)" \
--modify-time "$(git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S')" \
--dry-run
```
单 commit 自测仍可用 `--old-sha HEAD~1 --new-sha HEAD`
---
## 10. 相关文档
| 文档 | 说明 |
|------|------|
| [实施方案.md](./实施方案.md) | 缓存检测总体方案 |
| [配置说明.md](./配置说明.md) | YAML 配置项 |
| [MQ序列化结构检测方案.md](./MQ序列化结构检测方案.md) | MQ 消息体 SchemaRocketMQ + Kafka方案已落地 |