feat: 坐标重命名
All checks were successful
序列化结构检查 / serialization-schema-check (push) Has been skipped

This commit is contained in:
2026-07-15 11:33:24 +08:00
parent 8ef5abc262
commit fd5aab5e7f
14 changed files with 102 additions and 103 deletions

View File

@@ -17,11 +17,11 @@ import java.util.concurrent.Callable;
/**
* 命令行入口退出码0 通过 / 1 阻断 / 2 执行错误
*/
@Command(name = "cache-schema-checker",
@Command(name = "serialization-schema-checker",
mixinStandardHelpOptions = true,
version = "cache-schema-checker 1.0.0",
description = "检测两次提交间缓存 value 序列化结构变更并通过企微机器人通知。")
public class CacheSchemaCheckerMain implements Callable<Integer> {
version = "serialization-schema-checker 1.0.0",
description = "检测两次提交间缓存/MQ 等 value 序列化结构变更并通过企微机器人通知。")
public class SerializationSchemaCheckerMain implements Callable<Integer> {
@Option(names = "--config", required = true, description = "业务仓库检测配置文件路径")
private Path configPath;
@@ -56,12 +56,12 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
CheckerConfig config = ConfigLoader.load(configPath);
if (!config.isEnabled()) {
System.out.println("[cache-schema-checker] 总开关 enabled=false跳过检测。");
System.out.println("[serialization-schema-checker] 总开关 enabled=false跳过检测。");
return 0;
}
if (oldSha == null || oldSha.trim().isEmpty()) {
System.out.println("[cache-schema-checker] 无对比基准提交,跳过检测。");
System.out.println("[serialization-schema-checker] 无对比基准提交,跳过检测。");
return 0;
}
@@ -75,7 +75,6 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
report.setRepository(repository != null ? repository : root.getFileName().toString());
ReportBuilder builder = new ReportBuilder(config.getNotify().getTitlePrefix());
// CI字段明细 + 完整企微 Markdown
System.out.println(builder.toConsole(report));
boolean shouldNotify = config.getNotify().isEnabled()
@@ -84,24 +83,24 @@ public class CacheSchemaCheckerMain implements Callable<Integer> {
String webhook = config.getNotify().getWebhookUrl();
List<String> messages = builder.toWeComMessages(report);
int ok = new WeComNotifier().sendMarkdownMessages(webhook, messages);
System.out.println("[cache-schema-checker] 企微通知发送: "
System.out.println("[serialization-schema-checker] 企微通知发送: "
+ ok + "/" + messages.size()
+ (messages.size() > 1 ? "(已按 key 拆分)" : ""));
}
if (report.isBlocked()) {
System.out.println("[cache-schema-checker] block 模式命中流水线将被阻断exit 1");
System.out.println("[serialization-schema-checker] block 模式命中流水线将被阻断exit 1");
}
return report.getExitCode();
} catch (Exception e) {
System.err.println("[cache-schema-checker] 执行错误: " + e.getMessage());
System.err.println("[serialization-schema-checker] 执行错误: " + e.getMessage());
e.printStackTrace();
return 2;
}
}
public static void main(String[] args) {
int exitCode = new CommandLine(new CacheSchemaCheckerMain()).execute(args);
int exitCode = new CommandLine(new SerializationSchemaCheckerMain()).execute(args);
System.exit(exitCode);
}
}

View File

