Repository navigation
ci(replay): Test Session Replay against Compose UI versions from a checked-in file #6638
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
Merged
+197
−23
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a4cfc11
ci(replay): Test Session Replay against the latest Compose UI version…
sentry-junior[bot] 320b506
ci(replay): Open an issue when the scheduled Compose UI matrix fails
sentry-junior[bot] 1e2c1ac
ci(replay): Read the Compose UI matrix versions from a checked-in file
sentry-junior[bot] b567302
ci(replay): Register a test task per Compose UI version with a depend…
sentry-junior[bot] 6aeae18
ci(replay): Explain the afterEvaluate and note AGP test suites in the…
sentry-junior[bot] 2074abb
ci(replay): Test Session Replay on Compose UI 1.8.3, the oldest version
sentry-junior[bot] 380fe3e
Merge remote-tracking branch 'origin/main' into ci/compose-ui-matrix
sentry-junior[bot] 01a7f40
ci(replay): Configure the matrix variants through the AGP variant API
sentry-junior[bot] 5cc5041
ci(replay): Make the dependency matrix plugin Android-only
sentry-junior[bot] 8bb6ff7
ci(replay): Run every Compose UI version in one Gradle invocation
sentry-junior[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: Compose UI Matrix | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| compose-ui-matrix: | ||
| timeout-minutes: 30 | ||
| runs-on: ubuntu-latest | ||
| name: Compose UI Matrix | ||
|
|
||
| steps: | ||
| - name: Checkout Repo | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Setup Java Version | ||
| uses: actions/setup-java@77dd5b2ce225ea11469928ac317850245a74ae78 # v6.2.0 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| - name: Setup Gradle | ||
| uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 | ||
|
|
||
| # Runs every version in gradle/compose-ui-versions.json; --continue reports each failing one. | ||
| - name: Run Session Replay unit tests | ||
| run: ./gradlew :sentry-android-replay:composeUiTest --continue | ||
|
|
||
| - name: Upload test results | ||
| if: always() | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 | ||
| with: | ||
| name: test-results-compose-ui | ||
| path: | | ||
| sentry-android-replay/build/reports/* | ||
| sentry-android-replay/build/test-results/**/*.xml | ||
|
|
||
| - name: Test Report | ||
| uses: phoenix-actions/test-reporting@7317eea6e13c47348dd0bb318669485157c518d6 # pin@v16 | ||
| if: always() | ||
| with: | ||
| name: JUnit Compose UI | ||
| path: | | ||
| sentry-android-replay/build/test-results/**/*.xml | ||
| reporter: java-junit | ||
| output-to: step-summary | ||
| fail-on-error: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package io.sentry.gradle | ||
|
|
||
| import com.android.build.api.variant.HasHostTests | ||
| import com.android.build.api.variant.HasHostTestsBuilder | ||
| import com.android.build.api.variant.HostTestBuilder | ||
| import com.android.build.api.variant.LibraryAndroidComponentsExtension | ||
| import groovy.json.JsonSlurper | ||
| import javax.inject.Inject | ||
| import org.gradle.api.Plugin | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.artifacts.Configuration | ||
| import org.gradle.api.tasks.TaskProvider | ||
| import org.gradle.language.base.plugins.LifecycleBasePlugin | ||
|
|
||
| /** | ||
| * Runs an Android library module's unit tests on each version of a dependency listed in a | ||
| * checked-in JSON file. | ||
| * | ||
| * The module's main code compiles against the version catalog's version, and the tests for each | ||
| * version in the file run with that version, which is how users run our published artifacts on a | ||
| * newer or older version of the dependency. | ||
| */ | ||
| class DependencyMatrixPlugin : Plugin<Project> { | ||
| override fun apply(project: Project) { | ||
| project.extensions.create("dependencyMatrix", DependencyMatrixExtension::class.java) | ||
| } | ||
| } | ||
|
|
||
| abstract class DependencyMatrixExtension @Inject constructor(private val project: Project) { | ||
| /** | ||
| * Registers `<name>Test<version>` for each version in `gradle/<versionsFile>`, a JSON list such | ||
| * as `["1.12.1", "1.13.0-rc01"]`. Each task runs the module's unit tests with every dependency in | ||
| * [groups] at that version. An entry can also be an object such as `{"version": "1.8.3", "pin": | ||
| * {"androidx.compose.material3": "1.3.2"}}`, which also forces each group in `pin` to its | ||
| * version, for test dependencies whose current version needs a newer [groups] version. | ||
| * `<name>Test` runs every version. | ||
| */ | ||
| fun matrix(name: String, groups: List<String>, versionsFile: String) { | ||
| val file = project.layout.settingsDirectory.file("gradle/$versionsFile") | ||
| val entries = | ||
| JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*> | ||
| check(entries.isNotEmpty()) { "gradle/$versionsFile lists no versions" } | ||
| val all = | ||
| project.tasks.register("${name}Test") { | ||
| description = "Runs the unit tests with every version in gradle/$versionsFile." | ||
| group = LifecycleBasePlugin.VERIFICATION_GROUP | ||
| } | ||
| var previous: String? = null | ||
| entries.forEach { entry -> | ||
| val version = if (entry is Map<*, *>) entry["version"] as String else entry as String | ||
| val pin = (entry as? Map<*, *>)?.get("pin") as Map<*, *>? | ||
| val forced = | ||
| groups.associateWith { version } + | ||
| pin.orEmpty().entries.associate { (group, pinned) -> group as String to pinned as String } | ||
| val variant = "$name${suffix(version)}" | ||
| val test = androidUnitTest(variant, forced) | ||
| // One version at a time: each starts its own Robolectric test JVM, and the configuration | ||
| // cache would run them all at once, which ran out of memory with 16 GB. | ||
| previous?.let { before -> | ||
| project.tasks.named { it == test }.configureEach { mustRunAfter(before) } | ||
| } | ||
| previous = test | ||
| val versionTest = | ||
| project.tasks.register("${name}Test${suffix(version)}") { | ||
| description = "Runs the unit tests with ${groups.joinToString()} at $version." | ||
| group = LifecycleBasePlugin.VERIFICATION_GROUP | ||
| dependsOn(test) | ||
| } | ||
| all.configure { dependsOn(versionTest) } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * A build type of [name] based on the test build type, whose unit tests compile and run with the | ||
| * [forced] versions. Android needs a variant per version, because AGP builds the R class and | ||
| * resources the unit tests run with from the variant's dependencies. The tests also compile | ||
| * against the [forced] versions: Kotlin compiler plugins such as the Compose compiler emit calls | ||
| * into the library's runtime that older versions don't have. | ||
| * | ||
| * Revisit this once the modules can use AGP test suites: a test suite per version could replace | ||
| * the extra build types. | ||
| */ | ||
| private fun androidUnitTest(name: String, forced: Map<String, String>): String { | ||
| val components = project.extensions.getByType(LibraryAndroidComponentsExtension::class.java) | ||
| components.finalizeDsl { android -> | ||
| val base = android.testBuildType | ||
| android.buildTypes.create(name) { | ||
| initWith(android.buildTypes.getByName(base)) | ||
| matchingFallbacks += base | ||
| } | ||
| } | ||
| // AGP only generates unit tests for the test build type. | ||
| components.beforeVariants(components.selector().withBuildType(name)) { | ||
| (it as HasHostTestsBuilder).hostTests[HostTestBuilder.UNIT_TEST_TYPE]?.enable = true | ||
| } | ||
| components.onVariants(components.selector().withBuildType(name)) { | ||
| val unitTest = (it as HasHostTests).hostTests.getValue(HostTestBuilder.UNIT_TEST_TYPE) | ||
| unitTest.compileConfiguration.force(forced) | ||
| unitTest.runtimeConfiguration.force(forced) | ||
| } | ||
| val unitTest = "test${name.replaceFirstChar(Char::uppercase)}UnitTest" | ||
| // Keeps them out of `test` and `check`, which run the test build type's unit tests only, like | ||
| // without a matrix. AGP creates `test` and makes it depend on every variant's unit tests after | ||
| // the build script runs, so the dependency can only be removed in afterEvaluate. | ||
| project.afterEvaluate { | ||
| project.tasks.named("test") { | ||
| setDependsOn(dependsOn.filterNot { it is TaskProvider<*> && it.name == unitTest }) | ||
| } | ||
| } | ||
| return unitTest | ||
| } | ||
|
|
||
| private fun Configuration.force(versions: Map<String, String>) { | ||
| resolutionStrategy.eachDependency { versions[requested.group]?.let { useVersion(it) } } | ||
| } | ||
|
|
||
| private fun suffix(version: String) = version.replace('.', '_').replace('-', '_') | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| [ | ||
| { "version": "1.8.3", "pin": { "androidx.compose.material3": "1.3.2" } }, | ||
| "1.12.1", | ||
| "1.13.0-rc01" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.