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

Detect CI environments for default no-color value #330

Merged
merged 7 commits into from Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 additions & 2 deletions cmd/main.go
Expand Up @@ -201,8 +201,32 @@ func (o options) Validate() error {
}

var defaultNoColor = func() bool {
if os.Getenv("GITHUB_ACTIONS") == "true" {
return false
// fatih/color will only output color when stdout is a terminal which is not
// true for many CI environments which support color output. So instead, we
// try to detect these CI environments via their environment variables.
// This code is based on https://github.com/jwalton/go-supportscolor
if _, exists := os.LookupEnv("CI"); exists {
var ciEnvNames = []string{
"APPVEYOR",
"BUILDKITE",
"CIRCLECI",
"DRONE",
"GITEA_ACTIONS",
"GITHUB_ACTIONS",
"GITLAB_CI",
"TRAVIS",
}
for _, ciEnvName := range ciEnvNames {
if _, exists := os.LookupEnv(ciEnvName); exists {
return false
}
}
if _, exists := os.LookupEnv("TEAMCITY_VERSION"); exists {
return false
}
silverwind marked this conversation as resolved.
Show resolved Hide resolved
if os.Getenv("CI_NAME") == "codeship" {
return false
}
}
return color.NoColor
}()
Expand Down
2 changes: 1 addition & 1 deletion cmd/testdata/gotestsum-help-text
Expand Up @@ -18,7 +18,7 @@ Flags:
--junitfile-testcase-classname field-format format the testcase classname field as: full, relative, short (default full)
--junitfile-testsuite-name field-format format the testsuite name field as: full, relative, short (default full)
--max-fails int end the test run after this number of failures
--no-color disable color output (default true)
--no-color disable color output
--packages list space separated list of package to test
--post-run-command command command to run after the tests have completed
--raw-command don't prepend 'go test -json' to the 'go test' command
Expand Down