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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,31 @@ func (o options) Validate() error {
}

var defaultNoColor = func() bool {
if os.Getenv("GITHUB_ACTIONS") == "true" {
// 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 os.Getenv("CI_NAME") == "codeship" {
return false
}
}
if _, exists := os.LookupEnv("TEAMCITY_VERSION"); exists {
return false
}
return color.NoColor
Expand Down
2 changes: 1 addition & 1 deletion cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
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