feat: 1、流水线总开关配置 2、删除p0p1p2级别阻断
All checks were successful
Redis序列化结构检查 / redis-schema-check (push) Has been skipped

This commit is contained in:
2026-07-14 10:58:05 +08:00
parent 7a8ca7ce0b
commit 114b053733
10 changed files with 74 additions and 68 deletions

View File

@@ -330,16 +330,7 @@ public class SchemaCheckAnalyzer {
report.getChanges().addAll(changes);
report.getKeyChanges().addAll(keyChanges.values());
boolean blocked = false;
if (config.isBlockMode()) {
Set<String> blockSev = new HashSet<>(config.getBlockSeverities());
for (SchemaChange c : changes) {
if (blockSev.contains(c.getSeverity().name())) {
blocked = true;
break;
}
}
}
boolean blocked = config.isBlockMode() && !changes.isEmpty();
report.setBlocked(blocked);
report.setExitCode(blocked ? 1 : 0);
return report;

View File

@@ -55,6 +55,11 @@ public class RedisSchemaCheckerMain implements Callable<Integer> {
try {
CheckerConfig config = ConfigLoader.load(configPath);
if (!config.isEnabled()) {
System.out.println("[redis-schema-checker] 总开关 enabled=false跳过检测。");
return 0;
}
if (oldSha == null || oldSha.trim().isEmpty()) {
System.out.println("[redis-schema-checker] 无对比基准提交,跳过检测。");
return 0;

View File

@@ -10,11 +10,12 @@ import java.util.Map;
*/
public class CheckerConfig {
/** 总开关false 时跳过检测与通知(流水线 exit 0 */
private boolean enabled = true;
/** notify | block */
private String mode = "notify";
private List<String> blockSeverities = new ArrayList<>();
private boolean scanTestSources = false;
private List<String> sourceRoots = new ArrayList<>();
@@ -231,6 +232,14 @@ public class CheckerConfig {
}
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public String getMode() {
return mode;
}
@@ -239,14 +248,6 @@ public class CheckerConfig {
this.mode = mode;
}
public List<String> getBlockSeverities() {
return blockSeverities;
}
public void setBlockSeverities(List<String> blockSeverities) {
this.blockSeverities = blockSeverities;
}
public boolean isScanTestSources() {
return scanTestSources;
}

View File

@@ -75,8 +75,8 @@ public final class ConfigLoader {
private static CheckerConfig bind(Map<String, Object> map) {
CheckerConfig config = new CheckerConfig();
config.setEnabled(bool(map, "enabled", true));
config.setMode(str(map, "mode", "notify"));
config.setBlockSeverities(strList(map.get("block_severities")));
config.setScanTestSources(bool(map, "scan_test_sources", false));
config.setSourceRoots(strList(map.get("source_roots")));
config.setIncludeModules(strList(map.get("include_modules")));

View File

@@ -1,14 +1,11 @@
# redis-schema-checker 内置默认配置
# 业务仓库通过 --config 指定的配置会与本文件深度合并(业务配置优先)。
# 运行模式notify仅通知| block按 block_severities 阻断exit 1
mode: notify
# 总开关false 时不执行检测、不发通知、流水线直接通过
enabled: true
# block 模式下触发阻断的严重级别(默认全部阻断
block_severities:
- P0
- P1
- P2
# 运行模式notify仅通知| block检测到结构变更即阻断exit 1
mode: notify
# 是否扫描测试代码(第一版固定 false
scan_test_sources: false

View File

@@ -16,8 +16,8 @@ class ConfigLoaderTest {
@Test
void loadsDefaultsWhenNoBusinessConfig() {
CheckerConfig config = ConfigLoader.load(null);
assertTrue(config.isEnabled());
assertEquals("notify", config.getMode());
assertTrue(config.getBlockSeverities().contains("P0"));
assertTrue(config.getDetection().getPatterns().contains("W01"));
assertFalse(config.isScanTestSources());
}
@@ -25,18 +25,20 @@ class ConfigLoaderTest {
@Test
void businessConfigOverridesDefaults(@org.junit.jupiter.api.io.TempDir Path tmp) throws IOException {
Path cfg = tmp.resolve("biz.yaml");
Files.write(cfg, ("mode: block\n"
Files.write(cfg, ("enabled: false\n"
+ "mode: block\n"
+ "include_modules:\n - jnpf-tenant\n"
+ "notify:\n enabled: false\n").getBytes(StandardCharsets.UTF_8));
CheckerConfig config = ConfigLoader.load(cfg);
assertFalse(config.isEnabled());
assertEquals("block", config.getMode());
assertTrue(config.isBlockMode());
assertEquals(1, config.getIncludeModules().size());
assertEquals("jnpf-tenant", config.getIncludeModules().get(0));
// 未覆盖项保留默认
assertFalse(config.getNotify().isEnabled());
assertTrue(config.getBlockSeverities().contains("P2"));
assertTrue(config.getDetection().getPatterns().contains("W01"));
}
@Test