Skip to content

Commit

Permalink
refactor(analytics): skip github_action env variable (#3964) (#3965)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7695df6)

Co-authored-by: Julien Robert <[email protected]>
  • Loading branch information
mergify[bot] and julienrbrt authored Feb 14, 2024
1 parent 3ad6eff commit 1beb7b1
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"

Expand All @@ -21,6 +22,7 @@ const (
telemetryEndpoint = "https://telemetry-cli.ignite.com"
envDoNotTrack = "DO_NOT_TRACK"
envCI = "CI"
envGitHubActions = "GITHUB_ACTIONS"
igniteDir = ".ignite"
igniteAnonIdentity = "anon_identity.json"
)
Expand Down Expand Up @@ -73,8 +75,7 @@ func SendMetric(wg *sync.WaitGroup, cmd *cobra.Command) {
// checkDNT check if the user allow to track data or if the DO_NOT_TRACK
// env var is set https://consoledonottrack.com/
func checkDNT() (anonIdentity, error) {
envDoNotTrackVar := os.Getenv(envDoNotTrack)
if envDoNotTrackVar == "1" || strings.ToLower(envDoNotTrackVar) == "true" {
if dnt, err := strconv.ParseBool(os.Getenv(envDoNotTrack)); err != nil || dnt {
return anonIdentity{DoNotTrack: true}, nil
}

Expand Down Expand Up @@ -126,7 +127,19 @@ func checkDNT() (anonIdentity, error) {
}

func getIsCI() bool {
str := strings.ToLower(os.Getenv(envCI))
ci, err := strconv.ParseBool(os.Getenv(envCI))
if err != nil {
return false
}

if ci {
return true
}

ci, err = strconv.ParseBool(os.Getenv(envGitHubActions))
if err != nil {
return false
}

return str == "1" || str == "true"
return ci
}

0 comments on commit 1beb7b1

Please sign in to comment.