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

Set the environment variable to enable colorful output by default #288

Closed
Tyrrrz opened this issue Apr 20, 2022 · 9 comments
Closed

Set the environment variable to enable colorful output by default #288

Tyrrrz opened this issue Apr 20, 2022 · 9 comments
Assignees
Labels
feature request New feature or request to improve the current logic

Comments

@Tyrrrz
Copy link

Tyrrrz commented Apr 20, 2022

Description:

.NET previously disabled console colors if it detected that the output was redirected. Recently, a new environment variable has been added to override this: dotnet/runtime#47935

Setting below environment variables will enable colorful output when running on GitHub Actions (not on Windows though):

  • DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION to 1 or true
  • TERM to xterm

More info: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_system_console_allow_ansi_color_redirection

Relevant discussion explaining the need for the second variable: dotnet/runtime#68302 (comment)

Justification:

Colorful output is much easier to visually parse and, since we can guarantee that we're always running on GitHub Actions (which supports ansi color escape codes), it makes sense to make this setting enabled by default. As the worst case, this should be at least added as one of the action inputs, but I think enabling it by default is the way to go (not anymore, read comments below).

Are you willing to submit a PR?

Sure

@vsafonkin
Copy link

Hi @Tyrrrz, we will take a look at this, thank you for your contribution!

@Tyrrrz
Copy link
Author

Tyrrrz commented Apr 21, 2022

Just as a note, we noticed that setting this variable manually on GitHub Actions still seems to not produce the expected color codes. It does work locally though. It's probably an issue with the dotnet CLI. 🤔

Here's the relevant discussion: dotnet/runtime#68302

Update: according to this comment, setting TERM: xterm is also required. Edited the original post.

@vsafonkin
Copy link

@Tyrrrz, it seems to me the setting of these variables is out of scope setup-dotnet action cause it's related to kind of customisation .NET installation but the goal of the action to install required .NET version with minimum custom configuration. It will be better the users will set these settings as workflow env variables from their side.

@Tyrrrz
Copy link
Author

Tyrrrz commented Apr 21, 2022

@Tyrrrz, it seems to me the setting of these variables is out of scope setup-dotnet action cause it's related to kind of customisation .NET installation but the goal of the action to install required .NET version with minimum custom configuration. It will be better the users will set these settings as workflow env variables from their side.

I understand your point, but here's why I think it makes sense as an addition to setup-dotnet:

  1. Colored output looks much nicer without any drawbacks. I can't imagine a situation where a user may not want it.
  2. The two environment variables (DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION and TERM) are used to convince dotnet that the output terminal/renderer supports color codes. This is always true in case with GitHub Actions.
  3. Most users are not aware that this is an option that they can set at all. Putting it in setup-dotnet would guarantee that everyone gets it.

That said, there may be some edge-cases such as if some step relies on the output of a dotnet command to have a specific format (for example regex) that this option may break. Because of this, I now realize it's probably not a great idea to have it enabled by default in those cases (unless with a major version bump?).

In any case, I leave the decision with you :) I'm personally okay setting this manually for my own projects.

@timheuer
Copy link
Contributor

Great suggestion @Tyrrrz! I'm in favor of this as well and brings this inline with some of the other colored output we see in Actions and other setup scripts as well (with node/etc). This seems like a small, but useful, thing to see in the unformatted log views. I think you identified a possible case (item 3 above) that could be a possibility, but could be easily gated with another input on the action (colored-output: false) but the majority of users win.

I'd love to see this in.

@vsafonkin
Copy link

cc @marko-zivic-93 @brcrista

@xt0rted
Copy link

xt0rted commented Apr 21, 2022

...there may be some edge-cases such as if some step relies on the output of a dotnet command to have a specific format...

This is actually the case with FORCE_COLOR in node with the setup-node action (ref: actions/setup-node#317). When enabling that and using the cache option the post setup step fails because of the color codes in the log. The solution there is to disable that setting on the setup-node step, but it does catch you off guard if you don't know about it.

@xt0rted
Copy link

xt0rted commented Apr 21, 2022

I've started to maintain a composite action that wraps this one and implements features that aren't yet supported. I just added this feature to it in case anyone's interested in trying it out. https://github.com/xt0rted/setup-dotnet

@vsafonkin
Copy link

I'm going to close this issue. More details in the PR: #293

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

No branches or pull requests

4 participants