Skip to content

RUMM-2244: Sourcemap upload script#222

Merged
louiszawadzki merged 7 commits into
developfrom
nogorodnikov/rumm-2244/android-sourcemaps-upload-script
Jul 29, 2022
Merged

RUMM-2244: Sourcemap upload script#222
louiszawadzki merged 7 commits into
developfrom
nogorodnikov/rumm-2244/android-sourcemaps-upload-script

Conversation

@0xnm

@0xnm 0xnm commented Jun 23, 2022

Copy link
Copy Markdown
Member

What does this PR do?

This changed brings a task to upload JS source maps/bundles for Android by getting their location and passing it to the datadog-ci tool. Currently it only supports application module (hence relying on the specific project) and should be applied as apply from in the end of the app module's build.gradle.

It can read properties from the datadog-sourcemaps.properties file (currently reading only service name property + API key), which should be located in the root dir of React Native project. Content should be in the key=value format.

For the custom service name the logic is to check if there is SERVICE_NAME_ANDROID_%FLAVOR% key first, if not check SERVICE_NAME_ANDROID, otherwise fallback to applicationId.

When applied it will add the necessary upload tasks for the variants which have bundling enabled. This task will be automatically run after bundle task completes.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

Comment thread packages/core/datadog-sourcemaps.gradle Outdated
}

// TODO service name per variant?
def serviceName = datadogConfig.SERVICE_NAME ?: androidExtension.defaultConfig.applicationId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Question: should we be able to provide this as an environment variable to get a similar behaviour on iOS and Android?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can you please point me how it is defined/used in case of iOS?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for iOS I thought we could specify it in the Build phase. But now I feel this is a bit too hard to implement.
Now there is an .xcode.env file in the ios folder with env variables that are going to be used for the build.

I thought we could do a .datadog.sourcemaps.env file at the root of the project, which could contain variables like:

  • DATADOG_API_KEY
  • DATADOG_SITE
  • DATADOG_ANDROID_SERVICE
  • DATADOG_IOS_SERVICE

This file can be gitignored so the variables could also be specified in the CI without having to create or decrypt a file.

In the plugin, we could try to source it if is present, then use the env variable that is present.
I think there is an advantage of having only 1 file for iOS and Android, and it integrates nicely with the CI, Fastlane or the .xcode.env (we can add a line to source our file from this one).

What do you think?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the only downside is that not everything should be sourced (service name is not read as env variable by datadog-ci, if I'm not wrong?) and there is no source on Windows (but it is not a big deal, with Gradle we can source by ourselves), but overall I'm ok with such common file.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indeed the service name is not read as an environment variable by datadog-ci, I don't think it should be (if they want to directly use this command, users can create a script that gets this variable and feeds it into the script).

I think the advantage of having 1 config file is that it makes it easy for devs to know where to put things.

Comment thread packages/core/datadog-sourcemaps.gradle Outdated
def serviceName = datadogConfig.SERVICE_NAME ?: androidExtension.defaultConfig.applicationId

if (serviceName == null) {
throw new GradleException("Cannot determine service name.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe a lot of people are going to feel helpless at short messages.
We could improve this message by adding a few troubleshooting actions.
For example:
"Make sure that you've applied the datadog plugin in your android/app/build.gradle (or equivalent) and it has a defaultConfi applicationId."
"You can specify a custom service from the datadog.properties file"

Comment thread packages/core/datadog-sourcemaps.gradle Outdated
def buildVersion = androidExtension.defaultConfig.versionCode

if (releaseVersion == null) {
throw new GradleException("Cannot determine application version," +

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing here, I think we should assume that the person reading this message is not familiar with android development.

Comment thread packages/core/datadog-sourcemaps.gradle
Comment thread packages/core/datadog-sourcemaps.gradle
Comment thread packages/core/datadog-sourcemaps.gradle
Comment thread packages/core/datadog-sourcemaps.gradle
@louiszawadzki

Copy link
Copy Markdown
Contributor

The file needs to be added to the files in packages/core/package.json, and then the release-content needs to be updated

@louiszawadzki

Copy link
Copy Markdown
Contributor

To test this with a new version of datadog-ci:
In your local datadog-ci

  • yarn link
  • yarn build

In your project with a new version of the core package

  • yarn link @datadog/datadog-ci
  • copy datadog-ci/dist/cli.js to node_modules/bin/datadog-ci

@0xnm
0xnm force-pushed the nogorodnikov/rumm-2244/android-sourcemaps-upload-script branch 4 times, most recently from 818a6a9 to 86e8aed Compare June 27, 2022 11:44
@0xnm
0xnm force-pushed the nogorodnikov/rumm-2244/android-sourcemaps-upload-script branch from 86e8aed to 4bc959e Compare June 27, 2022 11:49
@louiszawadzki louiszawadzki added the Do not merge This PR is not ready to be merged yet label Jun 27, 2022
@louiszawadzki

Copy link
Copy Markdown
Contributor

This PR is good for me, let's wait for the unminification to be working in staging before merging it.

}

uploadTask.dependsOn bundleTask
bundleTask.finalizedBy uploadTask

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why this also ? isn't the first dependency enough ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No, not enough. Without uploadTask.dependsOn bundleTask there will be an error if user runs upload task, but there is no bundle task run before by some reason. Without bundleTask.finalizedBy uploadTask there won't be automatic upload after bundle task is finished.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, tks for the explanation. That makes sense.

Comment thread packages/core/datadog-sourcemaps.gradle Outdated
}
}

def runShellCommand(List<String> command, Map<String, String> env = [:]) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

there's already an Exec gradle task from which you can inherit one. Here's the example of the one I did when working for the nightly tests coverage:

tasks.create("checkNightlyTestsCoverage", Exec::class.java) {
        this.group = "datadog"
        val generateApiTasks = allprojects.mapNotNull { it.tasks.findByName("generateApiSurface") }
        setDependsOn(generateApiTasks)
        setCommandLine(
            "python3",
            "instrumentation-tools/nightly_tests_code_coverage.py",
            "-t $threshold"
        )
    }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, inside runShellCommand there is a call to exec, just the body of the upload task created is responsible for the configuration phase, and actual upload is triggered in the doFirst.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yup, sorry didn't check your last commit ;)

@mariusc83 mariusc83 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@louiszawadzki louiszawadzki removed the Do not merge This PR is not ready to be merged yet label Jul 25, 2022
@louiszawadzki
louiszawadzki marked this pull request as ready for review July 25, 2022 09:22
@louiszawadzki
louiszawadzki requested a review from a team as a code owner July 25, 2022 09:22
Comment thread packages/core/datadog-sourcemaps.gradle Outdated
@louiszawadzki
louiszawadzki force-pushed the nogorodnikov/rumm-2244/android-sourcemaps-upload-script branch from a3c49f3 to 454c4a4 Compare July 29, 2022 09:50
@louiszawadzki
louiszawadzki merged commit 108acaa into develop Jul 29, 2022
@louiszawadzki
louiszawadzki deleted the nogorodnikov/rumm-2244/android-sourcemaps-upload-script branch July 29, 2022 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants