-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Enable terminal colors in CI #57998
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
Comments
Already implemented. |
check you CI env var maybe no color is enabled |
No. Colors are disabled by default on GitHub actions. I made a reproduction: https://github.com/remcohaszing/node-issue-styletext. You can see the CI output here: https://github.com/remcohaszing/node-issue-styletext/actions/runs/14704349430/job/41260837797 |
It's strange because I can't reproduce the result on my Mac M1. Could it be GH?? no idea, I'm going to make myself a docker with ubuntu. EDIT: |
The following yields the same result: docker run --rm node:22.15 -e 'console.log(util.styleText(["red"], "array")); console.log(util.styleText("red", "string")); console.dir(process.env)' Whereas the same command on my own Linux laptop does yield colors: node -e 'console.log(util.styleText(["red"], "array")); console.log(util.styleText("red", "string")); console.dir(process.env)' I don’t necessarily really Docker output to be colorized. This can run in many contexts. But I do think it would be nice to support colors in some common specific environments that are known to support colors, notably in CI. |
I just used docker to have a local ubuntu environment. |
You can start an interactive Node.js shell with: docker run -ti --rm node:22.15 Or an interactive bash shell with: docker run -ti --rm --entrypoint bash node:22.15 In both these cases It just doesn’t add colors for non-interactive stdout. Another example to explicitly disallow colors piping the output through node -e 'console.log(util.styleText(["red"], "array")); console.log(util.styleText("red", "string"))' | cat I think everything works as expected. There are just some situations where a non-interactive shell still supports colors. Mainly CI output comes to mind. |
According to https://github.com/chalk/supports-color/blob/ae809ecabd5965d0685e7fc121efe98c47ad8724/index.js#L126-L129, the only way to enable colors support by default on CI hosts is to hardcode them. |
Do we want that on node core ??? and do we have a fix for that using force_color ? |
Ideological I’m in doubt. I believe CI systems that support colors, should signal that. In practice however, I think this will never happen, but individual users of As a practical example, I use this in function color(style, text) {
return styleText(style, text, {
validateStream: !process.env.GITLAB_CI
})
} For an individual case is fine of course, but I think every project should do this. And also every project should support other CI environments as well. So realistically one currently still needs a userland library to support terminal colors. You could also assume that basic colors are supported when |
Wait, we already have the hardcoded CI variables: Lines 161 to 174 in fca4107
This might actually be a bug in |
I think the function itself is good, it's the function itself node/lib/internal/util/colors.js Line 18 in fca4107
|
This adds a couple new entries or increases the support depending on newer data. I checked ncurses, tput, supports-color, and termstandard on github. Most updates are from supports-color. PR-URL: #58146 Refs: #57998 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a couple new entries or increases the support depending on newer data. I checked ncurses, tput, supports-color, and termstandard on github. Most updates are from supports-color. PR-URL: #58146 Refs: #57998 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This adds a couple new entries or increases the support depending on newer data. I checked ncurses, tput, supports-color, and termstandard on github. Most updates are from supports-color. PR-URL: #58146 Refs: #57998 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Uh oh!
There was an error while loading. Please reload this page.
What is the problem this feature will solve?
I noticed
util.styleText()
supports colorizing text in GitLab CI and GitHub Actions in 22.14, but not in 22.15. And in 22.14, only when the color input is an array. The cause is #56722. That PR correctly solves the bug it references. But it does raise a question: Shouldutil.styleText()
enable colors if it runs in a CI provider that supports it? I think it would be nice to have.What is the feature you are proposing to solve the problem?
Enable colorizing text if Node.js runs in a CI provider that is known to support colors.
What alternatives have you considered?
Keep the status quo. Don’t support colorizing text in CI by default.
The text was updated successfully, but these errors were encountered: