Skip to content

Commit b59e7ea

Browse files
authored
fix: log output in CI (#258)
1 parent c903ffb commit b59e7ea

File tree

6 files changed

+28
-22
lines changed

6 files changed

+28
-22
lines changed

cmd/internal/flags/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var LogModeFlag = &Metadata{
2727
Name: "log-mode",
2828
Shorthand: "m",
2929
Usage: "Log mode (text, logfmt, json, hidden)",
30-
Default: "logfmt",
30+
Default: "",
3131
Required: false,
3232
}
3333

docs/cli/flow_exec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ flow exec EXECUTABLE_ID [args...] [flags]
5151

5252
```
5353
-h, --help help for exec
54-
-m, --log-mode string Log mode (text, logfmt, json, hidden) (default "logfmt")
54+
-m, --log-mode string Log mode (text, logfmt, json, hidden)
5555
-p, --param stringArray Set a parameter value by env key. (i.e. KEY=value) Use multiple times to set multiple parameters.This will override any existing parameter values defined for the executable.
5656
```
5757

internal/services/run/run.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,7 @@ import (
1515
)
1616

1717
func init() {
18-
if _, exists := os.LookupEnv("TERM"); !exists {
19-
_ = os.Setenv("TERM", "xterm-256color")
20-
}
21-
if _, exists := os.LookupEnv("FORCE_COLOR"); !exists {
22-
_ = os.Setenv("FORCE_COLOR", "1")
23-
}
24-
if _, exists := os.LookupEnv("CLICOLOR_FORCE"); !exists {
25-
_ = os.Setenv("CLICOLOR_FORCE", "1")
26-
}
18+
setupColorEnvironment()
2719
}
2820

2921
// RunCmd executes a command in the current shell in a specific directory.
@@ -144,3 +136,26 @@ func stdOutWriter(mode io.LogMode, logger io.Logger, logFields ...any) stdio.Wri
144136
func stdErrWriter(mode io.LogMode, logger io.Logger, logFields ...any) stdio.Writer {
145137
return io.StdErrWriter{LogFields: logFields, Logger: logger, LogMode: &mode}
146138
}
139+
140+
func setupColorEnvironment() {
141+
hasColorPreference := os.Getenv("NO_COLOR") != "" ||
142+
os.Getenv("FORCE_COLOR") != "" ||
143+
os.Getenv("CLICOLOR_FORCE") != ""
144+
145+
if !hasColorPreference {
146+
isCI := os.Getenv("CI") != "" || os.Getenv("GITHUB_ACTIONS") != ""
147+
isTesting := strings.HasSuffix(os.Args[0], ".test")
148+
149+
if isCI || isTesting {
150+
_ = os.Setenv("NO_COLOR", "1")
151+
} else {
152+
_ = os.Setenv("FORCE_COLOR", "1")
153+
_ = os.Setenv("CLICOLOR_FORCE", "1")
154+
}
155+
}
156+
157+
// Always ensure TERM is set if colors might be used
158+
if os.Getenv("NO_COLOR") == "" && os.Getenv("TERM") == "" {
159+
_ = os.Setenv("TERM", "xterm-256color")
160+
}
161+
}

internal/utils/utils.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,3 @@ func IsZeroValue(v interface{}) bool {
164164
}
165165
return reflect.DeepEqual(v, reflect.Zero(reflect.TypeOf(v)).Interface())
166166
}
167-
168-
//nolint:lll
169-
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
170-
171-
var re = regexp.MustCompile(ansi)
172-
173-
func StripAnsi(str string) string {
174-
return re.ReplaceAllString(str, "")
175-
}

tests/secret_cmds_e2e_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
. "github.com/onsi/ginkgo/v2"
1111
. "github.com/onsi/gomega"
1212

13-
internalUtils "github.com/jahvon/flow/internal/utils"
1413
"github.com/jahvon/flow/tests/utils"
1514
)
1615

@@ -45,7 +44,7 @@ var _ = Describe("vault/secrets e2e", Ordered, func() {
4544
Expect(lines).ToNot(BeEmpty())
4645
parts := strings.Split(strings.TrimSpace(lines[0]), ":")
4746
Expect(parts).To(HaveLen(2))
48-
encryptionKey := strings.TrimSpace(internalUtils.StripAnsi(parts[1]))
47+
encryptionKey := strings.TrimSpace(parts[1])
4948
Expect(os.Setenv(keyEnv, encryptionKey)).To(Succeed())
5049
})
5150

tests/utils/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ func setTestEnv(t ginkgo.FullGinkgoTInterface, configDir, cacheDir string) {
286286
t.Setenv(filesystem.FlowConfigDirEnvVar, configDir)
287287
t.Setenv(filesystem.FlowCacheDirEnvVar, cacheDir)
288288
t.Setenv(store.BucketEnv, "")
289+
t.Setenv("NO_COLOR", "1")
289290
}
290291

291292
func expectInternalMockLoggerCalls(logger *tuikitIOMocks.MockLogger) {

0 commit comments

Comments
 (0)