package main import "strings" func init() { register(Check{ Seq: 25, ID: "2f", Title: "sqlc compile and buf generate", Run: func(ctx *ScanContext, rep *Reporter) { codegenTargets := discoverCodegenTargets(ctx.repoRoot, ctx.backendDir, ctx.backendTargets, ctx.pluginTargets, ctx.includeCoreTargets) if len(codegenTargets) > 0 { completedCodegenTargets, codegenFailures, codegenErr := runCodegenChecks(codegenTargets) if codegenErr != nil { rep.Fatal("failed to run codegen checks: %v", codegenErr) } if len(codegenFailures) > 0 { rep.Fail("%d codegen target(s) failed sqlc compile or buf generate", len(codegenFailures)) for _, failure := range codegenFailures { rep.Findingf("[%s] %s", failure.stage, failure.target) if failure.output != "" { for line := range strings.SplitSeq(failure.output, "\n") { rep.Findingf("%s", line) } } } } else { rep.OK("sqlc compile / buf generate clean for %d target(s)", len(completedCodegenTargets)) } } else { rep.Skip("no sqlc or buf codegen targets found") } protoFreshness, protoFreshnessErr := checkProtoGeneratedFreshness(ctx.repoRoot) if protoFreshnessErr != nil { rep.Fail("failed to run make proto freshness check: %v", protoFreshnessErr) if protoFreshness.output != "" { for line := range strings.SplitSeq(protoFreshness.output, "\n") { rep.Findingf("%s", line) } } } else if protoFreshness.changed() { rep.Fail("make proto changed generated outputs; run make proto and commit the generated files") rep.Finding("before:") appendStatusFindings(rep, protoFreshness.beforeStatus) rep.Finding("after:") appendStatusFindings(rep, protoFreshness.afterStatus) } else if protoFreshness.checked { rep.OK("make proto freshness check clean") } }, }) } func appendStatusFindings(rep *Reporter, status string) { if strings.TrimSpace(status) == "" { rep.Finding("(clean)") return } for line := range strings.SplitSeq(status, "\n") { rep.Findingf("%s", line) } }