Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ to keep the column out of the inventory afterwards too, name both rules:
`-- cdclint:ignore schema-before-connector,source-column-not-captured: PII`.

Files in, findings out, non-zero exit. No database, no daemon, no credentials.
Under a second on a laptop. `--fail-on warning` or `info` raises the bar;
Under a second on a laptop. `--fail-on warning` or `info` raises the bar
(any other value is an error, not the default);
`--format json` is for anything that wants to post findings somewhere. A
later live mode reads the deployed Postgres, Kafka Connect and sink to report
drift against what is actually running.
Expand Down
5 changes: 4 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ runs:
PR_BASE_SHA: ${{ github.event.pull_request.base.sha }}
run: |
set -uo pipefail
args=(--migrations "$MIGRATIONS" --connector "$CONNECTOR" --fail-on "$FAIL_ON")
# An empty input (a workflow passing an unset variable) meant error
# before cdclint checked --fail-on, and still does; anything else
# that is not error, warning or info now fails the step.
args=(--migrations "$MIGRATIONS" --connector "$CONNECTOR" --fail-on "${FAIL_ON:-error}")
if [ -n "$DISABLE" ]; then
args+=(--disable "$DISABLE")
fi
Expand Down
16 changes: 9 additions & 7 deletions cmd/cdclint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ func run(args []string, stdout, stderr io.Writer) int {
fmt.Fprintln(stdout, "cdclint", version)
return 0
}
// An unknown --fail-on used to fall through to error, so
// `--fail-on warnings` let warnings pass while the pipeline believed it
// blocked on them. It is checked before anything is read, like
// --disable, so a typo cannot look like a clean run.
threshold, ok := map[string]model.Severity{"error": model.Error, "warning": model.Warning, "info": model.Info}[*minSev]
if !ok {
fmt.Fprintf(stderr, "cdclint: --fail-on: unknown severity %q; the severities are error, warning, info\n", *minSev)
return 2
}
disabled := map[string]bool{}
for _, v := range disable {
for _, name := range strings.Split(v, ",") {
Expand Down Expand Up @@ -139,13 +148,6 @@ func run(args []string, stdout, stderr io.Writer) int {
default:
fmt.Fprint(stdout, TextReport(findings, hidden, acked))
}
threshold := model.Error
switch *minSev {
case "warning":
threshold = model.Warning
case "info":
threshold = model.Info
}
for _, f := range findings {
if f.Severity >= threshold {
return 1
Expand Down
29 changes: 29 additions & 0 deletions cmd/cdclint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,32 @@ func TestJSONKeepsItsShapeAndNotesOnStderr(t *testing.T) {
t.Errorf("stderr %q", errOut)
}
}

func TestAnUnknownFailOnIsAnErrorNotTheDefault(t *testing.T) {
// "warnings" used to fall through to the default, error: a pipeline
// that asked to block on warnings passed them silently. include-list-typo
// has a warning and an error, so any lint that ran would exit 1.
// An explicit empty value is rejected too; action.yml maps an empty
// input to error itself, so only the CLI sees "" from a person.
for _, bad := range []string{"warnings", "WARNING", "err", ""} {
code, out, errOut := cli(t, append(entry("include-list-typo"), "--fail-on", bad)...)
if code != 2 || out != "" {
t.Errorf("--fail-on %q: exit %d, stdout %q; want exit 2 before linting", bad, code, out)
}
if !strings.Contains(errOut, "--fail-on") || !strings.Contains(errOut, "error, warning, info") {
t.Errorf("--fail-on %q: stderr %q", bad, errOut)
}
}
// The three that exist still work; info and warning reach the warning.
for sev, want := range map[string]int{"error": 1, "warning": 1, "info": 1} {
if code, _, _ := cli(t, append(entry("include-list-typo"), "--fail-on", sev)...); code != want {
t.Errorf("--fail-on %s: exit %d, want %d", sev, code, want)
}
}
if code, _, _ := cli(t, append(entry("include-list-typo"), "--fail-on", "warning", "--disable", "sink-column-not-captured")...); code != 1 {
t.Errorf("--fail-on warning with only the warning left: exit %d, want 1", code)
}
if code, _, _ := cli(t, append(entry("include-list-typo"), "--disable", "sink-column-not-captured")...); code != 0 {
t.Errorf("default --fail-on error with only the warning left: exit %d, want 0", code)
}
}