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

chore(telemetry): check for ci environments #1556

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
45 changes: 42 additions & 3 deletions pkg/telemetry/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/loft-sh/devpod/pkg/config"
"github.com/loft-sh/devpod/pkg/version"
"github.com/loft-sh/log"
"github.com/moby/term"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -114,11 +115,23 @@ func (d *cliCollector) RecordCLI(err error) {
}
}

isCI := false
if !isUI {
isCI = isCIEnvironment()
}

isInteractive := false
if !isUI {
isInteractive = isInteractiveShell()
}

timezone, _ := time.Now().Zone()
eventProperties := map[string]interface{}{
"command": cmd,
"version": version.GetVersion(),
"desktop": isUI,
"command": cmd,
"version": version.GetVersion(),
"desktop": isUI,
"is_ci": isCI,
"is_interactive": isInteractive,
}
if d.client != nil {
eventProperties["provider"] = d.client.Provider()
Expand Down Expand Up @@ -167,3 +180,29 @@ func (d *cliCollector) RecordCLI(err error) {
},
})
}

// isCIEnvironment looks up a couple of well-known CI env vars
func isCIEnvironment() bool {
ciIndicators := []string{
"CI", // Generic CI variable
"TRAVIS", // Travis CI
"GITHUB_ACTIONS", // GitHub Actions
"GITLAB_CI", // GitLab CI
"CIRCLECI", // CircleCI
"TEAMCITY_VERSION", // TeamCity
"BITBUCKET_BUILD_NUMBER", // Bitbucket
}

for _, key := range ciIndicators {
if _, exists := os.LookupEnv(key); exists {
return true
}
}
return false
}

// isInteractiveShell checks if the current shell is in interactive mode or not.
// Can be combined with `isCi` to narrow down usage
func isInteractiveShell() bool {
return term.IsTerminal(os.Stdin.Fd())
}
Loading