-
-
Notifications
You must be signed in to change notification settings - Fork 37
feat(snapshots): Add snapshot upload task #1091
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
35bf18d
feat(snapshots): Add snapshot upload task
runningcode ae87b25
fix(snapshots): Wire telemetry provider for snapshot uploads
runningcode 1eec8e8
refactor(snapshots): Remove afterEvaluate and isPresent check
runningcode ca2fec8
feat(snapshots): Add required --app-id argument
runningcode 2e69dd4
docs: Add changelog entry for snapshot uploads
runningcode 582082e
refactor(snapshots): Simplify task registration API
runningcode cfa4336
style: Apply spotless formatting
runningcode eb53543
refactor(snapshots): Wire telemetry and sentry properties properly
runningcode 65587af
fix(snapshots): Make variant nullable in getPropertiesFilePath
runningcode b298f89
refactor(snapshots): Remove telemetry from snapshot uploads
runningcode 612f5f8
fix(snapshots): Skip buildType paths when variant is null
runningcode 2603da1
test(snapshots): Add tests for null variant property lookup
runningcode 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
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
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
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
17 changes: 17 additions & 0 deletions
17
plugin-build/src/main/kotlin/io/sentry/android/gradle/extensions/SnapshotsExtension.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,17 @@ | ||
| package io.sentry.android.gradle.extensions | ||
|
|
||
| import javax.inject.Inject | ||
| import org.gradle.api.file.DirectoryProperty | ||
| import org.gradle.api.model.ObjectFactory | ||
| import org.gradle.api.provider.Property | ||
| import org.jetbrains.annotations.ApiStatus.Experimental | ||
|
|
||
| @Experimental | ||
| open class SnapshotsExtension @Inject constructor(objects: ObjectFactory) { | ||
|
|
||
| /** The application identifier used to associate snapshots with an app. */ | ||
| val appId: Property<String> = objects.property(String::class.java) | ||
|
runningcode marked this conversation as resolved.
|
||
|
|
||
| /** The path to the folder containing snapshots to upload. */ | ||
| val path: DirectoryProperty = objects.directoryProperty() | ||
|
runningcode marked this conversation as resolved.
|
||
| } | ||
72 changes: 72 additions & 0 deletions
72
plugin-build/src/main/kotlin/io/sentry/android/gradle/tasks/SentryUploadSnapshotsTask.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,72 @@ | ||
| package io.sentry.android.gradle.tasks | ||
|
|
||
| import io.sentry.android.gradle.SentryPropertiesFileProvider.getPropertiesFilePath | ||
| import io.sentry.android.gradle.autoinstall.SENTRY_GROUP | ||
| import io.sentry.android.gradle.extensions.SentryPluginExtension | ||
| import io.sentry.android.gradle.util.asSentryCliExec | ||
| import org.gradle.api.Project | ||
| import org.gradle.api.file.DirectoryProperty | ||
| import org.gradle.api.provider.Property | ||
| import org.gradle.api.provider.Provider | ||
| import org.gradle.api.tasks.Input | ||
| import org.gradle.api.tasks.InputDirectory | ||
| import org.gradle.api.tasks.PathSensitive | ||
| import org.gradle.api.tasks.PathSensitivity | ||
| import org.gradle.api.tasks.TaskProvider | ||
| import org.gradle.work.DisableCachingByDefault | ||
|
|
||
| @DisableCachingByDefault(because = "Uploads should not be cached") | ||
| abstract class SentryUploadSnapshotsTask : SentryCliExecTask() { | ||
|
|
||
| init { | ||
| group = SENTRY_GROUP | ||
| description = "Uploads snapshots to Sentry" | ||
| } | ||
|
|
||
| @get:Input abstract val appId: Property<String> | ||
|
|
||
| @get:InputDirectory | ||
| @get:PathSensitive(PathSensitivity.RELATIVE) | ||
| abstract val snapshotsPath: DirectoryProperty | ||
|
sentry[bot] marked this conversation as resolved.
|
||
|
|
||
| override fun getArguments(args: MutableList<String>) { | ||
| args.add("build") | ||
| args.add("snapshots") | ||
| args.add("--app-id") | ||
| args.add(appId.get()) | ||
| args.add(snapshotsPath.get().asFile.absolutePath) | ||
| } | ||
|
|
||
| companion object { | ||
| fun register( | ||
| project: Project, | ||
| extension: SentryPluginExtension, | ||
| cliExecutable: Provider<String>, | ||
| sentryOrgOverride: String?, | ||
| sentryProjectOverride: String?, | ||
| ): TaskProvider<SentryUploadSnapshotsTask> { | ||
| return project.tasks.register( | ||
| "sentryUploadSnapshots", | ||
| SentryUploadSnapshotsTask::class.java, | ||
| ) { task -> | ||
| task.workingDir(project.rootDir) | ||
| task.debug.set(extension.debug) | ||
| task.cliExecutable.set(cliExecutable) | ||
| task.sentryProperties.set( | ||
| getPropertiesFilePath(project)?.let { file -> project.file(file) } | ||
| ) | ||
| task.sentryOrganization.set( | ||
| sentryOrgOverride?.let { project.provider { it } } ?: extension.org | ||
| ) | ||
| task.sentryProject.set( | ||
| sentryProjectOverride?.let { project.provider { it } } ?: extension.projectName | ||
| ) | ||
| task.sentryAuthToken.set(extension.authToken) | ||
| task.sentryUrl.set(extension.url) | ||
| task.appId.set(extension.snapshots.appId) | ||
| task.snapshotsPath.set(extension.snapshots.path) | ||
| task.asSentryCliExec() | ||
| } | ||
| } | ||
| } | ||
| } | ||
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
140 changes: 140 additions & 0 deletions
140
plugin-build/src/test/kotlin/io/sentry/android/gradle/tasks/SentryUploadSnapshotsTaskTest.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,140 @@ | ||
| package io.sentry.android.gradle.tasks | ||
|
|
||
| import java.io.File | ||
| import kotlin.test.assertEquals | ||
| import kotlin.test.assertFalse | ||
| import kotlin.test.assertNull | ||
| import kotlin.test.assertTrue | ||
| import org.gradle.api.Project | ||
| import org.gradle.testfixtures.ProjectBuilder | ||
| import org.junit.Test | ||
|
|
||
| class SentryUploadSnapshotsTaskTest { | ||
|
|
||
| @Test | ||
| fun `cli-executable is set correctly`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertTrue("sentry-cli" in args) | ||
| assertTrue("build" in args) | ||
| assertTrue("snapshots" in args) | ||
| assertTrue("--app-id" in args) | ||
| assertTrue("com.example" in args) | ||
| assertTrue("/path/to/snapshots" in args) | ||
| assertFalse("--log-level=debug" in args) | ||
| } | ||
|
|
||
| @Test | ||
| fun `--log-level=debug is set correctly`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| it.debug.set(true) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertTrue("--log-level=debug" in args) | ||
| } | ||
|
|
||
| @Test | ||
| fun `with sentryProperties file SENTRY_PROPERTIES is set correctly`() { | ||
| val project = createProject() | ||
| val propertiesFile = project.file("dummy/folder/sentry.properties") | ||
| val task = createTestTask(project) { it.sentryProperties.set(propertiesFile) } | ||
|
|
||
| task.setSentryPropertiesEnv() | ||
|
|
||
| assertEquals(propertiesFile.absolutePath, task.environment["SENTRY_PROPERTIES"].toString()) | ||
| } | ||
|
|
||
| @Test | ||
| fun `without sentryProperties file SENTRY_PROPERTIES is not set`() { | ||
| val task = createTestTask() | ||
|
|
||
| task.setSentryPropertiesEnv() | ||
|
|
||
| assertNull(task.environment["SENTRY_PROPERTIES"]) | ||
| } | ||
|
|
||
| @Test | ||
| fun `with sentryOrganization adds --org`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.sentryOrganization.set("dummy-org") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertTrue("--org" in args) | ||
| assertTrue("dummy-org" in args) | ||
| } | ||
|
|
||
| @Test | ||
| fun `with sentryProject adds --project`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.sentryProject.set("dummy-proj") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertTrue("--project" in args) | ||
| assertTrue("dummy-proj" in args) | ||
| } | ||
|
|
||
| @Test | ||
| fun `with sentryUrl adds --url`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.sentryUrl.set("https://some-host.sentry.io") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertTrue("--url" in args) | ||
| assertTrue("https://some-host.sentry.io" in args) | ||
| } | ||
|
|
||
| @Test | ||
| fun `the --url parameter is placed as the first argument`() { | ||
| val task = createTestTask { | ||
| it.cliExecutable.set("sentry-cli") | ||
| it.sentryUrl.set("https://some-host.sentry.io") | ||
| it.appId.set("com.example") | ||
| it.snapshotsPath.set(File("/path/to/snapshots")) | ||
| } | ||
|
|
||
| val args = task.computeCommandLineArgs() | ||
|
|
||
| assertEquals(1, args.indexOf("--url")) | ||
| } | ||
|
|
||
| private fun createProject(): Project { | ||
| with(ProjectBuilder.builder().build()) { | ||
| plugins.apply("io.sentry.android.gradle") | ||
| return this | ||
| } | ||
| } | ||
|
|
||
| private fun createTestTask( | ||
| project: Project = createProject(), | ||
| block: (SentryUploadSnapshotsTask) -> Unit = {}, | ||
| ): SentryUploadSnapshotsTask = | ||
| project.tasks | ||
| .register("testUploadSnapshots", SentryUploadSnapshotsTask::class.java) { block(it) } | ||
| .get() | ||
| } |
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.