@@ -41,7 +41,7 @@ public class CheckerConfig {
/** 企微机器人 Webhook 完整 URL */
private String webhookUrl = "";
private boolean notifyOnClean = false;
private String titlePrefix = "[缓存结构变更]";
private String titlePrefix = "[序列化结构变更]";
public boolean isEnabled() {
return enabled;

View File

@@ -87,7 +87,7 @@ public final class ConfigLoader {
n.setEnabled(bool(notify, "enabled", true));
n.setWebhookUrl(resolveWebhookUrl(notify));
n.setNotifyOnClean(bool(notify, "notify_on_clean", false));
n.setTitlePrefix(str(notify, "title_prefix", "[缓存结构变更]"));
n.setTitlePrefix(str(notify, "title_prefix", "[序列化结构变更]"));
Map<String, Object> ignore = asMap(map.get("ignore"));
CheckerConfig.Ignore ig = config.getIgnore();

View File

@@ -28,7 +28,7 @@ public class ReportBuilder {
private final String titlePrefix;
public ReportBuilder(String titlePrefix) {
this.titlePrefix = titlePrefix == null ? "[缓存结构变更]" : titlePrefix;
this.titlePrefix = titlePrefix == null ? "[序列化结构变更]" : titlePrefix;
}
/**
@@ -63,7 +63,7 @@ public class ReportBuilder {
String header = buildHeader(report);
List<String> bodies = buildKeyBodies(report);
if (bodies.isEmpty()) {
return Collections.singletonList(header + "未检测到缓存序列化结构变更。\n");
return Collections.singletonList(header + "未检测到序列化结构变更。\n");
}
StringBuilder combined = new StringBuilder(header);
@@ -182,7 +182,7 @@ public class ReportBuilder {
public String toConsole(CheckReport report) {
StringBuilder sb = new StringBuilder();
if (!report.hasChanges()) {
sb.append("未检测到缓存序列化结构变更。\n");
sb.append("未检测到序列化结构变更。\n");
return sb.toString();
}

View File

@@ -1,4 +1,4 @@
# cache-schema-checker 内置默认配置
# serialization-schema-checker 内置默认配置
# 业务仓库通过 --config 指定的配置会与本文件深度合并(业务配置优先)。
# 总开关false 时不执行检测、不发通知、流水线直接通过
@@ -19,7 +19,7 @@ notify:
enabled: true
webhook_url: ""
notify_on_clean: false
title_prefix: "[缓存结构变更]"
title_prefix: "[序列化结构变更]"
# 忽略规则
ignore:

View File

@@ -56,7 +56,7 @@ class ReportBuilderTest {
key.getFieldDetails().add(addedErr);
report.getKeyChanges().add(key);
String md = new ReportBuilder("[缓存结构变更]").toMarkdown(report);
String md = new ReportBuilder("[序列化结构变更]").toMarkdown(report);
assertTrue(md.contains("- Key --> `saas:period-config:migration:current`"));
assertFalse(md.contains("key 无法解析)"));
@@ -133,7 +133,7 @@ class ReportBuilderTest {
key.getFieldDetails().add(detail);
report.getKeyChanges().add(key);
String console = new ReportBuilder("[缓存结构变更]").toConsole(report);
String console = new ReportBuilder("[序列化结构变更]").toConsole(report);
assertTrue(console.contains("======== 字段明细 ========"));
assertTrue(console.contains("**删除字段**: x"));
assertTrue(console.contains("<font color=\"warning\">\"x\":\"\"</font>"));
@@ -161,7 +161,7 @@ class ReportBuilderTest {
key.getFieldDetails().add(added);
report.getKeyChanges().add(key);
String md = new ReportBuilder("[缓存结构变更]").toMarkdown(report);
String md = new ReportBuilder("[序列化结构变更]").toMarkdown(report);
assertTrue(md.contains("- Key --> `req.getKey()` <font color=\"comment\">key 无法解析)</font>"));
assertTrue(md.contains("> **位置**: `ClockInXxxService#export:128`"));
assertTrue(md.contains("> **类型**: `List<ClockInExportVo>`"));
@@ -185,7 +185,7 @@ class ReportBuilderTest {
report.getKeyChanges().add(simpleKey("k-a", "{\"a\":\"\"}", "{\"a\":\"\",\"x\":\"\"}", "x"));
report.getKeyChanges().add(simpleKey("k-b", "{\"b\":\"\"}", "{\"b\":\"\",\"y\":\"\"}", "y"));
List<String> messages = new ReportBuilder("[缓存结构变更]").toWeComMessages(report);
List<String> messages = new ReportBuilder("[序列化结构变更]").toWeComMessages(report);
assertEquals(1, messages.size());
assertTrue(messages.get(0).contains("k-a"));
assertTrue(messages.get(0).contains("k-b"));
@@ -200,7 +200,7 @@ class ReportBuilderTest {
report.getKeyChanges().add(simpleKey("fat-key-1", fat, fat + "1", null));
report.getKeyChanges().add(simpleKey("fat-key-2", fat, fat + "2", null));
List<String> messages = new ReportBuilder("[缓存结构变更]").toWeComMessages(report);
List<String> messages = new ReportBuilder("[序列化结构变更]").toWeComMessages(report);
assertEquals(2, messages.size(), "超长应按 key 拆成 2 条");
assertTrue(messages.get(0).contains("fat-key-1"));
assertFalse(messages.get(0).contains("fat-key-2"));
@@ -209,10 +209,10 @@ class ReportBuilderTest {
assertTrue(ReportBuilder.utf8Bytes(messages.get(0)) <= ReportBuilder.WECOM_MARKDOWN_MAX_BYTES);
assertTrue(ReportBuilder.utf8Bytes(messages.get(1)) <= ReportBuilder.WECOM_MARKDOWN_MAX_BYTES);
// 抬头在每条中重复
assertTrue(messages.get(0).contains("## [缓存结构变更] jnpf-java-cloud"));
assertTrue(messages.get(1).contains("## [缓存结构变更] jnpf-java-cloud"));
assertTrue(messages.get(0).contains("## [序列化结构变更] jnpf-java-cloud"));
assertTrue(messages.get(1).contains("## [序列化结构变更] jnpf-java-cloud"));
String console = new ReportBuilder("[缓存结构变更]").toConsole(report);
String console = new ReportBuilder("[序列化结构变更]").toConsole(report);
assertTrue(console.contains("超长已按 key 拆为 2 条"));
}