Keep main green
A watch runs the tests on a schedule, and when they go red, a worker fixes the code and tells you in one line.
Don't check the build. Tell something to check it, and to act when it breaks.
- tests on main every few minutes
- go vet after every commit
- the lint job you keep forgetting
A watch is a standing order with a probe: a command CodeAF runs on a schedule, and work that starts only when the probe fails. In this playbook the probe is your test suite. When a teammate pushes a regression, a worker reads the failure, fixes the code, runs the tests again, and the chat that set the watch tells you in one line what broke and what was fixed.
Steps
- In a chat in the repository, say what to watch and what to do, and press Enter:
Keep main green here: every 2 minutes run go test -count=1 ./... in this folder. Whenever a test fails, fix the code (not the test), run the tests again, and tell me in one line what broke and what you fixed.- A card comes back,
wants to watch for something, with the name and the schedule it understood:keep main green · every 2 minutes · shares the day's $500.00 allowance · checked every 5 minutes. Press 1 (Watch for it). - Carry on with your day. When a test fails, the watch fires by itself.
What you see
We tested it the honest way: we committed post: skip negative entries, a change that breaks TestBalance. On the next pass the probe failed and the watch fired. The worker fixed ledger.go, the tests passed, and the chat woke with one message:
A probe fired and the worker fixed both real bugs in ledger.go (Post dropped negative entries; the Ledger had no lock for concurrent posts): go test -count=1 -race ./... now passes, main is green.
The worker found the second bug on its own, a missing lock that let concurrent posts race, and fixed it in the same pass.
The card tells you how often the watch really looks: you asked for every 2 minutes, and standing orders are checked on a 5-minute pass, so it says checked every 5 minutes.
In our run
Setting up the watch took about a minute and $0.06. The firing that fixed main took 12 seconds, and two firings together cost $0.018.
Make it yours
- Watch something else. Any command that fails when something is wrong can be the probe:
go vet ./..., a linter, a script that checks a health endpoint. - Pick a steady probe. A test that fails only some of the time makes the watch fire on a flake. Keep racy tests out of the probe, or let the nightly routine file them as issues.
- Stop it. Say "stop the keep main green watch" in any chat of the project.
Go further
Watches: Say what you are waiting for; CodeAF looks on a timer and starts work only when the answer is yes.
Coming soon: describe the org you want and CodeAF builds it: teams, managers, budgets, standing orders.