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

feat(core): basic ci integration #964

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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 = CIConfiguration.Auto::class, name = "auto"),
JsonSubTypes.Type(value = CIConfiguration.None::class, name = "none"),
JsonSubTypes.Type(value = CIConfiguration.Teamcity::class, name = "teamcity"),
)
sealed class CIConfiguration {
object Auto : CIConfiguration()
object None : CIConfiguration()
object Teamcity : CIConfiguration()
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data class Configuration private constructor(
val analyticsTracking: Boolean,
val bugsnagReporting: Boolean,
val deviceInitializationTimeoutMillis: Long,
val ciConfiguration: CIConfiguration,
) {
fun toMap() =
mapOf<String, String>(
Expand All @@ -74,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(),
"ciConfiguration" to ciConfiguration.toString(),
)

override fun equals(other: Any?): Boolean {
Expand Down Expand Up @@ -108,6 +110,7 @@ data class Configuration private constructor(
if (analyticsTracking != other.analyticsTracking) return false
if (bugsnagReporting != other.bugsnagReporting) return false
if (deviceInitializationTimeoutMillis != other.deviceInitializationTimeoutMillis) return false
if (ciConfiguration != other.ciConfiguration) return false

return true
}
Expand Down Expand Up @@ -138,6 +141,7 @@ data class Configuration private constructor(
result = 31 * result + analyticsTracking.hashCode()
result = 31 * result + bugsnagReporting.hashCode()
result = 31 * result + deviceInitializationTimeoutMillis.hashCode()
result = 31 * result + ciConfiguration.hashCode()
return result
}

Expand Down Expand Up @@ -173,6 +177,7 @@ data class Configuration private constructor(

var outputConfiguration: OutputConfiguration = OutputConfiguration(),
var vendorConfiguration: VendorConfiguration = VendorConfiguration.EmptyVendorConfiguration(),
var ciConfiguration: CIConfiguration = CIConfiguration.None,
) {
fun build(): Configuration {
return Configuration(
Expand Down Expand Up @@ -200,7 +205,8 @@ data class Configuration private constructor(
vendorConfiguration = vendorConfiguration,
analyticsTracking = analyticsTracking,
bugsnagReporting = bugsnagReporting,
deviceInitializationTimeoutMillis = deviceInitializationTimeoutMillis
deviceInitializationTimeoutMillis = deviceInitializationTimeoutMillis,
ciConfiguration = ciConfiguration,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.malinskiy.marathon.execution.TestStatus
import com.malinskiy.marathon.execution.queue.TestAction
import com.malinskiy.marathon.execution.queue.TestEvent
import com.malinskiy.marathon.execution.queue.TestState
import com.malinskiy.marathon.integrations.ci.CIIntegrationFactory
import com.malinskiy.marathon.log.MarathonLogging
import com.malinskiy.marathon.test.Test
import com.malinskiy.marathon.test.toTestName
Expand All @@ -26,6 +27,7 @@ class PoolProgressAccumulator(
private val tests: HashMap<String, TestExecutionData> = HashMap()
private val logger = MarathonLogging.logger {}
private val executionStrategy = configuration.executionStrategy
private val ci = CIIntegrationFactory.get(configuration)

private fun createState(initialCount: Int) = StateMachine.create<TestState, TestEvent, TestAction> {
initialState(TestState.Added(initialCount))
Expand Down Expand Up @@ -265,6 +267,7 @@ class PoolProgressAccumulator(

fun testStarted(device: DeviceInfo, test: Test) {
transition(test, TestEvent.Started)
ci.setBuildProgress(progress().toInt())
println("${toPercent(progress())} | [${poolId.name}]-[${device.serialNumber}] ${test.toTestName()} started")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.malinskiy.marathon.integrations.ci

interface CI {
fun setBuildProgress(int: Int)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.malinskiy.marathon.integrations.ci

import com.malinskiy.marathon.config.CIConfiguration
import com.malinskiy.marathon.config.Configuration

object CIIntegrationFactory {
fun get(configuration: Configuration) = when (configuration.ciConfiguration) {
CIConfiguration.Auto -> auto()
CIConfiguration.None -> None
CIConfiguration.Teamcity -> Teamcity
}

private fun auto() = when {
// Teamcity predefined variables: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#84e0b866
System.getenv().containsValue("TEAMCITY_VERSION") -> Teamcity
else -> None
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.malinskiy.marathon.integrations.ci

object None: CI {
override fun setBuildProgress(int: Int) = Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.malinskiy.marathon.integrations.ci

object Teamcity: CI {
private fun setBuildMessage(message: String) = println("##teamcity[buildStatus text='$message']")

private fun setKeyValue(key: String, value: String) = println("##teamcity[buildStatisticValue key='$key' value='$value']")

override fun setBuildProgress(int: Int) = setBuildMessage("Marathon run: $int %")
}
Loading