From b6ad03436de783efa119f94ef33b5fc55aeacdf7 Mon Sep 17 00:00:00 2001 From: Konstantin Aksenov Date: Tue, 5 Apr 2022 22:34:47 +1000 Subject: [PATCH] Add sample teamcity configuration --- .../config/BuildManagementConfiguration.kt | 18 +++++++++++++++ .../marathon/config/Configuration.kt | 11 ++++++++-- .../execution/progress/ProgressReporter.kt | 22 +++++++++++++++---- .../buildmanagement/BuildManagement.kt | 6 +++++ .../integration/buildmanagement/Teamcity.kt | 6 +++++ 5 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 configuration/src/main/kotlin/com/malinskiy/marathon/config/BuildManagementConfiguration.kt create mode 100644 core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/BuildManagement.kt create mode 100644 core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/Teamcity.kt diff --git a/configuration/src/main/kotlin/com/malinskiy/marathon/config/BuildManagementConfiguration.kt b/configuration/src/main/kotlin/com/malinskiy/marathon/config/BuildManagementConfiguration.kt new file mode 100644 index 000000000..963dc8bba --- /dev/null +++ b/configuration/src/main/kotlin/com/malinskiy/marathon/config/BuildManagementConfiguration.kt @@ -0,0 +1,18 @@ +package com.malinskiy.marathon.config + +import com.fasterxml.jackson.annotation.JsonSubTypes +import com.fasterxml.jackson.annotation.JsonTypeInfo + +@JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + include = JsonTypeInfo.As.PROPERTY, + property = "type" +) +@JsonSubTypes( + JsonSubTypes.Type(value = BuildManagementConfiguration.TeamCityConfiguration::class, name = "teamcity"), +) +sealed class BuildManagementConfiguration { + object TeamCityConfiguration : BuildManagementConfiguration() + object NoBuildManagementConfiguration: BuildManagementConfiguration() +} + diff --git a/configuration/src/main/kotlin/com/malinskiy/marathon/config/Configuration.kt b/configuration/src/main/kotlin/com/malinskiy/marathon/config/Configuration.kt index b93b14492..14f239c0f 100644 --- a/configuration/src/main/kotlin/com/malinskiy/marathon/config/Configuration.kt +++ b/configuration/src/main/kotlin/com/malinskiy/marathon/config/Configuration.kt @@ -48,6 +48,8 @@ data class Configuration private constructor( val analyticsTracking: Boolean, val deviceInitializationTimeoutMillis: Long, + + val buildManagementConfiguration: BuildManagementConfiguration, ) { fun toMap() = mapOf( @@ -73,7 +75,8 @@ data class Configuration private constructor( "debug" to debug.toString(), "screenRecordingPolicy" to screenRecordingPolicy.toString(), "vendorConfiguration" to vendorConfiguration.toString(), - "deviceInitializationTimeoutMillis" to deviceInitializationTimeoutMillis.toString() + "deviceInitializationTimeoutMillis" to deviceInitializationTimeoutMillis.toString(), + "buildManagementConfiguration" to buildManagementConfiguration.toString() ) override fun equals(other: Any?): Boolean { @@ -108,6 +111,7 @@ data class Configuration private constructor( if (vendorConfiguration != other.vendorConfiguration) return false if (analyticsTracking != other.analyticsTracking) return false if (deviceInitializationTimeoutMillis != other.deviceInitializationTimeoutMillis) return false + if (buildManagementConfiguration != other.buildManagementConfiguration) return false return true } @@ -138,6 +142,7 @@ data class Configuration private constructor( result = 31 * result + vendorConfiguration.hashCode() result = 31 * result + analyticsTracking.hashCode() result = 31 * result + deviceInitializationTimeoutMillis.hashCode() + result = 31 * result + buildManagementConfiguration.hashCode() return result } @@ -155,6 +160,7 @@ data class Configuration private constructor( var flakinessStrategy: FlakinessStrategyConfiguration = FlakinessStrategyConfiguration.IgnoreFlakinessStrategyConfiguration var retryStrategy: RetryStrategyConfiguration = RetryStrategyConfiguration.NoRetryStrategyConfiguration var filteringConfiguration: FilteringConfiguration = FilteringConfiguration(emptyList(), emptyList()) + var buildManagementConfiguration = BuildManagementConfiguration.NoBuildManagementConfiguration var ignoreFailures: Boolean = false var isCodeCoverageEnabled: Boolean = false @@ -201,7 +207,8 @@ data class Configuration private constructor( screenRecordingPolicy = screenRecordingPolicy, vendorConfiguration = vendorConfiguration, analyticsTracking = analyticsTracking, - deviceInitializationTimeoutMillis = deviceInitializationTimeoutMillis + deviceInitializationTimeoutMillis = deviceInitializationTimeoutMillis, + buildManagementConfiguration = buildManagementConfiguration ) } } diff --git a/core/src/main/kotlin/com/malinskiy/marathon/execution/progress/ProgressReporter.kt b/core/src/main/kotlin/com/malinskiy/marathon/execution/progress/ProgressReporter.kt index 93df275bf..461acdcd9 100644 --- a/core/src/main/kotlin/com/malinskiy/marathon/execution/progress/ProgressReporter.kt +++ b/core/src/main/kotlin/com/malinskiy/marathon/execution/progress/ProgressReporter.kt @@ -1,9 +1,11 @@ package com.malinskiy.marathon.execution.progress +import com.malinskiy.marathon.config.BuildManagementConfiguration import com.malinskiy.marathon.config.Configuration import com.malinskiy.marathon.device.DeviceInfo import com.malinskiy.marathon.device.DevicePoolId import com.malinskiy.marathon.execution.progress.tracker.PoolProgressTracker +import com.malinskiy.marathon.integration.buildmanagement.Teamcity import com.malinskiy.marathon.test.Test import com.malinskiy.marathon.test.toTestName import java.util.concurrent.ConcurrentHashMap @@ -13,6 +15,10 @@ const val HUNDRED_PERCENT_IN_FLOAT: Float = 100.0f class ProgressReporter(private val configuration: Configuration) { private val reporters = ConcurrentHashMap() + private val buildManagement = when(configuration.buildManagementConfiguration) { + BuildManagementConfiguration.NoBuildManagementConfiguration -> Teamcity + BuildManagementConfiguration.TeamCityConfiguration -> null + } private inline fun execute(poolId: DevicePoolId, f: (PoolProgressTracker) -> T): T { val reporter = reporters[poolId] ?: PoolProgressTracker(configuration) @@ -29,22 +35,30 @@ class ProgressReporter(private val configuration: Configuration) { fun testStarted(poolId: DevicePoolId, device: DeviceInfo, test: Test) { execute(poolId) { it.testStarted(test) } - println("${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} started") + val message = "${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} started" + println(message) + buildManagement?.setBuildMessage(message) } fun testFailed(poolId: DevicePoolId, device: DeviceInfo, test: Test) { execute(poolId) { it.testFailed(test) } - println("${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} failed") + val message = "${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} failed" + println(message) + buildManagement?.setBuildMessage(message) } fun testPassed(poolId: DevicePoolId, device: DeviceInfo, test: Test) { execute(poolId) { it.testPassed(test) } - println("${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} ended") + val message = "${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} ended" + println(message) + buildManagement?.setBuildMessage(message) } fun testIgnored(poolId: DevicePoolId, device: DeviceInfo, test: Test) { execute(poolId) { it.testIgnored(test) } - println("${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} ignored") + val message = "${toPercent(progress(poolId))} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} ignored" + println(message) + buildManagement?.setBuildMessage(message) } fun aggregateResult(): Boolean { diff --git a/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/BuildManagement.kt b/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/BuildManagement.kt new file mode 100644 index 000000000..7fe1b7e5f --- /dev/null +++ b/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/BuildManagement.kt @@ -0,0 +1,6 @@ +package com.malinskiy.marathon.integration.buildmanagement + +interface BuildManagement { + fun setBuildMessage(message: String) + fun setKeyValue(key: String, value: String) +} diff --git a/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/Teamcity.kt b/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/Teamcity.kt new file mode 100644 index 000000000..e7ff143e7 --- /dev/null +++ b/core/src/main/kotlin/com/malinskiy/marathon/integration/buildmanagement/Teamcity.kt @@ -0,0 +1,6 @@ +package com.malinskiy.marathon.integration.buildmanagement + +object Teamcity : BuildManagement { + override fun setBuildMessage(message: String) = println("##teamcity[buildStatus text='$message']") + override fun setKeyValue(key: String, value: String) = println("##teamcity[buildStatisticValue key='$key' value='$value']") +}