Skip to content

Commit

Permalink
Merge pull request #450 from DataDog/louiszawadzki/fix-android-send-b…
Browse files Browse the repository at this point in the history
…undle

Always pass bundle to sourcemap command on Android
  • Loading branch information
louiszawadzki authored Apr 17, 2023
2 parents e99b231 + 84f4fdd commit d943f3e
Showing 1 changed file with 6 additions and 49 deletions.
55 changes: 6 additions & 49 deletions packages/core/datadog-sourcemaps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ afterEvaluate {
group = "datadog"
description = "Uploads sourcemaps to Datadog."

def execCommand = { jsBundleFile, shouldUploadBundleFile ->
def command = [
def execCommand = { jsBundleFile ->
return [
"yarn",
"datadog-ci",
"react-native",
Expand All @@ -66,33 +66,28 @@ afterEvaluate {
"android",
"--service",
serviceName,
"--bundle",
jsBundleFile.absolutePath,
"--sourcemap",
jsOutputSourceMapFile.absolutePath,
"--release-version",
releaseVersion,
"--build-version",
buildVersion
]
if (shouldUploadBundleFile) {
command.add("--bundle")
command.add(jsBundleFile.absolutePath)
}
return command
}

doFirst {
def shouldUploadBundleFile = getShouldUploadBundleFile(reactRoot)

def jsBundleFile = reactConfig.bundleFileResolver()
if (jsBundleFile == null && shouldUploadBundleFile) {
if (jsBundleFile == null) {
throw new GradleException("JS bundle file doesn't exist, aborting upload.")
}

if (!jsOutputSourceMapFile.exists()) {
throw new GradleException("JS sourcemap file doesn't exist, aborting upload.")
}

runShellCommand(execCommand(jsBundleFile, shouldUploadBundleFile), reactRoot)
runShellCommand(execCommand(jsBundleFile), reactRoot)

}
}
Expand Down Expand Up @@ -184,7 +179,6 @@ private def runShellCommand(
result.rethrowFailure()
} else {
logger.lifecycle(outputStream.toString("UTF-8"))
return outputStream.toString("UTF-8")
}
} catch (Exception e) {
def errorStreamContent = errorStream.toString("UTF-8")
Expand All @@ -195,43 +189,6 @@ private def runShellCommand(
}
}

private def getShouldUploadBundleFile(File reactRoot) {
// Provide a way to override bundle upload
if (project.hasProperty("datadog")) {
if (project.datadog.containsKey("shouldUploadBundle")) {
return project.datadog.shouldUploadBundle
}
}

def datadogCiVersionCommand = [
"yarn",
"--silent",
"datadog-ci",
"version"
]
try {
def versionAsString = runShellCommand(datadogCiVersionCommand, reactRoot) // outputs: v2.5.1
// We remove the leading "v" in the version number output
List version = versionAsString.replace("v", "").tokenize('.').collect { it.toInteger() }

// First datadog-ci version allowing not uploading the bundle is 2.6.0
return !isVersionEqualOrAbove(version, [2, 6, 0])
} catch (Exception e) {

return true
}
}

private static isVersionEqualOrAbove(List version, List targetVersion) {
if (version[0] != targetVersion[0]) {
return version[0] > targetVersion[0]
}
if (version [1] != targetVersion[1]) {
return version[1] > targetVersion[1]
}
return version[2] >= targetVersion[2]
}

private def getServiceName(variant) {
if (project.hasProperty("datadog")) {
if (project.datadog.serviceName) {
Expand Down

0 comments on commit d943f3e

Please sign in to comment.