Skip to content

Commit

Permalink
Add MAESTRO_CLI_NO_ANALYTICS flag (#1848)
Browse files Browse the repository at this point in the history
* add MAESTRO_CLI_NO_ANALYTICS flag

* add more CI providers

* update changelog and version

* CiUtils: add comments when particular CI service envvar was added
  • Loading branch information
bartekpacia authored Jul 30, 2024
1 parent d453545 commit 0cd8bc1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Changelog

## 1.37.4 - 2024-07-30

- Don't ask for analytics permission on CI + add `MAESTRO_CLI_NO_ANALYTICS` env var ([#1848](https://github.com/mobile-dev-inc/maestro/pull/1848))

## 1.37.3 - 2024-07-29

### Bug fixes

Fix `FileNotFoundException: ~.maestro/sessions` ([#1843](https://github.com/mobile-dev-inc/maestro/pull/1843))
- Fix `FileNotFoundException: ~.maestro/sessions` ([#1843](https://github.com/mobile-dev-inc/maestro/pull/1843))

## 1.37.2 - 2024-07-29

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
GROUP=dev.mobile
VERSION_NAME=1.37.3
VERSION_NAME=1.37.4
POM_DESCRIPTION=Maestro is a server-driven platform-agnostic library that allows to drive tests for both iOS and Android using the same implementation through an intuitive API.
POM_URL=https://github.com/mobile-dev-inc/maestro
POM_SCM_URL=https://github.com/mobile-dev-inc/maestro
Expand Down
2 changes: 1 addition & 1 deletion maestro-cli/gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CLI_VERSION=1.37.3
CLI_VERSION=1.37.4
25 changes: 24 additions & 1 deletion maestro-cli/src/main/java/maestro/cli/analytics/Analytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ object Analytics {
private val analyticsStatePath: Path = EnvUtils.xdgStateHome().resolve("analytics.json")
private val legacyUuidPath: Path = EnvUtils.legacyMaestroHome().resolve("uuid")

private const val DISABLE_ANALYTICS_ENV_VAR = "MAESTRO_CLI_NO_ANALYTICS"
private val analyticsDisabledWithEnvVar: Boolean
get() = System.getenv(DISABLE_ANALYTICS_ENV_VAR) != null

private val JSON = jacksonObjectMapper().apply {
registerModule(JavaTimeModule())
enable(SerializationFeature.INDENT_OUTPUT)
Expand Down Expand Up @@ -73,6 +77,21 @@ object Analytics {
fun maybeAskToEnableAnalytics() {
if (hasRunBefore) return

// Fix for https://github.com/mobile-dev-inc/maestro/issues/1846
if (CiUtils.getCiProvider() != null) {
if (!analyticsDisabledWithEnvVar) {
println("CI detected, analytics was automatically enabled.")
println("To opt out, set $DISABLE_ANALYTICS_ENV_VAR environment variable to any value before running Maestro.")
} else {
println("CI detected and $DISABLE_ANALYTICS_ENV_VAR environment variable set, analytics disabled.")
}
return
}

if (analyticsDisabledWithEnvVar) {
return
}

while (!Thread.interrupted()) {
println("Maestro CLI would like to collect anonymous usage data to improve the product.")
print("Enable analytics? [Y/n] ")
Expand All @@ -99,8 +118,12 @@ object Analytics {
return
}

if (analyticsDisabledWithEnvVar) {
logger.trace("Analytics disabled with env var, not uploading")
}

if (!analyticsState.enabled) {
logger.trace("Analytics disabled, not uploading")
logger.trace("Analytics disabled with config file, not uploading")
return
}

Expand Down
23 changes: 16 additions & 7 deletions maestro-cli/src/main/java/maestro/cli/util/CiUtils.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package maestro.cli.util

object CiUtils {

// When adding a new CI, also add the first version of Maestro that supports it.
private val ciEnvVarMap = mapOf(
"JENKINS_HOME" to "jenkins",
"APPVEYOR" to "appveyor", // since v1.37.4
"BITBUCKET_BUILD_NUMBER" to "bitbucket",
"BITRISE_IO" to "bitrise",
"BUILDKITE" to "buildkite", // since v1.37.4
"CIRCLECI" to "circleci",
"GITLAB_CI" to "gitlab",
"CIRRUS_CI" to "cirrusci", // since v1.37.4
"DRONE" to "drone", // since v1.37.4
"GITHUB_ACTIONS" to "github",
"BITBUCKET_BUILD_NUMBER" to "bitbucket",
"GITLAB_CI" to "gitlab",
"JENKINS_HOME" to "jenkins",
"TEAMCITY_VERSION" to "teamcity", // since v1.37.4
"CI" to "ci"
)

Expand All @@ -22,12 +29,14 @@ object CiUtils {
return mdevCiEnvVar
}

for (ciVar in ciEnvVarMap.entries) {
for (ciEnvVar in ciEnvVarMap.entries) {
try {
if (isTruthy(System.getenv(ciVar.key).lowercase())) return ciVar.value
} catch (e: Exception) {}
if (isTruthy(System.getenv(ciEnvVar.key).lowercase())) return ciEnvVar.value
} catch (e: Exception) {
// We don't care
}
}

return null
}
}
}

0 comments on commit 0cd8bc1

Please sign in to comment.