Skip to content

Commit e1f8393

Browse files
sentry-junior[bot]romtsnrunningcode
authored
ci(replay): Test Session Replay against Compose UI versions from a checked-in file (#6638)
* ci(replay): Test Session Replay against the latest Compose UI versions from Google Maven Replace the hardcoded composeUi112/composeUi113 build types with a Compose UI matrix workflow. Like the AGP matrix in sentry-android-gradle-plugin, a Kotlin script reads androidx.compose.ui:ui's maven-metadata.xml and picks the latest stable and, when newer, the latest pre-release. Each matrix job runs the replay unit tests with VERSION_COMPOSE_UI forcing that version on the test runtime classpath. The workflow also runs daily, so new Compose releases are tested without a version bump PR. Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> * ci(replay): Open an issue when the scheduled Compose UI matrix fails GitHub only notifies the workflow's creator about scheduled runs, which is the bot that pushed it, so a failing daily run would go unnoticed. On a scheduled failure, open an issue, or comment on the open one so repeated failures stay in one place. Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> * ci(replay): Read the Compose UI matrix versions from a checked-in file Like the Spring Boot matrix, keep the Compose UI versions in gradle/compose-ui-versions.json instead of looking them up on Google Maven on every run, so the same commit always tests the same versions. Drop the daily schedule and its failure issue, which only made sense with the live lookup. Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> * ci(replay): Register a test task per Compose UI version with a dependency matrix plugin Adds io.sentry.dependency-matrix, which reads a versions file in gradle/ and registers <name>Test<version> tasks. Android modules get a build type per version, kept out of check; JVM modules reuse the compiled tests on a versioned runtime classpath. The workflow reads the file with jq inline, like the Spring Boot matrix workflows. Co-Authored-By: roman <roman.zavarnitsyn@sentry.io> Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * ci(replay): Explain the afterEvaluate and note AGP test suites in the dependency matrix plugin * ci(replay): Test Session Replay on Compose UI 1.8.3, the oldest version Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> * ci(replay): Configure the matrix variants through the AGP variant API Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * ci(replay): Make the dependency matrix plugin Android-only Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> * ci(replay): Run every Compose UI version in one Gradle invocation Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io> Co-authored-by: Nelson Osacky <nelson.osacky@sentry.io>
1 parent 9c26cdd commit e1f8393

5 files changed

Lines changed: 197 additions & 23 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Compose UI Matrix
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
compose-ui-matrix:
15+
timeout-minutes: 30
16+
runs-on: ubuntu-latest
17+
name: Compose UI Matrix
18+
19+
steps:
20+
- name: Checkout Repo
21+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
22+
23+
- name: Setup Java Version
24+
uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0
25+
with:
26+
distribution: 'temurin'
27+
java-version: '21'
28+
29+
- name: Setup Gradle
30+
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
31+
32+
# Runs every version in gradle/compose-ui-versions.json; --continue reports each failing one.
33+
- name: Run Session Replay unit tests
34+
run: ./gradlew :sentry-android-replay:composeUiTest --continue
35+
36+
- name: Upload test results
37+
if: always()
38+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
39+
with:
40+
name: test-results-compose-ui
41+
path: |
42+
sentry-android-replay/build/reports/*
43+
sentry-android-replay/build/test-results/**/*.xml
44+
45+
- name: Test Report
46+
uses: phoenix-actions/test-reporting@7317eea6e13c47348dd0bb318669485157c518d6 # pin@v16
47+
if: always()
48+
with:
49+
name: JUnit Compose UI
50+
path: |
51+
sentry-android-replay/build/test-results/**/*.xml
52+
reporter: java-junit
53+
output-to: step-summary
54+
fail-on-error: false

‎build-logic/build.gradle.kts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ gradlePlugin {
5050
id = "io.sentry.spring-boot-matrix"
5151
implementationClass = "io.sentry.gradle.SpringBootMatrixPlugin"
5252
}
53+
register("sentryDependencyMatrix") {
54+
id = "io.sentry.dependency-matrix"
55+
implementationClass = "io.sentry.gradle.DependencyMatrixPlugin"
56+
}
5357
register("sentryOtelAgentTests") {
5458
id = "io.sentry.otel-agent-tests"
5559
implementationClass = "io.sentry.gradle.OtelAgentTestsPlugin"
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package io.sentry.gradle
2+
3+
import com.android.build.api.variant.HasHostTests
4+
import com.android.build.api.variant.HasHostTestsBuilder
5+
import com.android.build.api.variant.HostTestBuilder
6+
import com.android.build.api.variant.LibraryAndroidComponentsExtension
7+
import groovy.json.JsonSlurper
8+
import javax.inject.Inject
9+
import org.gradle.api.Plugin
10+
import org.gradle.api.Project
11+
import org.gradle.api.artifacts.Configuration
12+
import org.gradle.api.tasks.TaskProvider
13+
import org.gradle.language.base.plugins.LifecycleBasePlugin
14+
15+
/**
16+
* Runs an Android library module's unit tests on each version of a dependency listed in a
17+
* checked-in JSON file.
18+
*
19+
* The module's main code compiles against the version catalog's version, and the tests for each
20+
* version in the file run with that version, which is how users run our published artifacts on a
21+
* newer or older version of the dependency.
22+
*/
23+
class DependencyMatrixPlugin : Plugin<Project> {
24+
override fun apply(project: Project) {
25+
project.extensions.create("dependencyMatrix", DependencyMatrixExtension::class.java)
26+
}
27+
}
28+
29+
abstract class DependencyMatrixExtension @Inject constructor(private val project: Project) {
30+
/**
31+
* Registers `<name>Test<version>` for each version in `gradle/<versionsFile>`, a JSON list such
32+
* as `["1.12.1", "1.13.0-rc01"]`. Each task runs the module's unit tests with every dependency in
33+
* [groups] at that version. An entry can also be an object such as `{"version": "1.8.3", "pin":
34+
* {"androidx.compose.material3": "1.3.2"}}`, which also forces each group in `pin` to its
35+
* version, for test dependencies whose current version needs a newer [groups] version.
36+
* `<name>Test` runs every version.
37+
*/
38+
fun matrix(name: String, groups: List<String>, versionsFile: String) {
39+
val file = project.layout.settingsDirectory.file("gradle/$versionsFile")
40+
val entries =
41+
JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*>
42+
check(entries.isNotEmpty()) { "gradle/$versionsFile lists no versions" }
43+
val all =
44+
project.tasks.register("${name}Test") {
45+
description = "Runs the unit tests with every version in gradle/$versionsFile."
46+
group = LifecycleBasePlugin.VERIFICATION_GROUP
47+
}
48+
var previous: String? = null
49+
entries.forEach { entry ->
50+
val version = if (entry is Map<*, *>) entry["version"] as String else entry as String
51+
val pin = (entry as? Map<*, *>)?.get("pin") as Map<*, *>?
52+
val forced =
53+
groups.associateWith { version } +
54+
pin.orEmpty().entries.associate { (group, pinned) -> group as String to pinned as String }
55+
val variant = "$name${suffix(version)}"
56+
val test = androidUnitTest(variant, forced)
57+
// One version at a time: each starts its own Robolectric test JVM, and the configuration
58+
// cache would run them all at once, which ran out of memory with 16 GB.
59+
previous?.let { before ->
60+
project.tasks.named { it == test }.configureEach { mustRunAfter(before) }
61+
}
62+
previous = test
63+
val versionTest =
64+
project.tasks.register("${name}Test${suffix(version)}") {
65+
description = "Runs the unit tests with ${groups.joinToString()} at $version."
66+
group = LifecycleBasePlugin.VERIFICATION_GROUP
67+
dependsOn(test)
68+
}
69+
all.configure { dependsOn(versionTest) }
70+
}
71+
}
72+
73+
/**
74+
* A build type of [name] based on the test build type, whose unit tests compile and run with the
75+
* [forced] versions. Android needs a variant per version, because AGP builds the R class and
76+
* resources the unit tests run with from the variant's dependencies. The tests also compile
77+
* against the [forced] versions: Kotlin compiler plugins such as the Compose compiler emit calls
78+
* into the library's runtime that older versions don't have.
79+
*
80+
* Revisit this once the modules can use AGP test suites: a test suite per version could replace
81+
* the extra build types.
82+
*/
83+
private fun androidUnitTest(name: String, forced: Map<String, String>): String {
84+
val components = project.extensions.getByType(LibraryAndroidComponentsExtension::class.java)
85+
components.finalizeDsl { android ->
86+
val base = android.testBuildType
87+
android.buildTypes.create(name) {
88+
initWith(android.buildTypes.getByName(base))
89+
matchingFallbacks += base
90+
}
91+
}
92+
// AGP only generates unit tests for the test build type.
93+
components.beforeVariants(components.selector().withBuildType(name)) {
94+
(it as HasHostTestsBuilder).hostTests[HostTestBuilder.UNIT_TEST_TYPE]?.enable = true
95+
}
96+
components.onVariants(components.selector().withBuildType(name)) {
97+
val unitTest = (it as HasHostTests).hostTests.getValue(HostTestBuilder.UNIT_TEST_TYPE)
98+
unitTest.compileConfiguration.force(forced)
99+
unitTest.runtimeConfiguration.force(forced)
100+
}
101+
val unitTest = "test${name.replaceFirstChar(Char::uppercase)}UnitTest"
102+
// Keeps them out of `test` and `check`, which run the test build type's unit tests only, like
103+
// without a matrix. AGP creates `test` and makes it depend on every variant's unit tests after
104+
// the build script runs, so the dependency can only be removed in afterEvaluate.
105+
project.afterEvaluate {
106+
project.tasks.named("test") {
107+
setDependsOn(dependsOn.filterNot { it is TaskProvider<*> && it.name == unitTest })
108+
}
109+
}
110+
return unitTest
111+
}
112+
113+
private fun Configuration.force(versions: Map<String, String>) {
114+
resolutionStrategy.eachDependency { versions[requested.group]?.let { useVersion(it) } }
115+
}
116+
117+
private fun suffix(version: String) = version.replace('.', '_').replace('-', '_')
118+
}

‎gradle/compose-ui-versions.json‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
{ "version": "1.8.3", "pin": { "androidx.compose.material3": "1.3.2" } },
3+
"1.12.1",
4+
"1.13.0-rc01"
5+
]

‎sentry-android-replay/build.gradle.kts‎

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import com.android.build.api.variant.HasHostTestsBuilder
2-
import com.android.build.api.variant.HostTestBuilder
31
import io.gitlab.arturbosch.detekt.Detekt
42
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
53
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
@@ -16,12 +14,9 @@ plugins {
1614
id("io.sentry.publish")
1715
id("io.sentry.api-validation")
1816
id("io.sentry.robolectric")
17+
id("io.sentry.dependency-matrix")
1918
}
2019

21-
// Session Replay calls Compose internals, whose mangled JVM names change between Compose versions.
22-
// Creating extra build types to run tests against the latest stable, and latest preview version.
23-
val composeUiTestVersions = mapOf("composeUi112" to "1.12.1", "composeUi113" to "1.13.0-rc01")
24-
2520
android {
2621
compileSdk = libs.versions.compileSdk.get().toInt()
2722
compileSdkMinor = libs.versions.compileSdkMinor.get().toInt()
@@ -43,12 +38,6 @@ android {
4338
buildTypes {
4439
getByName("debug") { consumerProguardFiles("proguard-rules.pro") }
4540
getByName("release") { consumerProguardFiles("proguard-rules.pro") }
46-
composeUiTestVersions.keys.forEach { name ->
47-
create(name) {
48-
initWith(getByName("release"))
49-
matchingFallbacks += "release"
50-
}
51-
}
5241
}
5342

5443
// AGP 9 only generates unit tests for the testBuildType. The debug variant is
@@ -85,9 +74,6 @@ android {
8574

8675
androidComponents.beforeVariants {
8776
it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType)
88-
if (it.buildType in composeUiTestVersions) {
89-
(it as HasHostTestsBuilder).hostTests[HostTestBuilder.UNIT_TEST_TYPE]?.enable = true
90-
}
9177
}
9278
}
9379

@@ -117,14 +103,21 @@ dependencies {
117103
testImplementation(libs.coil.compose)
118104
}
119105

120-
composeUiTestVersions.forEach { (buildType, version) ->
121-
configurations
122-
.matching { it.name == "${buildType}UnitTestRuntimeClasspath" }
123-
.configureEach {
124-
resolutionStrategy.eachDependency {
125-
if (requested.group == "androidx.compose.ui") useVersion(version)
126-
}
127-
}
106+
// Session Replay calls Compose internals, whose mangled JVM names change between Compose versions.
107+
// .github/workflows/compose-ui-matrix.yml runs each version's task. The oldest entry pins material3
108+
// to a version that runs on that Compose UI, because the catalog's material3 needs a newer one.
109+
dependencyMatrix {
110+
matrix(
111+
name = "composeUi",
112+
groups =
113+
listOf(
114+
"androidx.compose.ui",
115+
"androidx.compose.foundation",
116+
"androidx.compose.animation",
117+
"androidx.compose.runtime",
118+
),
119+
versionsFile = "compose-ui-versions.json",
120+
)
128121
}
129122

130123
tasks.withType<Detekt>().configureEach {

0 commit comments

Comments
 (0)