Skip to content

Commit 19df621

Browse files
runningcodeclaude
andauthored
feat(snapshots): Add @SentrySnapshot runtime annotation (EME-1055) (#1154)
* feat(snapshots): Add @SentrySnapshot runtime annotation (EME-1055) Introduce a new Maven artifact io.sentry:sentry-snapshots-runtime that publishes the @SentrySnapshot annotation. Consumers apply it alongside @Preview to override the global diff threshold on a per-snapshot basis. The diffThreshold parameter name aligns with the --diff-threshold flag in sentry-cli and the diff_threshold field in the snapshot manifest, giving consistent naming across CLI, manifest, and the Android runtime. A follow-up will wire the Gradle plugin's preview scanner to read the annotation and surface the value in per-snapshot sidecar metadata. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * build(craft): Register sentry-snapshots-runtime in release registry (EME-1055) Add required first-publish metadata (name, sdkName, packageUrl, mainDocsUrl) for the new sentry-snapshots-runtime package so Craft can create its entry in the Sentry release registry. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * build(craft): Use central.sonatype.com for packageUrl (EME-1055) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * build(snapshots): Disable distTar packaging (EME-1055) Only distZip is needed for local development and publishing; skip the tar variant to avoid producing a redundant artifact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * build(snapshots): Drop distTar disable line (EME-1055) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * build(release): Bump sentry-snapshots-runtime version too (EME-1055) scripts/bump-version.sh previously only rewrote the plugin-build and sentry-kotlin-compiler-plugin property files. Without this, the newly added sentry-snapshots-runtime artifact would ship with a stale VERSION_NAME and drift from the other published artifacts on each release. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * apply runtime retention --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent df80572 commit 19df621

10 files changed

Lines changed: 142 additions & 0 deletions

File tree

.craft.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ targets:
1313
sdks:
1414
maven:io.sentry:sentry-android-gradle-plugin:
1515
maven:io.sentry:sentry-kotlin-compiler-plugin:
16+
maven:io.sentry:sentry-snapshots-runtime:
17+
name: 'io.sentry:sentry-snapshots-runtime'
18+
sdkName: 'sentry.java.android.snapshots-runtime'
19+
packageUrl: 'https://central.sonatype.com/artifact/io.sentry/sentry-snapshots-runtime'
20+
mainDocsUrl: 'https://docs.sentry.io/platforms/android'

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add `@SentrySnapshot` runtime annotation for configuring the per-snapshot diff threshold, published as `io.sentry:sentry-snapshots-runtime` ([EME-1055](https://linear.app/getsentry/issue/EME-1055))
8+
59
### Dependencies
610

711
- Bump CLI from v3.3.5 to v3.4.0 ([#1156](https://github.com/getsentry/sentry-android-gradle-plugin/pull/1156))

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ composeCompiler = { id = "org.jetbrains.kotlin.plugin.compose", version = "2.1.
3131

3232
[libraries]
3333
junit = { group = "junit", name = "junit", version = "4.13.2" }
34+
androidxAnnotation = { group = "androidx.annotation", name = "annotation", version = "1.9.1" }
3435
proguard = { group = "com.guardsquare", name = "proguard-gradle", version = "7.5.0" }
3536
# this allows us to develop against a fixed version of Gradle, as opposed to depending on the
3637
# locally available version. kotlin-gradle-plugin follows the same approach.

scripts/bump-version.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ perl -pi -e "s/^$VERSION_NAME_PATTERN = .*$/$VERSION_NAME_PATTERN = $NEW_VERSION
1717
GRADLE_FILEPATH="sentry-kotlin-compiler-plugin/gradle.properties"
1818
VERSION_NAME_PATTERN="VERSION_NAME"
1919
perl -pi -e "s/^$VERSION_NAME_PATTERN = .*$/$VERSION_NAME_PATTERN = $NEW_VERSION/g" $GRADLE_FILEPATH
20+
21+
GRADLE_FILEPATH="sentry-snapshots-runtime/gradle.properties"
22+
VERSION_NAME_PATTERN="VERSION_NAME"
23+
perl -pi -e "s/^$VERSION_NAME_PATTERN = .*$/$VERSION_NAME_PATTERN = $NEW_VERSION/g" $GRADLE_FILEPATH

sentry-snapshots-runtime/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.PHONY: compile all dist
2+
3+
compile:
4+
./gradlew assemble
5+
6+
# build distribution artifacts
7+
dist:
8+
./gradlew distZip --no-parallel
9+
10+
all: compile dist
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
plugins {
2+
alias(libs.plugins.kotlin)
3+
id("distribution")
4+
alias(libs.plugins.mavenPublish)
5+
alias(libs.plugins.spotless)
6+
}
7+
8+
spotless {
9+
kotlin {
10+
ktfmt(libs.versions.ktfmt.get()).googleStyle()
11+
target("**/*.kt")
12+
}
13+
kotlinGradle {
14+
target("**/*.kts")
15+
ktfmt(libs.versions.ktfmt.get()).googleStyle()
16+
}
17+
}
18+
19+
val sep = File.separator
20+
21+
distributions {
22+
main {
23+
contents {
24+
from("build${sep}libs")
25+
from("build${sep}publications${sep}maven")
26+
}
27+
}
28+
}
29+
30+
tasks.named("distZip") {
31+
dependsOn("publishToMavenLocal")
32+
onlyIf { inputs.sourceFiles.isEmpty.not().also { require(it) { "No distribution to zip." } } }
33+
}
34+
35+
dependencies { compileOnly(libs.androidxAnnotation) }
36+
37+
plugins.withId("com.vanniktech.maven.publish.base") {
38+
configure<PublishingExtension> {
39+
repositories {
40+
maven {
41+
name = "mavenTestRepo"
42+
url = file("${rootProject.projectDir}/../build/mavenTestRepo").toURI()
43+
}
44+
maven {
45+
name = "mavenCentralSnapshots"
46+
url = uri("https://central.sonatype.com/repository/maven-snapshots/")
47+
credentials {
48+
username = findProperty("mavenCentralUsername")?.toString()
49+
password = findProperty("mavenCentralPassword")?.toString()
50+
}
51+
}
52+
}
53+
}
54+
}
55+
56+
kotlin { jvmToolchain(11) }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
org.gradle.jvmargs=-Xmx4g -XX:MaxMetaspaceSize=1536m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC -XX:+CrashOnOutOfMemoryError
2+
org.gradle.caching=true
3+
org.gradle.parallel=true
4+
5+
GROUP = io.sentry
6+
POM_ARTIFACT_ID = sentry-snapshots-runtime
7+
VERSION_NAME = 6.4.0
8+
9+
# publication pom properties
10+
POM_NAME=Sentry Snapshots Runtime
11+
POM_DESCRIPTION=Runtime annotations for configuring Sentry snapshot tests
12+
POM_URL=https://github.com/getsentry/sentry-android-gradle-plugin
13+
POM_SCM_URL=https://github.com/getsentry/sentry-android-gradle-plugin
14+
POM_SCM_CONNECTION=scm:git:git://github.com/getsentry/sentry-android-gradle-plugin.git
15+
POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/getsentry/sentry-android-gradle-plugin.git
16+
17+
POM_LICENCE_NAME=MIT
18+
POM_LICENCE_URL=https://github.com/getsentry/sentry-android-gradle-plugin/blob/main/LICENSE
19+
20+
POM_DEVELOPER_ID=getsentry
21+
POM_DEVELOPER_NAME=Sentry Team and Contributors
22+
POM_DEVELOPER_URL=https://github.com/getsentry/
23+
24+
RELEASE_SIGNING_ENABLED=false
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rootProject.name = ("sentry-snapshots-runtime")
2+
3+
dependencyResolutionManagement {
4+
repositories {
5+
google()
6+
mavenCentral()
7+
}
8+
versionCatalogs.create("libs") { from(files("../gradle/libs.versions.toml")) }
9+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.sentry.snapshots.runtime
2+
3+
import androidx.annotation.FloatRange
4+
5+
/**
6+
* Configures how Sentry compares this preview snapshot against the baseline.
7+
*
8+
* Apply alongside `@Preview` on a composable to override the global diff threshold on a
9+
* per-snapshot basis.
10+
*/
11+
@Retention(AnnotationRetention.RUNTIME)
12+
@Target(AnnotationTarget.FUNCTION)
13+
annotation class SentrySnapshot(
14+
/**
15+
* Minimum pixel-difference percentage required to report this snapshot as changed. Differences
16+
* below this value are treated as unchanged.
17+
*
18+
* Range: `0.0`..`1.0`. Example: `0.01f` reports a change only when at least 1% of pixels differ.
19+
* Defaults to `0f` (report any difference).
20+
*/
21+
@FloatRange(from = 0.0, to = 1.0) val diffThreshold: Float = 0f
22+
)

settings.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,9 @@ includeBuild("sentry-kotlin-compiler-plugin") {
4646
substitute(module("io.sentry:sentry-kotlin-compiler-plugin")).using(project(":"))
4747
}
4848
}
49+
50+
includeBuild("sentry-snapshots-runtime") {
51+
dependencySubstitution {
52+
substitute(module("io.sentry:sentry-snapshots-runtime")).using(project(":"))
53+
}
54+
}

0 commit comments

Comments
 (0)