This pull request has been discarded
-
2 days ago
-
It is expected that tod exits with 0 even if build is failed, as tod executes the command itself successfully. You will need to get status of the build to check its result.
-
| Submitter | Robert Navarro |
| Target | main |
| Source | forks/rnavarro/tod:fix/build-run-exit-status |
Merge Strategy
Create Merge Commit
I run
tod build runfrom scripts and coding agents against my OneDev 16.9.1 server, and a failed build returned exit 0. The log ends with the red "Build #N is failed" line, buttod build run --local ci && next-stepcarried on to the next step anyway.In
streamBuildLog, the FAILED / CANCELLED / TIMED_OUT branch prints the red status and thenbreaks out of the read loop, so the function returns nil the same way it does for SUCCESSFUL. With this change that branch returns a sentinel error,errBuildNotSuccessful.mainexits 1 for it but skips printing the error, since the red status line already says what happened. Successful builds still exit 0 and their output is unchanged.streamBuildLogis only reached throughrunBuildJobCommand, so this covers--branch,--tagand--local, plus the hiddentod runalias. I did not find another command that streams and waits on a build.Heads up: pressing Ctrl-C during
tod build runcancels the build, the server then sends CANCELLED, and the command now exits 1 where it used to exit 0.Exit codes I measured with
tod build run --local <job>against my server, using a scratch buildspec with one job that runsexit 0, one that runsexit 1, one that sleeps past a 10 second job timeout, and one I cancelled with SIGINT while it was running:On this branch the failed and timed out runs print no extra error line.
I added
TestStreamBuildLogReturnsErrorForUnsuccessfulBuildinbuild_commands_test.go. It serves a single status frame from an httptest server and checks that SUCCESSFUL returns nil and the other three returnerrBuildNotSuccessful.gofmt,go vet ./...,go test ./...andgo buildpass. I only ran the live test with--local.--branchand--taggo through the same function, but I did not run them against a server. I also only tested on Linux.I searched the onedev/tod issues and pull requests, and the onedev/server issues, for exit code and build run reports before putting this up and did not find one.
I used an AI coding assistant to help write this change, and I reviewed and tested it myself.