question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Set the environment variable to enable colorful output by default

See original GitHub issue

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: https://github.com/dotnet/runtime/pull/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: https://github.com/dotnet/runtime/discussions/68302#discussioncomment-2605104

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:7
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
xt0rtedcommented, 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: https://github.com/actions/setup-node/issues/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.

2reactions
Tyrrrzcommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there any env variable to turn --color (and the like) on for all ...
This is what I put in my .bashrc (well, really my .env, but it's like .bashrc) to make it happen by default: #...
Read more >
Color output in console - ArchWiki
The LS_COLORS variable is used to define colors, and it configures various parts of highlighting. Use the dircolors(1) command to set it.
Read more >
[Modules] Colored output | Environment Modules - SourceForge
Manage your shell environment variables and aliases ... Default color mode could be controlled at configure time with the `--enable-color` and the ...
Read more >
NO_COLOR: disabling ANSI color output in various Unix ...
Software Description Date/Version Supported alogview Android logcat Filter 2018‑10‑31 Ammonite Scala Scripting 2017‑07‑03 / 1.0.0 Ansible IT automation system 2021‑04‑26 / 2.11.0
Read more >
Grep default color option - linux - Super User
3 Answers 3 · 12. Or equivalently, set the GREP_OPTIONS environment variable: export GREP_OPTIONS='--color=always' · This doesn't add the color ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found