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 doesn't work on github actions out of the box #130

Open
os14 opened this issue May 30, 2024 · 2 comments
Open

colors doesn't work on github actions out of the box #130

os14 opened this issue May 30, 2024 · 2 comments

Comments

@os14
Copy link

os14 commented May 30, 2024

Is your feature request related to a problem? Please describe.
we have a cli tool that uses charmbracelet/log for logging, locally it prints nice colors, but in github actions terminal it doesn't print colors.

Describe the solution you'd like
perhaps the issue is on github side but i would like to get a workaround for this or ideally make it works out of the box.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
local:
image

github actions:
image

@os14 os14 added the enhancement New feature or request label May 30, 2024
@aymanbagabas aymanbagabas removed the enhancement New feature or request label May 30, 2024
@aymanbagabas
Copy link
Member

@os14 this is intentional, GitHub Actions and other CIs export CI=1 to indicate that the application is running in a CI environment. Some CIs don't support colors. Termenv, the underlying library currently used to render colors, detects the CI environment variable and disables colors accordingly. To enable colors make sure that you set CI='' in your workflow or application.

@paleboot
Copy link

@os14 this is intentional, GitHub Actions and other CIs export CI=1 to indicate that the application is running in a CI environment. Some CIs don't support colors. Termenv, the underlying library currently used to render colors, detects the CI environment variable and disables colors accordingly. To enable colors make sure that you set CI='' in your workflow or application.

I found that, in GitHub Actions at least, all it takes is CLICOLOR_FORCE=1.

I tested the logics here:

Using the following snippet:

// fatih/color
white := color.New(color.FgBlue)
boldWhite := white.Add(color.Bold)
boldWhite.Println("Colors using fatih/color")

// charmbracelet/log
logger := log.New(os.Stdout)
logger.Info("Colors using charmbracelet/log")

if isatty.IsTerminal(os.Stdout.Fd()) {
	fmt.Println("IsTerminal: true")
} else {
	fmt.Println("IsTerminal: false")
}
fmt.Printf("TERM: %s\n", os.Getenv("TERM"))
fmt.Printf("CI: %s\n", os.Getenv("CI"))
fmt.Printf("CLICOLOR_FORCE: %s\n", os.Getenv("CLICOLOR_FORCE"))

and adding the following to the Github Actions step, more info on that here:

shell: 'script -q -e -c "bash --noprofile --norc -eo pipefail {0}"'

Here are the results:

  • image
  • image
  • image
  • image
  • image
  • image
  • image

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

No branches or pull requests

3 participants