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

feat(ci): support colorized output in GitHub Actions #149

Closed
tdabasinskas opened this issue Dec 24, 2024 · 5 comments · Fixed by #150
Closed

feat(ci): support colorized output in GitHub Actions #149

tdabasinskas opened this issue Dec 24, 2024 · 5 comments · Fixed by #150
Labels
enhancement New feature or request

Comments

@tdabasinskas
Copy link

tdabasinskas commented Dec 24, 2024

Hi,

First, thanks for a great tool!

Would it be possible to add support for colorized output in GitHub Actions? As I understand, you are using fatih/color module for colorized output. As per the documentation, the module does support colorizing output in GitHub Actions, but requires explicitly setting color.NoColor = false.

Could we introduce some flag or environment variable, e.g. FORCE_COLOR, which, when set would set color.NoColor to false?

@jlandowner
Copy link
Owner

Hi @tdabasinskas. Thanks for raising!

I didn't know that 👀
I understand that setting the env NO_COLOR=1 disables colored output, but is it enabled by default in GitHub Actions?

I came up with a idea to set color.NoColor = false by default when the env NO_COLOR is not present...but is it meaningless?
Do you mean it is necessary to handle color control regardless of env NO_COLOR?

@jlandowner jlandowner added the enhancement New feature or request label Dec 25, 2024
@tdabasinskas
Copy link
Author

tdabasinskas commented Dec 25, 2024

Hi,

Thanks for a quick reply!

The way I understand fatih/color works is:

  • If there's NO_COLOR environment variable set (regardless of its value), it explicitly disables colors.
  • If there's no NO_COLOR nor color.NoColor set, it automatically decides if the colors should be used based on terminal type (which, in case of GitHub Actions results in no colors).
  • If color.NoColor is explicitly set to false, it always uses colors.

So, my suggestion would be the following:

  • Do not change any existing behavior of NO_COLOR environment variable.
  • Introduce new environment variable FORCE_COLOR which, if set, explicitly adds color.NoColor=false.

This would result in no breaking changes as well as follow common patterns - some languages (e.g. Python) and frameworks already support FORCE_COLOR environment variable which forces the console coloring.

@jlandowner
Copy link
Owner

Thanks for the information! I learned much through this issue😳

I thought this feature should be discussed in the library and found fatih/color#155

By default, faith/color does not colorize outputs if stdout is not a TTY.

Unfortunately it is no merged at this point but I also found fatih's stance for env FORCE_COLOR . So it might be a native support in the library in the future.
fatih/color#156 (comment)

But chartsnap is inspired by the existing UI snapshot testing tools like Jest.

As listed in https://force-color.org/,
Jest supports env FORCE_COLOR and also --color cli option to colorize outputs even if stdout is not TTY. https://jestjs.io/docs/cli#--colors

So I understand it is worth implementing this feature👍

@jlandowner
Copy link
Owner

Released v0.4.3 🚀

You can also check this job.
https://github.com/jlandowner/helm-chartsnap/actions/runs/12517536227/job/34918495488#step:6:63

@tdabasinskas
Copy link
Author

Already tested it - works great. Thanks!

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

Successfully merging a pull request may close this issue.

2 participants