Commands icon
Docker icon
Switch icon
Log icon
Set icon
Fail icon
Webhook icon

Find the commit that broke the build with git bisect

Find the commit that broke a test with git bisect in Kestra. Checks both ends, names the first bad commit, its author, files and the failing output.

Categories
CoreInfrastructure

When main turns red after a busy day of merges, someone reads a dozen diffs to guess which one did it. git bisect run finds it in log2(n) test runs, but nobody runs it by hand at 2 a.m. This flow does:

  • It checks the good end and the bad end first. A good end that already fails would blame the wrong commit, so the flow stops with a clear message instead.
  • It runs git bisect run with your test command.
  • It reports the first bad commit, its author, its message, the files it changed and the test output at that commit.

It runs with no setup and no network. The default builds a demo repository: a pricing script, 40 commits, and one commit at position demo_regression_at that breaks the discount rule.

How it works

  1. bisect (io.kestra.plugin.scripts.shell.Commands, alpine/git:2.47.2) clones repository_url or builds the demo repository. It resolves good_ref and bad_ref to commit ids, tests both ends, runs git bisect run sh -c "$TEST_COMMAND", then reads the result. It outputs verdict, commits_in_range, test_runs, first_bad, author, subject, files, committed and failure.
  2. verdict (io.kestra.plugin.core.flow.Switch):
    • FOUND: report_culprit logs the commit, and record_culprit (io.kestra.plugin.core.kv.Set) stores it.
    • NO_REGRESSION: the test passes at the bad end.
    • Otherwise: bad_range (io.kestra.plugin.core.execution.Fail), because the good end already fails.
  3. on_red_build (io.kestra.plugin.core.trigger.Webhook) lets CI start it with the last green commit as good_ref.

Quick start

Run Input Result
1 defaults FOUND: "Refactor discount rounding" by Dana Dev, changing pricing.sh, after 5 test runs across 39 commits. Failing output: expected 180, got 1800
2 demo_regression_at: 40 FOUND at the last commit, again in 5 runs
3 demo_regression_at: 0 NO_REGRESSION
4 test_command: false Fails: the good end already fails

Inputs

  • repository_url (STRING, default empty for the demo).
  • good_ref (STRING, default v1.0.0) and bad_ref (STRING, default HEAD).
  • test_command (STRING, default sh test.sh): exit 0 for good, 1 to 124 for bad, 125 to skip an untestable commit.
  • demo_regression_at (INT, default 27).

Things to know

  • Both refs are resolved to commit ids before anything is checked out. In my first version HEAD was read after checking out the good end, so it pointed at the good commit and every run reported NO_REGRESSION.
  • Kestra runs commands with set -e. Failing tests are expected here, so the script turns it off.
  • For a project that needs a toolchain, use an image that has it and installs git, for example python:3.12 or maven, and keep the same commands.

Expected outputs

  • outputs.bisect.vars: verdict, first_bad, author, subject, files, committed, failure, test_runs, commits_in_range.
  • KV last_bisect_result.

Links

This blueprint was created by zkasuran.

See How

New to Kestra?

Use blueprints to kickstart your first workflows.