Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/main/java/io/sentry/UploadSourceBundleMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public class UploadSourceBundleMojo extends AbstractMojo {
@Parameter(defaultValue = DEFAULT_SKIP_SOURCE_BUNDLE_STRING)
private boolean skipSourceBundle;

@Parameter(defaultValue = DEFAULT_IGNORE_SOURCE_BUNDLE_UPLOAD_FAILURE_STRING)
private boolean ignoreSourceBundleUploadFailure;

@SuppressWarnings("NullAway")
@Component
private @NotNull BuildPluginManager pluginManager;
Expand Down Expand Up @@ -257,7 +260,11 @@ private void uploadSourceBundle(
cliRunner.runSentryCli(String.join(" ", command), true);
} catch (Throwable t) {
SentryTelemetryService.getInstance().captureError(t, "uploadSourceBundle");
throw t;
if (ignoreSourceBundleUploadFailure) {
logger.warn("Source bundle upload failed, ignored by configuration");
} else {
throw t;
}
} finally {
SentryTelemetryService.getInstance().endTask(span);
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/sentry/config/PluginConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class PluginConfig {
public static final @NotNull String DEFAULT_SKIP_AUTO_INSTALL_STRING = "false";
public static final boolean DEFAULT_SKIP_SOURCE_BUNDLE = false;
public static final @NotNull String DEFAULT_SKIP_SOURCE_BUNDLE_STRING = "false";
public static final boolean DEFAULT_IGNORE_SOURCE_BUNDLE_UPLOAD_FAILURE = false;
public static final @NotNull String DEFAULT_IGNORE_SOURCE_BUNDLE_UPLOAD_FAILURE_STRING = "false";
public static final boolean DEFAULT_SKIP_TELEMETRY = false;
public static final @NotNull String DEFAULT_SKIP_TELEMETRY_STRING = "false";
public static final boolean DEFAULT_DEBUG_SENTRY_CLI = false;
Expand All @@ -28,6 +30,7 @@ public class PluginConfig {
private boolean skipTelemetry = DEFAULT_SKIP_TELEMETRY;
private boolean skipReportDependencies = DEFAULT_SKIP_REPORT_DEPENDENCIES;
private boolean skipSourceBundle = DEFAULT_SKIP_SOURCE_BUNDLE;
private boolean ignoreSourceBundleUploadFailure = DEFAULT_IGNORE_SOURCE_BUNDLE_UPLOAD_FAILURE;
private boolean debugSentryCli = DEFAULT_DEBUG_SENTRY_CLI;
private boolean debug = DEFAULT_DEBUG;
private boolean skipValidateSdkDependencyVersions = DEFAULT_SKIP_VALIDATE_SDK_DEPENDENCY_VERSIONS;
Expand Down Expand Up @@ -88,6 +91,10 @@ public void setSkipSourceBundle(final boolean skipSourceBundle) {
this.skipSourceBundle = skipSourceBundle;
}

public void setIgnoreSourceBundleUploadFailure(final boolean ignoreSourceBundleUploadFailure) {
this.ignoreSourceBundleUploadFailure = ignoreSourceBundleUploadFailure;
}

public void setSkipValidateSdkDependencyVersions(
final boolean skipValidateSdkDependencyVersions) {
this.skipValidateSdkDependencyVersions = skipValidateSdkDependencyVersions;
Expand All @@ -109,6 +116,10 @@ public boolean isSkipSourceBundle() {
return skipSourceBundle || skip;
}

public boolean isIgnoreSourceBundleUploadFailure() {
return ignoreSourceBundleUploadFailure;
}

public boolean isSkipValidateSdkDependencyVersions() {
return skipValidateSdkDependencyVersions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.sentry.integration.uploadSourceBundle
fun basePom(
skipPlugin: Boolean = false,
skipSourceBundle: Boolean = false,
ignoreSourceBundleUploadFailure: Boolean = false,
sentryCliPath: String? = null,
extraSourceRoots: List<String> = listOf(),
extraSourceContextDirs: List<String> = emptyList(),
Expand Down Expand Up @@ -88,7 +89,9 @@ fun basePom(
<debugSentryCli>true</debugSentryCli>
<skip>$skipPlugin</skip>
<skipSourceBundle>$skipSourceBundle</skipSourceBundle>
<ignoreSourceBundleUploadFailure>$ignoreSourceBundleUploadFailure</ignoreSourceBundleUploadFailure>
<skipTelemetry>true</skipTelemetry>

<org>sentry-sdks</org>
<project>sentry-maven</project>
<authToken>\&lt;token\&gt;</authToken>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,44 @@ class UploadSourceBundleTestIT {
baseDir: File,
skipPlugin: Boolean = false,
skipSourceBundle: Boolean = false,
ignoreSourceBundleUploadFailure: Boolean = false,
sentryCliPath: String? = null,
extraSourceRoots: List<String> = listOf(),
extraSourceContextDirs: List<String> = emptyList(),
): String {
val pomContent = basePom(skipPlugin, skipSourceBundle, sentryCliPath, extraSourceRoots, extraSourceContextDirs)
val pomContent =
basePom(skipPlugin, skipSourceBundle, ignoreSourceBundleUploadFailure, sentryCliPath, extraSourceRoots, extraSourceContextDirs)

Files.write(Path("${baseDir.absolutePath}/pom.xml"), pomContent.toByteArray(), StandardOpenOption.CREATE)

return baseDir.absolutePath
}

@Test
fun `does not fail build when upload fails and ignoreSourceBundleUploadFailure is true`() {
val baseDir = setupProject()
val cliPath = File(baseDir, "sentry-cli-fail")
cliPath.writeText(
"""
#!/bin/sh
if echo "$@" | grep -q "upload"; then
exit 1
fi
exit 0
""",
)
cliPath.setExecutable(true)

val path = getPOM(baseDir, sentryCliPath = cliPath.absolutePath, ignoreSourceBundleUploadFailure = true)
val verifier = Verifier(path)
verifier.isAutoclean = false
verifier.executeGoal("install")

verifier.verifyTextInLog("Source bundle upload failed, ignored by configuration")

verifier.resetStreams()
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test to confirm that if the flag is set to false the build fails (i.e. old behaviour):

Suggested change
@Test
fun `fails build when upload fails and ignoreSourceBundleUploadFailure is false`() {
val baseDir = setupProject()
val path = getPOM(baseDir, sentryUrl = "http://unknown")
val verifier = Verifier(path)
verifier.isAutoclean = false
assertThrows(VerificationException::class.java) {
verifier.executeGoal("install")
}
verifier.verifyTextInLog("Could not resolve hostname (Could not resolve host: unknown)")
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThrows wasn't available, but

        assertFailsWith<VerificationException> {
            verifier.executeGoal("install")
        }

seems to do just fine.

@Test
@Throws(VerificationException::class, IOException::class)
fun `uploads source bundle`() {
Expand Down
Loading