From a4cfc11b8d788c0d3c2ac60dde784f4cd4081c3b Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 10:50:33 +0000 Subject: [PATCH 1/9] 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 --- .github/workflows/compose-ui-matrix.yml | 80 +++++++++++++++++++++++++ scripts/compose-ui-versions.main.kts | 31 ++++++++++ sentry-android-replay/build.gradle.kts | 22 ++----- 3 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/compose-ui-matrix.yml create mode 100644 scripts/compose-ui-versions.main.kts diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml new file mode 100644 index 0000000000..b112c632f3 --- /dev/null +++ b/.github/workflows/compose-ui-matrix.yml @@ -0,0 +1,80 @@ +name: Compose UI Matrix + +on: + # Daily, to catch new Compose releases that break Session Replay without waiting for a PR. + schedule: + - cron: '0 4 * * *' + push: + branches: + - main + pull_request: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + versions: + runs-on: ubuntu-latest + name: Compose UI versions + outputs: + versions: ${{ steps.versions.outputs.versions }} + + steps: + - name: Checkout Repo + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + sparse-checkout: scripts + + - name: Read latest Compose UI versions from Google Maven + id: versions + run: kotlin scripts/compose-ui-versions.main.kts + + compose-ui-matrix: + needs: versions + timeout-minutes: 30 + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + compose-ui: ${{ fromJSON(needs.versions.outputs.versions) }} + + name: Compose UI ${{ matrix.compose-ui }} + env: + VERSION_COMPOSE_UI: ${{ matrix.compose-ui }} + + 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 + + - name: Run Session Replay unit tests + run: ./gradlew :sentry-android-replay:testReleaseUnitTest + + - name: Upload test results + if: always() + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 + with: + name: test-results-compose-ui-${{ matrix.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 ${{ matrix.compose-ui }} + path: | + sentry-android-replay/build/test-results/**/*.xml + reporter: java-junit + output-to: step-summary + fail-on-error: false diff --git a/scripts/compose-ui-versions.main.kts b/scripts/compose-ui-versions.main.kts new file mode 100644 index 0000000000..a50ba83168 --- /dev/null +++ b/scripts/compose-ui-versions.main.kts @@ -0,0 +1,31 @@ +#!/usr/bin/env kotlin +@file:DependsOn("io.github.z4kn4fein:semver-jvm:3.1.0") + +// Prints the androidx.compose.ui versions that the Compose UI matrix workflow runs the +// sentry-android-replay unit tests against: the latest stable, plus the latest pre-release when +// it is newer. Same approach as the AGP matrix in getsentry/sentry-android-gradle-plugin. + +import io.github.z4kn4fein.semver.Version +import java.io.File +import javax.xml.parsers.DocumentBuilderFactory + +val metadataUrl = + "https://dl.google.com/dl/android/maven2/androidx/compose/ui/ui/maven-metadata.xml" + +val document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(metadataUrl) +val versionNodes = document.documentElement.getElementsByTagName("version") +val versions = + (0 until versionNodes.length).map { Version.parse(versionNodes.item(it).textContent, strict = false) } + +val latestStable = versions.filter { it.isStable }.max() +val latestPreRelease = versions.filter { it.isPreRelease }.max() + +val matrix = buildList { + add(latestStable) + if (latestPreRelease > latestStable) add(latestPreRelease) +} +val json = matrix.joinToString(separator = ",", prefix = "[", postfix = "]") { "\"$it\"" } + +println(json) +val githubOutput = System.getenv("GITHUB_OUTPUT") +if (githubOutput != null) File(githubOutput).appendText("versions=$json\n") diff --git a/sentry-android-replay/build.gradle.kts b/sentry-android-replay/build.gradle.kts index d0d101d190..684c76b437 100644 --- a/sentry-android-replay/build.gradle.kts +++ b/sentry-android-replay/build.gradle.kts @@ -1,5 +1,3 @@ -import com.android.build.api.variant.HasHostTestsBuilder -import com.android.build.api.variant.HostTestBuilder import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion @@ -18,10 +16,6 @@ plugins { id("io.sentry.robolectric") } -// Session Replay calls Compose internals, whose mangled JVM names change between Compose versions. -// Creating extra build types to run tests against the latest stable, and latest preview version. -val composeUiTestVersions = mapOf("composeUi112" to "1.12.1", "composeUi113" to "1.13.0-rc01") - android { compileSdk = libs.versions.compileSdk.get().toInt() compileSdkMinor = libs.versions.compileSdkMinor.get().toInt() @@ -43,12 +37,6 @@ android { buildTypes { getByName("debug") { consumerProguardFiles("proguard-rules.pro") } getByName("release") { consumerProguardFiles("proguard-rules.pro") } - composeUiTestVersions.keys.forEach { name -> - create(name) { - initWith(getByName("release")) - matchingFallbacks += "release" - } - } } // AGP 9 only generates unit tests for the testBuildType. The debug variant is @@ -85,9 +73,6 @@ android { androidComponents.beforeVariants { it.enable = !Config.Android.shouldSkipDebugVariant(it.buildType) - if (it.buildType in composeUiTestVersions) { - (it as HasHostTestsBuilder).hostTests[HostTestBuilder.UNIT_TEST_TYPE]?.enable = true - } } } @@ -117,9 +102,12 @@ dependencies { testImplementation(libs.coil.compose) } -composeUiTestVersions.forEach { (buildType, version) -> +// Session Replay calls Compose internals, whose mangled JVM names change between Compose versions. +// .github/workflows/compose-ui-matrix.yml sets VERSION_COMPOSE_UI to run the unit tests against the +// latest stable and pre-release versions from Google Maven. +System.getenv("VERSION_COMPOSE_UI")?.let { version -> configurations - .matching { it.name == "${buildType}UnitTestRuntimeClasspath" } + .matching { it.name == "releaseUnitTestRuntimeClasspath" } .configureEach { resolutionStrategy.eachDependency { if (requested.group == "androidx.compose.ui") useVersion(version) From 320b506701840f7a6f2c760338fe432fb2195cc1 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 11:32:37 +0000 Subject: [PATCH 2/9] 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 --- .github/workflows/compose-ui-matrix.yml | 21 +++++++++++++++++++++ scripts/report-compose-ui-matrix-failure.sh | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100755 scripts/report-compose-ui-matrix-failure.sh diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml index b112c632f3..54cd63e989 100644 --- a/.github/workflows/compose-ui-matrix.yml +++ b/.github/workflows/compose-ui-matrix.yml @@ -78,3 +78,24 @@ jobs: reporter: java-junit output-to: step-summary fail-on-error: false + + report-failure: + needs: [versions, compose-ui-matrix] + # Nobody gets GitHub's notifications for scheduled runs, so open an issue instead. + if: failure() && github.event_name == 'schedule' + runs-on: ubuntu-latest + name: Report scheduled failure + permissions: + contents: read + issues: write + + steps: + - name: Checkout Repo + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + sparse-checkout: scripts + + - name: Open or update the failure issue + run: ./scripts/report-compose-ui-matrix-failure.sh + env: + GH_TOKEN: ${{ github.token }} diff --git a/scripts/report-compose-ui-matrix-failure.sh b/scripts/report-compose-ui-matrix-failure.sh new file mode 100755 index 0000000000..244faac2d1 --- /dev/null +++ b/scripts/report-compose-ui-matrix-failure.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# Reports a failed scheduled Compose UI matrix run: opens an issue, or comments on the open one so +# repeated daily failures stay in one place. Needs GH_TOKEN, GITHUB_REPOSITORY, GITHUB_SERVER_URL, +# and GITHUB_RUN_ID, which GitHub Actions sets. +set -eu + +ISSUE_TITLE='Session Replay: Compose UI matrix fails on the latest Compose UI versions' +export ISSUE_TITLE +run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" +body="The scheduled [Compose UI matrix run]($run_url) failed. A new \`androidx.compose.ui:ui\` release may have changed Compose internals that Session Replay calls. Check the failing jobs for the version." + +# --search is fuzzy, so match the exact title afterwards. +existing=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "$ISSUE_TITLE in:title" \ + --json number,title --jq '[.[] | select(.title == env.ISSUE_TITLE)][0].number // empty') + +if [ -n "$existing" ]; then + gh issue comment "$existing" --repo "$GITHUB_REPOSITORY" --body "$body" +else + gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" --body "$body" \ + --label 'Session Replay' --label 'Jetpack Compose' +fi From 1e2c1acc6d97bd15c1ecea06d023c3948e5b1d1d Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 16:08:44 +0000 Subject: [PATCH 3/9] 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 --- .github/workflows/compose-ui-matrix.yml | 32 ++++----------------- gradle/compose-ui-versions.json | 1 + scripts/compose-ui-versions.main.kts | 31 -------------------- scripts/read-compose-ui-versions.sh | 8 ++++++ scripts/report-compose-ui-matrix-failure.sh | 21 -------------- sentry-android-replay/build.gradle.kts | 2 +- 6 files changed, 15 insertions(+), 80 deletions(-) create mode 100644 gradle/compose-ui-versions.json delete mode 100644 scripts/compose-ui-versions.main.kts create mode 100755 scripts/read-compose-ui-versions.sh delete mode 100755 scripts/report-compose-ui-matrix-failure.sh diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml index 54cd63e989..f8f871ed65 100644 --- a/.github/workflows/compose-ui-matrix.yml +++ b/.github/workflows/compose-ui-matrix.yml @@ -1,9 +1,6 @@ name: Compose UI Matrix on: - # Daily, to catch new Compose releases that break Session Replay without waiting for a PR. - schedule: - - cron: '0 4 * * *' push: branches: - main @@ -24,11 +21,13 @@ jobs: - name: Checkout Repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - sparse-checkout: scripts + sparse-checkout: | + gradle + scripts - - name: Read latest Compose UI versions from Google Maven + - name: Read Compose UI versions id: versions - run: kotlin scripts/compose-ui-versions.main.kts + run: ./scripts/read-compose-ui-versions.sh compose-ui-matrix: needs: versions @@ -78,24 +77,3 @@ jobs: reporter: java-junit output-to: step-summary fail-on-error: false - - report-failure: - needs: [versions, compose-ui-matrix] - # Nobody gets GitHub's notifications for scheduled runs, so open an issue instead. - if: failure() && github.event_name == 'schedule' - runs-on: ubuntu-latest - name: Report scheduled failure - permissions: - contents: read - issues: write - - steps: - - name: Checkout Repo - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - sparse-checkout: scripts - - - name: Open or update the failure issue - run: ./scripts/report-compose-ui-matrix-failure.sh - env: - GH_TOKEN: ${{ github.token }} diff --git a/gradle/compose-ui-versions.json b/gradle/compose-ui-versions.json new file mode 100644 index 0000000000..a3e9fc5745 --- /dev/null +++ b/gradle/compose-ui-versions.json @@ -0,0 +1 @@ +["1.12.1", "1.13.0-rc01"] diff --git a/scripts/compose-ui-versions.main.kts b/scripts/compose-ui-versions.main.kts deleted file mode 100644 index a50ba83168..0000000000 --- a/scripts/compose-ui-versions.main.kts +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env kotlin -@file:DependsOn("io.github.z4kn4fein:semver-jvm:3.1.0") - -// Prints the androidx.compose.ui versions that the Compose UI matrix workflow runs the -// sentry-android-replay unit tests against: the latest stable, plus the latest pre-release when -// it is newer. Same approach as the AGP matrix in getsentry/sentry-android-gradle-plugin. - -import io.github.z4kn4fein.semver.Version -import java.io.File -import javax.xml.parsers.DocumentBuilderFactory - -val metadataUrl = - "https://dl.google.com/dl/android/maven2/androidx/compose/ui/ui/maven-metadata.xml" - -val document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(metadataUrl) -val versionNodes = document.documentElement.getElementsByTagName("version") -val versions = - (0 until versionNodes.length).map { Version.parse(versionNodes.item(it).textContent, strict = false) } - -val latestStable = versions.filter { it.isStable }.max() -val latestPreRelease = versions.filter { it.isPreRelease }.max() - -val matrix = buildList { - add(latestStable) - if (latestPreRelease > latestStable) add(latestPreRelease) -} -val json = matrix.joinToString(separator = ",", prefix = "[", postfix = "]") { "\"$it\"" } - -println(json) -val githubOutput = System.getenv("GITHUB_OUTPUT") -if (githubOutput != null) File(githubOutput).appendText("versions=$json\n") diff --git a/scripts/read-compose-ui-versions.sh b/scripts/read-compose-ui-versions.sh new file mode 100755 index 0000000000..6e20e9e01f --- /dev/null +++ b/scripts/read-compose-ui-versions.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# Writes the Compose UI versions from gradle/compose-ui-versions.json to the step's outputs, as a +# JSON list for the Compose UI matrix. +set -eu + +versions=$(jq -c -e 'if type == "array" and length > 0 then . else error("expected a non-empty list") end' \ + gradle/compose-ui-versions.json) +printf 'versions=%s\n' "$versions" >> "$GITHUB_OUTPUT" diff --git a/scripts/report-compose-ui-matrix-failure.sh b/scripts/report-compose-ui-matrix-failure.sh deleted file mode 100755 index 244faac2d1..0000000000 --- a/scripts/report-compose-ui-matrix-failure.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -# Reports a failed scheduled Compose UI matrix run: opens an issue, or comments on the open one so -# repeated daily failures stay in one place. Needs GH_TOKEN, GITHUB_REPOSITORY, GITHUB_SERVER_URL, -# and GITHUB_RUN_ID, which GitHub Actions sets. -set -eu - -ISSUE_TITLE='Session Replay: Compose UI matrix fails on the latest Compose UI versions' -export ISSUE_TITLE -run_url="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" -body="The scheduled [Compose UI matrix run]($run_url) failed. A new \`androidx.compose.ui:ui\` release may have changed Compose internals that Session Replay calls. Check the failing jobs for the version." - -# --search is fuzzy, so match the exact title afterwards. -existing=$(gh issue list --repo "$GITHUB_REPOSITORY" --state open --search "$ISSUE_TITLE in:title" \ - --json number,title --jq '[.[] | select(.title == env.ISSUE_TITLE)][0].number // empty') - -if [ -n "$existing" ]; then - gh issue comment "$existing" --repo "$GITHUB_REPOSITORY" --body "$body" -else - gh issue create --repo "$GITHUB_REPOSITORY" --title "$ISSUE_TITLE" --body "$body" \ - --label 'Session Replay' --label 'Jetpack Compose' -fi diff --git a/sentry-android-replay/build.gradle.kts b/sentry-android-replay/build.gradle.kts index 684c76b437..a6a82bdebd 100644 --- a/sentry-android-replay/build.gradle.kts +++ b/sentry-android-replay/build.gradle.kts @@ -104,7 +104,7 @@ dependencies { // Session Replay calls Compose internals, whose mangled JVM names change between Compose versions. // .github/workflows/compose-ui-matrix.yml sets VERSION_COMPOSE_UI to run the unit tests against the -// latest stable and pre-release versions from Google Maven. +// versions in gradle/compose-ui-versions.json. System.getenv("VERSION_COMPOSE_UI")?.let { version -> configurations .matching { it.name == "releaseUnitTestRuntimeClasspath" } From b567302a088e2c9b25cc45d0cbd838d7689a8e7a Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 21:47:34 +0000 Subject: [PATCH 4/9] 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 Test 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 Co-Authored-By: Nelson Osacky --- .github/workflows/compose-ui-matrix.yml | 10 +- build-logic/build.gradle.kts | 4 + .../sentry/gradle/DependencyMatrixPlugin.kt | 123 ++++++++++++++++++ scripts/read-compose-ui-versions.sh | 8 -- sentry-android-replay/build.gradle.kts | 18 ++- 5 files changed, 139 insertions(+), 24 deletions(-) create mode 100644 build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt delete mode 100755 scripts/read-compose-ui-versions.sh diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml index f8f871ed65..78c42cd24f 100644 --- a/.github/workflows/compose-ui-matrix.yml +++ b/.github/workflows/compose-ui-matrix.yml @@ -21,13 +21,11 @@ jobs: - name: Checkout Repo uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: - sparse-checkout: | - gradle - scripts + sparse-checkout: gradle - name: Read Compose UI versions id: versions - run: ./scripts/read-compose-ui-versions.sh + run: echo "versions=$(jq -c . gradle/compose-ui-versions.json)" >> "$GITHUB_OUTPUT" compose-ui-matrix: needs: versions @@ -40,7 +38,7 @@ jobs: name: Compose UI ${{ matrix.compose-ui }} env: - VERSION_COMPOSE_UI: ${{ matrix.compose-ui }} + COMPOSE_UI_VERSION: ${{ matrix.compose-ui }} steps: - name: Checkout Repo @@ -56,7 +54,7 @@ jobs: uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 - name: Run Session Replay unit tests - run: ./gradlew :sentry-android-replay:testReleaseUnitTest + run: ./gradlew ":sentry-android-replay:composeUiTest${COMPOSE_UI_VERSION//[.-]/_}" - name: Upload test results if: always() diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index db40bf7443..532537feb1 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -50,6 +50,10 @@ gradlePlugin { id = "io.sentry.spring-boot-matrix" implementationClass = "io.sentry.gradle.SpringBootMatrixPlugin" } + register("sentryDependencyMatrix") { + id = "io.sentry.dependency-matrix" + implementationClass = "io.sentry.gradle.DependencyMatrixPlugin" + } register("sentryOtelAgentTests") { id = "io.sentry.otel-agent-tests" implementationClass = "io.sentry.gradle.OtelAgentTestsPlugin" diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt new file mode 100644 index 0000000000..321df80348 --- /dev/null +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -0,0 +1,123 @@ +package io.sentry.gradle + +import com.android.build.api.dsl.LibraryExtension +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.SourceSetContainer +import org.gradle.api.tasks.TaskProvider +import org.gradle.api.tasks.testing.Test +import org.gradle.language.base.plugins.LifecycleBasePlugin + +/** + * Runs a module's unit tests on each version of a dependency listed in a checked-in JSON file, for + * Android library and JVM modules. + * + * The module compiles against the version catalog's version, and the tests for each version in the + * file run with that version on their runtime classpath, which is how users run our published + * artifacts on a newer or older version of the dependency. + */ +class DependencyMatrixPlugin : Plugin { + override fun apply(project: Project) { + project.extensions.create("dependencyMatrix", DependencyMatrixExtension::class.java) + } +} + +abstract class DependencyMatrixExtension @Inject constructor(private val project: Project) { + /** + * Registers `Test` for each version in `gradle/`, a JSON list such + * as `["1.12.1", "1.13.0-rc01"]`. Each task runs the module's unit tests with every dependency in + * [group] at that version. A CI workflow reads the same file and runs each version in its own + * job. In an Android module, call it after `android {}`. + */ + fun matrix(name: String, group: String, versionsFile: String) { + val file = project.layout.settingsDirectory.file("gradle/$versionsFile") + val versions = + (JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*>).map { + it as String + } + check(versions.isNotEmpty()) { "gradle/$versionsFile lists no versions" } + val android = project.plugins.hasPlugin("com.android.library") + versions.forEach { version -> + val variant = "$name${suffix(version)}" + val test = if (android) androidUnitTest(variant) else jvmTest(variant) + project.configurations + .matching { it.name == runtimeClasspathName(variant, android) } + .configureEach { forceGroup(group, version) } + project.tasks.register("${name}Test${suffix(version)}") { + description = "Runs the unit tests with $group at $version." + this.group = LifecycleBasePlugin.VERIFICATION_GROUP + dependsOn(test) + } + } + } + + /** + * A build type of [name] based on the test build type, whose unit tests run on their own runtime + * classpath. Android needs a variant per version, because AGP builds the R class and resources + * the unit tests run with from the variant's dependencies. + */ + private fun androidUnitTest(name: String): String { + val android = project.extensions.getByType(LibraryExtension::class.java) + val base = android.testBuildType + android.buildTypes.create(name) { + initWith(android.buildTypes.getByName(base)) + matchingFallbacks += base + } + val components = project.extensions.getByType(LibraryAndroidComponentsExtension::class.java) + // 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 + } + 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 adds the dependency when it creates the variant's tasks, after the + // build script runs. + project.afterEvaluate { + project.tasks.named("test") { + setDependsOn(dependsOn.filterNot { it is TaskProvider<*> && it.name == unitTest }) + } + } + return unitTest + } + + /** + * A test task of [name] that reuses the compiled tests on its own runtime classpath, like + * [SpringBootMatrixPlugin] does. + */ + private fun jvmTest(name: String): TaskProvider { + val sourceSets = project.extensions.getByType(SourceSetContainer::class.java) + val test = sourceSets.getByName("test") + val configurations = project.configurations + val runtimeClasspath = + configurations.resolvable(runtimeClasspathName(name, android = false)) { + extendsFrom( + configurations.getByName(test.implementationConfigurationName), + configurations.getByName(test.runtimeOnlyConfigurationName), + ) + attributes.addAllLater( + configurations.getByName(test.runtimeClasspathConfigurationName).attributes + ) + } + val taskName = "test${name.replaceFirstChar(Char::uppercase)}" + return project.tasks.register(taskName, Test::class.java) { + testClassesDirs = test.output.classesDirs + classpath = test.output + sourceSets.getByName("main").output + runtimeClasspath.get() + useJUnit() + } + } + + private fun runtimeClasspathName(name: String, android: Boolean) = + if (android) "${name}UnitTestRuntimeClasspath" else "${name}TestRuntimeClasspath" + + private fun Configuration.forceGroup(group: String, version: String) { + resolutionStrategy.eachDependency { if (requested.group == group) useVersion(version) } + } + + private fun suffix(version: String) = version.replace('.', '_').replace('-', '_') +} diff --git a/scripts/read-compose-ui-versions.sh b/scripts/read-compose-ui-versions.sh deleted file mode 100755 index 6e20e9e01f..0000000000 --- a/scripts/read-compose-ui-versions.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -# Writes the Compose UI versions from gradle/compose-ui-versions.json to the step's outputs, as a -# JSON list for the Compose UI matrix. -set -eu - -versions=$(jq -c -e 'if type == "array" and length > 0 then . else error("expected a non-empty list") end' \ - gradle/compose-ui-versions.json) -printf 'versions=%s\n' "$versions" >> "$GITHUB_OUTPUT" diff --git a/sentry-android-replay/build.gradle.kts b/sentry-android-replay/build.gradle.kts index a6a82bdebd..d311139d21 100644 --- a/sentry-android-replay/build.gradle.kts +++ b/sentry-android-replay/build.gradle.kts @@ -14,6 +14,7 @@ plugins { id("io.sentry.publish") id("io.sentry.api-validation") id("io.sentry.robolectric") + id("io.sentry.dependency-matrix") } android { @@ -103,16 +104,13 @@ dependencies { } // Session Replay calls Compose internals, whose mangled JVM names change between Compose versions. -// .github/workflows/compose-ui-matrix.yml sets VERSION_COMPOSE_UI to run the unit tests against the -// versions in gradle/compose-ui-versions.json. -System.getenv("VERSION_COMPOSE_UI")?.let { version -> - configurations - .matching { it.name == "releaseUnitTestRuntimeClasspath" } - .configureEach { - resolutionStrategy.eachDependency { - if (requested.group == "androidx.compose.ui") useVersion(version) - } - } +// .github/workflows/compose-ui-matrix.yml runs each version's task. +dependencyMatrix { + matrix( + name = "composeUi", + group = "androidx.compose.ui", + versionsFile = "compose-ui-versions.json", + ) } tasks.withType().configureEach { From 6aeae18104514ec0fb71a8ea9938037330eccaa7 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:08:43 +0000 Subject: [PATCH 5/9] ci(replay): Explain the afterEvaluate and note AGP test suites in the dependency matrix plugin --- .../main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt index 321df80348..ed22d8cf07 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -61,6 +61,9 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project * A build type of [name] based on the test build type, whose unit tests run on their own runtime * classpath. Android needs a variant per version, because AGP builds the R class and resources * the unit tests run with from the variant's dependencies. + * + * 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): String { val android = project.extensions.getByType(LibraryExtension::class.java) @@ -76,8 +79,8 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project } 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 adds the dependency when it creates the variant's tasks, after the - // build script runs. + // 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 }) From 2074abbd93004a247a1c24308f923e9b1edbdac1 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:22:47 +0000 Subject: [PATCH 6/9] ci(replay): Test Session Replay on Compose UI 1.8.3, the oldest version Co-Authored-By: Roman Zavarnitsyn --- .github/workflows/compose-ui-matrix.yml | 2 +- .../sentry/gradle/DependencyMatrixPlugin.kt | 56 ++++++++++++------- gradle/compose-ui-versions.json | 6 +- sentry-android-replay/build.gradle.kts | 11 +++- 4 files changed, 50 insertions(+), 25 deletions(-) diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml index 78c42cd24f..4eac7884a5 100644 --- a/.github/workflows/compose-ui-matrix.yml +++ b/.github/workflows/compose-ui-matrix.yml @@ -25,7 +25,7 @@ jobs: - name: Read Compose UI versions id: versions - run: echo "versions=$(jq -c . gradle/compose-ui-versions.json)" >> "$GITHUB_OUTPUT" + run: echo "versions=$(jq -c 'map(.version? // .)' gradle/compose-ui-versions.json)" >> "$GITHUB_OUTPUT" compose-ui-matrix: needs: versions diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt index ed22d8cf07..87537b4db1 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -18,9 +18,9 @@ import org.gradle.language.base.plugins.LifecycleBasePlugin * Runs a module's unit tests on each version of a dependency listed in a checked-in JSON file, for * Android library and JVM modules. * - * The module compiles against the version catalog's version, and the tests for each version in the - * file run with that version on their runtime classpath, which is how users run our published - * artifacts on a newer or older version of the dependency. + * 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 { override fun apply(project: Project) { @@ -32,35 +32,41 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project /** * Registers `Test` for each version in `gradle/`, a JSON list such * as `["1.12.1", "1.13.0-rc01"]`. Each task runs the module's unit tests with every dependency in - * [group] at that version. A CI workflow reads the same file and runs each version in its own - * job. In an Android module, call it after `android {}`. + * [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. A CI + * workflow reads the same file and runs each version in its own job. In an Android module, call + * it after `android {}`. */ - fun matrix(name: String, group: String, versionsFile: String) { + fun matrix(name: String, groups: List, versionsFile: String) { val file = project.layout.settingsDirectory.file("gradle/$versionsFile") - val versions = - (JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*>).map { - it as String - } - check(versions.isNotEmpty()) { "gradle/$versionsFile lists no versions" } + val entries = + JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*> + check(entries.isNotEmpty()) { "gradle/$versionsFile lists no versions" } val android = project.plugins.hasPlugin("com.android.library") - versions.forEach { version -> + 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 = if (android) androidUnitTest(variant) else jvmTest(variant) project.configurations - .matching { it.name == runtimeClasspathName(variant, android) } - .configureEach { forceGroup(group, version) } + .matching { it.name in testClasspathNames(variant, android) } + .configureEach { force(forced) } project.tasks.register("${name}Test${suffix(version)}") { - description = "Runs the unit tests with $group at $version." - this.group = LifecycleBasePlugin.VERIFICATION_GROUP + description = "Runs the unit tests with ${groups.joinToString()} at $version." + group = LifecycleBasePlugin.VERIFICATION_GROUP dependsOn(test) } } } /** - * A build type of [name] based on the test build type, whose unit tests run on their own runtime - * classpath. Android needs a variant per version, because AGP builds the R class and resources - * the unit tests run with from the variant's dependencies. + * A build type of [name] based on the test build type, whose unit tests compile and run on their + * own classpaths. Android needs a variant per version, because AGP builds the R class and + * resources the unit tests run with from the variant's dependencies. * * Revisit this once the modules can use AGP test suites: a test suite per version could replace * the extra build types. @@ -118,8 +124,16 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project private fun runtimeClasspathName(name: String, android: Boolean) = if (android) "${name}UnitTestRuntimeClasspath" else "${name}TestRuntimeClasspath" - private fun Configuration.forceGroup(group: String, version: String) { - resolutionStrategy.eachDependency { if (requested.group == group) useVersion(version) } + /** + * On Android the tests also compile against the matrix versions: Kotlin compiler plugins such as + * the Compose compiler emit calls into the library's runtime that older versions don't have. + */ + private fun testClasspathNames(name: String, android: Boolean) = + if (android) setOf(runtimeClasspathName(name, android), "${name}UnitTestCompileClasspath") + else setOf(runtimeClasspathName(name, android)) + + private fun Configuration.force(versions: Map) { + resolutionStrategy.eachDependency { versions[requested.group]?.let { useVersion(it) } } } private fun suffix(version: String) = version.replace('.', '_').replace('-', '_') diff --git a/gradle/compose-ui-versions.json b/gradle/compose-ui-versions.json index a3e9fc5745..2f75c2c794 100644 --- a/gradle/compose-ui-versions.json +++ b/gradle/compose-ui-versions.json @@ -1 +1,5 @@ -["1.12.1", "1.13.0-rc01"] +[ + { "version": "1.8.3", "pin": { "androidx.compose.material3": "1.3.2" } }, + "1.12.1", + "1.13.0-rc01" +] diff --git a/sentry-android-replay/build.gradle.kts b/sentry-android-replay/build.gradle.kts index d311139d21..ebc5770544 100644 --- a/sentry-android-replay/build.gradle.kts +++ b/sentry-android-replay/build.gradle.kts @@ -104,11 +104,18 @@ dependencies { } // Session Replay calls Compose internals, whose mangled JVM names change between Compose versions. -// .github/workflows/compose-ui-matrix.yml runs each version's task. +// .github/workflows/compose-ui-matrix.yml runs each version's task. The oldest entry pins material3 +// to a version that runs on that Compose UI, because the catalog's material3 needs a newer one. dependencyMatrix { matrix( name = "composeUi", - group = "androidx.compose.ui", + groups = + listOf( + "androidx.compose.ui", + "androidx.compose.foundation", + "androidx.compose.animation", + "androidx.compose.runtime", + ), versionsFile = "compose-ui-versions.json", ) } From 01a7f4085fe32c29454a606531e1aa7f0dcd400d Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:04:25 +0000 Subject: [PATCH 7/9] ci(replay): Configure the matrix variants through the AGP variant API Co-Authored-By: Nelson Osacky --- .../sentry/gradle/DependencyMatrixPlugin.kt | 58 +++++++++---------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt index 87537b4db1..3e3a22d75f 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -1,6 +1,6 @@ package io.sentry.gradle -import com.android.build.api.dsl.LibraryExtension +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 @@ -35,8 +35,7 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project * [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. A CI - * workflow reads the same file and runs each version in its own job. In an Android module, call - * it after `android {}`. + * workflow reads the same file and runs each version in its own job. */ fun matrix(name: String, groups: List, versionsFile: String) { val file = project.layout.settingsDirectory.file("gradle/$versionsFile") @@ -51,10 +50,7 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project groups.associateWith { version } + pin.orEmpty().entries.associate { (group, pinned) -> group as String to pinned as String } val variant = "$name${suffix(version)}" - val test = if (android) androidUnitTest(variant) else jvmTest(variant) - project.configurations - .matching { it.name in testClasspathNames(variant, android) } - .configureEach { force(forced) } + val test = if (android) androidUnitTest(variant, forced) else jvmTest(variant, forced) project.tasks.register("${name}Test${suffix(version)}") { description = "Runs the unit tests with ${groups.joinToString()} at $version." group = LifecycleBasePlugin.VERIFICATION_GROUP @@ -64,25 +60,33 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project } /** - * A build type of [name] based on the test build type, whose unit tests compile and run on their - * own classpaths. Android needs a variant per version, because AGP builds the R class and - * resources the unit tests run with from the variant's dependencies. + * 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): String { - val android = project.extensions.getByType(LibraryExtension::class.java) - val base = android.testBuildType - android.buildTypes.create(name) { - initWith(android.buildTypes.getByName(base)) - matchingFallbacks += base - } + private fun androidUnitTest(name: String, forced: Map): 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 @@ -96,15 +100,16 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project } /** - * A test task of [name] that reuses the compiled tests on its own runtime classpath, like - * [SpringBootMatrixPlugin] does. + * A test task of [name] that reuses the compiled tests on a runtime classpath with the [forced] + * versions, like [SpringBootMatrixPlugin] does. */ - private fun jvmTest(name: String): TaskProvider { + private fun jvmTest(name: String, forced: Map): TaskProvider { val sourceSets = project.extensions.getByType(SourceSetContainer::class.java) val test = sourceSets.getByName("test") val configurations = project.configurations val runtimeClasspath = - configurations.resolvable(runtimeClasspathName(name, android = false)) { + configurations.resolvable("${name}TestRuntimeClasspath") { + force(forced) extendsFrom( configurations.getByName(test.implementationConfigurationName), configurations.getByName(test.runtimeOnlyConfigurationName), @@ -121,17 +126,6 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project } } - private fun runtimeClasspathName(name: String, android: Boolean) = - if (android) "${name}UnitTestRuntimeClasspath" else "${name}TestRuntimeClasspath" - - /** - * On Android the tests also compile against the matrix versions: Kotlin compiler plugins such as - * the Compose compiler emit calls into the library's runtime that older versions don't have. - */ - private fun testClasspathNames(name: String, android: Boolean) = - if (android) setOf(runtimeClasspathName(name, android), "${name}UnitTestCompileClasspath") - else setOf(runtimeClasspathName(name, android)) - private fun Configuration.force(versions: Map) { resolutionStrategy.eachDependency { versions[requested.group]?.let { useVersion(it) } } } From 5cc5041b82eb9d266b3ad6009a657927b9e5abbb Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:11:22 +0000 Subject: [PATCH 8/9] ci(replay): Make the dependency matrix plugin Android-only Co-Authored-By: Nelson Osacky --- .../sentry/gradle/DependencyMatrixPlugin.kt | 36 ++----------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt index 3e3a22d75f..2e37e9aa77 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -9,14 +9,12 @@ 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.SourceSetContainer import org.gradle.api.tasks.TaskProvider -import org.gradle.api.tasks.testing.Test import org.gradle.language.base.plugins.LifecycleBasePlugin /** - * Runs a module's unit tests on each version of a dependency listed in a checked-in JSON file, for - * Android library and JVM modules. + * 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 @@ -42,7 +40,6 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project val entries = JsonSlurper().parseText(project.providers.fileContents(file).asText.get()) as List<*> check(entries.isNotEmpty()) { "gradle/$versionsFile lists no versions" } - val android = project.plugins.hasPlugin("com.android.library") 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<*, *>? @@ -50,7 +47,7 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project groups.associateWith { version } + pin.orEmpty().entries.associate { (group, pinned) -> group as String to pinned as String } val variant = "$name${suffix(version)}" - val test = if (android) androidUnitTest(variant, forced) else jvmTest(variant, forced) + val test = androidUnitTest(variant, forced) project.tasks.register("${name}Test${suffix(version)}") { description = "Runs the unit tests with ${groups.joinToString()} at $version." group = LifecycleBasePlugin.VERIFICATION_GROUP @@ -99,33 +96,6 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project return unitTest } - /** - * A test task of [name] that reuses the compiled tests on a runtime classpath with the [forced] - * versions, like [SpringBootMatrixPlugin] does. - */ - private fun jvmTest(name: String, forced: Map): TaskProvider { - val sourceSets = project.extensions.getByType(SourceSetContainer::class.java) - val test = sourceSets.getByName("test") - val configurations = project.configurations - val runtimeClasspath = - configurations.resolvable("${name}TestRuntimeClasspath") { - force(forced) - extendsFrom( - configurations.getByName(test.implementationConfigurationName), - configurations.getByName(test.runtimeOnlyConfigurationName), - ) - attributes.addAllLater( - configurations.getByName(test.runtimeClasspathConfigurationName).attributes - ) - } - val taskName = "test${name.replaceFirstChar(Char::uppercase)}" - return project.tasks.register(taskName, Test::class.java) { - testClassesDirs = test.output.classesDirs - classpath = test.output + sourceSets.getByName("main").output + runtimeClasspath.get() - useJUnit() - } - } - private fun Configuration.force(versions: Map) { resolutionStrategy.eachDependency { versions[requested.group]?.let { useVersion(it) } } } From 8bb6ff7506cb1c36e3edc061f54e77b363ccbfe7 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:27:10 +0000 Subject: [PATCH 9/9] ci(replay): Run every Compose UI version in one Gradle invocation Co-Authored-By: Nelson Osacky Co-Authored-By: Roman Zavarnitsyn --- .github/workflows/compose-ui-matrix.yml | 33 +++---------------- .../sentry/gradle/DependencyMatrixPlugin.kt | 26 +++++++++++---- 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/.github/workflows/compose-ui-matrix.yml b/.github/workflows/compose-ui-matrix.yml index 4eac7884a5..6f1ac6f216 100644 --- a/.github/workflows/compose-ui-matrix.yml +++ b/.github/workflows/compose-ui-matrix.yml @@ -11,34 +11,10 @@ concurrency: cancel-in-progress: true jobs: - versions: - runs-on: ubuntu-latest - name: Compose UI versions - outputs: - versions: ${{ steps.versions.outputs.versions }} - - steps: - - name: Checkout Repo - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - sparse-checkout: gradle - - - name: Read Compose UI versions - id: versions - run: echo "versions=$(jq -c 'map(.version? // .)' gradle/compose-ui-versions.json)" >> "$GITHUB_OUTPUT" - compose-ui-matrix: - needs: versions timeout-minutes: 30 runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - compose-ui: ${{ fromJSON(needs.versions.outputs.versions) }} - - name: Compose UI ${{ matrix.compose-ui }} - env: - COMPOSE_UI_VERSION: ${{ matrix.compose-ui }} + name: Compose UI Matrix steps: - name: Checkout Repo @@ -53,14 +29,15 @@ jobs: - 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${COMPOSE_UI_VERSION//[.-]/_}" + 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-${{ matrix.compose-ui }} + name: test-results-compose-ui path: | sentry-android-replay/build/reports/* sentry-android-replay/build/test-results/**/*.xml @@ -69,7 +46,7 @@ jobs: uses: phoenix-actions/test-reporting@7317eea6e13c47348dd0bb318669485157c518d6 # pin@v16 if: always() with: - name: JUnit Compose UI ${{ matrix.compose-ui }} + name: JUnit Compose UI path: | sentry-android-replay/build/test-results/**/*.xml reporter: java-junit diff --git a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt index 2e37e9aa77..1d2a06f3d8 100644 --- a/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt +++ b/build-logic/src/main/kotlin/io/sentry/gradle/DependencyMatrixPlugin.kt @@ -32,14 +32,20 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project * 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. A CI - * workflow reads the same file and runs each version in its own job. + * version, for test dependencies whose current version needs a newer [groups] version. + * `Test` runs every version. */ fun matrix(name: String, groups: List, 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<*, *>? @@ -48,11 +54,19 @@ abstract class DependencyMatrixExtension @Inject constructor(private val project pin.orEmpty().entries.associate { (group, pinned) -> group as String to pinned as String } val variant = "$name${suffix(version)}" val test = androidUnitTest(variant, forced) - project.tasks.register("${name}Test${suffix(version)}") { - description = "Runs the unit tests with ${groups.joinToString()} at $version." - group = LifecycleBasePlugin.VERIFICATION_GROUP - dependsOn(test) + // 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) } } }