Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colors are always enabled in CI, even when output is piped #41

Open
anko opened this issue Nov 22, 2021 · 5 comments · May be fixed by #44
Open

Colors are always enabled in CI, even when output is piped #41

anko opened this issue Nov 22, 2021 · 5 comments · May be fixed by #44

Comments

@anko
Copy link

anko commented Nov 22, 2021

I wrote a program that uses this module. The tests pass on my local machine (because the colours are sensibly disabled when the program's output is piped), but they fail in CI, because this line turns colours on no matter what if process.env.CI is set. Even if it's not in a TTY.

When stdout is not a TTY, I think colour should always be disabled, unless it's specifically forced on with FORCE_COLOR.

@ai
Copy link
Contributor

ai commented Nov 22, 2021

Just for the context. GitHub Actions has broken TTY detection. CI supports colors, but report lack of TTY.

But I am not sure about the best solution here.

@anko
Copy link
Author

anko commented Nov 22, 2021

I see now. Upstream issue is here. I'd like to have color on a test script on GH Actions too, I just don't want color on every child process that it starts and internally reads the output of.

$ node -e "console.log(require('picocolors').isColorSupported)" | cat
false
$ CI=1 node -e "console.log(require('picocolors').isColorSupported)" | cat
true

Other CI services that also set $CI might not even support colours, but they'd be enabled anyway and the tests would fail. It would be really confusing trying to understand what's going on, because the CI might just show something like "OK" is not equal to "OK".

I think we should either;

  • Leave users to work around their chosen CI system's bugs themselves, instead of forcing them to work around our workaround of a bug in a specific CI system that they might not even be using, or
  • Find some way to cheaply but reliably detect Github Actions, so we can turn colours on for it without relying solely on the $CI variable.

@anko
Copy link
Author

anko commented Nov 22, 2021

Find some way to cheaply but reliably detect Github Actions

Oh. $GITHUB_ACTIONS is always set to true on Github Actions. 🎉

@anko
Copy link
Author

anko commented Nov 26, 2021

I worked around this by using supports-color, which is smallish at 10kB unpacked, 0 deps, and detects colour support correctly in a whole lot of environments including silly ones like GH Actions.

alexeyraspopov added a commit that referenced this issue Dec 3, 2021
@alexeyraspopov alexeyraspopov linked a pull request Dec 3, 2021 that will close this issue
@erezrokah
Copy link

We're experiencing this too, see netlify/cli#4354 (comment) in case a reproduction is needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants