When executing a project’s tests in a GHA with nix-shell --run <our test suite>, the output is monochromatic. Doing exactly the same locally, I get pretty colours in the test output.
The monochromatic test output on the GHA makes me really appreciate the colours: I want them back!
How can I persuade nix-shell to pick up whatever it is in the GHA environment that makes the colours appear?
Curious about this as well. I have some CI jobs that run color-using nix-shell demos, and one of the downsides I’ve found about moving to GA from travis-ci is losing that colored output.
This may not be a perfect proxy for the OP’s case since I just stuck it in a nix-build.
Outside of the execution (i.e., as an entry in the .yml), it is dumb, but inside my test.sh (running inside the nix-build) it is xterm-256color as I’d expect.
I don’t know if this would be helpful, but I recently reviewed a change to a library that tries to smartly determine whether to print in color or not.
Basically, the fix was to look at the output file descriptor for whether it is a terminal device. If it is, then print in color. If it is not, then don’t print in color.
I’m not actually sure what function is being called under the hood, but my guess is something like isatty():
It could be that GitHub Actions is redirecting output in some way that isatty() doesn’t return the same thing that you were seeing on TravisCI. Although it seems like you’ve figured out that forcing color output works.
With the caveat that I don’t know exactly why travis-ci and GA disagree here and realize they may have some compelling reasons, it strikes me as incredibly sad/stupid that every person/team/project who encounters this has to waste time understanding the issue, hunting down which tool in their toolchain is eating the sequences, and fiddling flags/envs (or filing issues…)
For others reading later: the above will only work on linux (bsd script doesn’t have the -e or -c args), so it won’t be a suitable default if you have macos in your build matrix.
Also, I noticed a new comment since I last read that thread suggesting the above may mark some failing builds as successful?