Skip to content

Commit

Permalink
Merge pull request #330 from silverwind/drone
Browse files Browse the repository at this point in the history
Detect CI environments for default `no-color` value
  • Loading branch information
dnephin committed Jun 16, 2023
2 parents 6d53517 + 3e99957 commit 00a4f25
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
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

0 comments on commit 00a4f25

Please sign in to comment.