feat: 流水线更新,兼容多次commit
All checks were successful
缓存序列化结构检查 / cache-schema-check (push) Has been skipped

This commit is contained in:
2026-07-14 17:17:35 +08:00
parent 1f119edb7c
commit 96a3bd46cf
3 changed files with 147 additions and 141 deletions

View File

@@ -5,21 +5,38 @@
## 1. 集成概览
```text
开发者 push 代码
开发者 push 代码(可含多个 commit
Gitea Actions 触发
浅克隆业务仓库depth=2
浅克隆业务仓库 tipdepth=1+ 按需取 push 前 tipbefore
从 Nexus 下载 cache-schema-checker.jar
java -jar 执行(对比 HEAD~1 与 HEAD
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 改回 → 累计可能无告警(以最终结构为准)
---
## 2. 前置条件
@@ -45,88 +62,31 @@ jnpf-java-cloud/
│ └── cache-schema-check-config.yaml # 检测配置
```
请以本仓库 `.gitea/workflows/cache-schema-check.yaml` 为模板同步到业务仓。
---
## 4. 流水线模板
## 4. 流水线模板(要点)
```yaml
name: 缓存序列化结构检查
run-name: ${{ gitea.actor }}的缓存结构检查
完整可运行版本见:`.gitea/workflows/cache-schema-check.yaml`
on:
push:
workflow_dispatch:
核心逻辑摘要:
env:
CACHE_SCHEMA_CHECKER_VERSION: "1.0.0"
CACHE_SCHEMA_CHECKER_REPO_URL: "http://192.168.3.25:18081/nexus/repository/maven-releases"
```bash
# 1) 浅拉 tip
git clone --depth 1 --single-branch --branch "$BRANCH" "$REPO_URL" .
git checkout -B "$BRANCH" "$NEW_SHA" # NEW_SHA = gitea.sha
jobs:
cache-schema-check:
if: ${{ gitea.ref != 'refs/heads/pre' && gitea.ref != 'refs/heads/dev' && gitea.ref != 'refs/heads/master-2.0' }}
runs-on: jdk11
steps:
- name: 检出代码
run: |
git config --global http.sslVerify false
git clone --depth 2 --single-branch --branch "${{ gitea.ref_name }}" \
"https://${{ gitea.token }}@git.niujiekeji.com/${{ gitea.repository }}.git" .
git checkout -B "${{ gitea.ref_name }}" "${{ 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 # 兜底
- name: 检查配置文件
run: |
if [ ! -f .gitea/config/cache-schema-check-config.yaml ]; then
echo "错误: 缺少 .gitea/config/cache-schema-check-config.yaml"
exit 1
fi
- name: 从 Nexus 下载检测工具
run: |
GROUP_PATH="com/codechecker/cache-schema-checker"
JAR_NAME="cache-schema-checker-${CACHE_SCHEMA_CHECKER_VERSION}.jar"
JAR_URL="${CACHE_SCHEMA_CHECKER_REPO_URL}/${GROUP_PATH}/${CACHE_SCHEMA_CHECKER_VERSION}/${JAR_NAME}"
JAR_PATH="/tmp/${JAR_NAME}"
echo "下载: ${JAR_URL}"
if command -v curl >/dev/null 2>&1; then
curl -fsSL -o "${JAR_PATH}" "${JAR_URL}"
elif command -v wget >/dev/null 2>&1; then
wget -q -O "${JAR_PATH}" "${JAR_URL}"
else
echo "错误: Runner 缺少 curl 或 wget"
exit 1
fi
if [ ! -s "${JAR_PATH}" ]; then
echo "错误: 下载失败或文件为空"
exit 1
fi
ls -lh "${JAR_PATH}"
- name: 验证 JDK
run: java -version
- name: 执行 缓存结构检测
env:
WECOM_ROBOT_WEBHOOK: ${{ secrets.WECOM_ROBOT_WEBHOOK }}
run: |
OLD_SHA=$(git rev-parse HEAD~1 2>/dev/null || echo "")
if [ -z "$OLD_SHA" ]; then
echo "首次提交,跳过检测"
exit 0
fi
COMMIT_TIME=$(git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S')
java -jar "/tmp/cache-schema-checker-${CACHE_SCHEMA_CHECKER_VERSION}.jar" \
--config .gitea/config/cache-schema-check-config.yaml \
--repo-root . \
--old-sha "$OLD_SHA" \
--new-sha "$(git rev-parse HEAD)" \
--branch "${{ gitea.ref_name }}" \
--modifier "${{ gitea.actor }}" \
--modify-time "$COMMIT_TIME"
# 4) 执行
java -jar cache-schema-checker-1.0.0.jar \
--old-sha "$OLD_SHA" \
--new-sha "$NEW_SHA" \
...
```
---
@@ -148,8 +108,8 @@ jobs:
# 在 redisCheck 仓库根目录
mvn clean package -DskipTests
# 发布到 Nexus需配置 settings.xml,并开启 deploy-nexus profile
mvn clean deploy -Dnexus.deploy.enabled=true -DskipTests
# 发布到 Nexus需配置 settings.xml
mvn clean deploy -DskipTests
```
发布产物:
@@ -166,9 +126,9 @@ com/codechecker/cache-schema-checker/1.0.0/
| 退出码 | 含义 | 流水线表现 |
|--------|------|------------|
| 0 | 通过(含 notify 模式下的告警) | 绿色 |
| 0 | 通过(含 notify 模式下的告警) / 跳过 | 绿色 |
| 1 | 阻断block 模式) | 红色 |
| 2 | 执行错误配置缺失、jar 异常等) | 红色 |
| 2 | 执行错误(配置缺失、无法取 before、jar 异常等) | 红色 |
---
@@ -176,27 +136,35 @@ com/codechecker/cache-schema-checker/1.0.0/
| 现象 | 可能原因 | 处理 |
|------|----------|------|
| 首次提交跳过 | 无 HEAD~1 | 正常行为 |
| 新分支首次 push 跳过 | `before` 全 0 | 正常行为 |
| 无法获取 before / exit 2 | 浅克隆未取到对象、服务端禁 fetch SHA | 看日志中的 deepen确认 Gitea 允许按 SHA fetch |
| 下载 jar 失败 | Nexus 地址/版本错误 | 检查 env 变量 |
| 未收到企微 | Secret 未配 / notify.enabled=false | 检查配置 |
| 未收到企微 | Secret 未配 / notify.enabled=false / webhook_url 空 | 检查配置 |
| 大量误报 | 锁/计数器未过滤 | 补充 ignore.key_patterns |
| 漏报 | 写入模式未覆盖 / 模块过滤过窄 | 确认 W01~W05 已启用;检查 `include_modules` |
| 漏报(多 commit | 业务仓仍用旧版 `HEAD~1` 流水线 | 同步本仓库最新 workflow`before..after` |
| 漏报(模式/模块) | W0x 未开 / include_modules 过窄 | 确认 W01~W05检查模块过滤 |
| 类型展开不完整 | 类型在依赖 jar 中 | 补充 `manual_mappings.value_type` |
---
## 9. 本地调试
模拟一次「多 commit push」的累计区间
```bash
# 在 jnpf-java-cloud 根目录
# 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 HEAD~1 \
--new-sha HEAD \
--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')"
--modify-time "$(git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S')" \
--dry-run
```
可加 `--dry-run` 仅输出报告不发企微
单 commit 自测仍可用 `--old-sha HEAD~1 --new-sha HEAD`