bugsnag / bugsnag-expo

MIT License
11 stars 5 forks source link

Support customization of the appVersion for sourcemap uploads. #129

Closed jmoseley closed 1 year ago

jmoseley commented 1 year ago

Description

In my app, I use an app version string that includes the git sha (such as 1.3.12-abcdef), and I specify this explicitly when I . I do this to allow me to have a unique app version for each call to eas update, and have separate source maps each time I publish. However, I am unable to configure the sourcemaps upload for a new build, so each build has an invalid version (until it receives an OTA update from eas update).

Describe the solution you'd like It would be great if the plugin could be configurable, so I can set a custom appVersion for the sourcemap upload.

Describe alternatives you've considered To work around this, I am modifying my app.json file during my CI step to inject the expo.version that I want the sourcemaps to be published with.

johnkiely1 commented 1 year ago

Hey @jmoseley.

For eas update we dont currently support uploading the sourcemaps automatically so you would need to use our cli tool manually in which you can specify any app version you like, but it doesn't sound like you are doing that.

Could you give me a bit more detail around how are you currently configuring the sourcemap uploads? Feel free to share code snippets as necessary.

jmoseley commented 1 year ago

Hey @johnkiely1 ,

Sorry I was not clear 🤦 . This request is specifically for the @bugsnag/plugin-expo-eas-sourcemaps plugin when using eas build. For eas update I am making a specific call to upload the source maps, and I am using a modified appVersion to make each update unique.

Here is how I am doing it for eas update in my Github Action:

      - name: Publish update
        run: eas update --auto
        env:
          GIT_SHA: ${{ github.sha }}

      - name: Extract version from app.json
        uses: sergeysova/jq-action@v2
        id: version
        with:
          cmd: jq -r ".expo.version" app.json

      - name: Upload sourcemaps for android
        run: npx bugsnag-source-maps upload-react-native
          --api-key 363b5b91d530296c0b8d96c78d11f1a5
          --platform android
          --app-version "${{ steps.version.outputs.value }}-$(echo ${{ github.sha }} | cut -c1-8)"
          --source-map "./dist/bundles/$(ls ./dist/bundles | grep "android.*.map")"
          --bundle "./dist/bundles/$(ls ./dist/bundles | grep "android.*.js")"

      - name: Upload sourcemaps for ios
        run: npx bugsnag-source-maps upload-react-native
          --api-key 363b5b91d530296c0b8d96c78d11f1a5
          --platform ios
          --app-version "${{ steps.version.outputs.value }}-$(echo ${{ github.sha }} | cut -c1-8)"
          --source-map "./dist/bundles/$(ls ./dist/bundles | grep "ios.*.map")"
          --bundle "./dist/bundles/$(ls ./dist/bundles | grep "ios.*.js")"

The interesting bit to note is how I generate the --app-version, using a combination of the version field from app.json, and a shortened git sha.

I am hoping to be able to specify a similar appVersion for @bugsnag/plugin-expo-eas-sourcemaps when it uploads the sourcemaps after a call to eas build. Currently it pulls the version directly from app.json, so there is no opportunity for me to also include the extra git sha portion.

johnkiely1 commented 1 year ago

Hey @jmoseley, Thanks for the clarification. Seems like a reasonable idea. We've added it to the backlog and we will post any updates here.

jmoseley commented 1 year ago

Wonderful, thanks!

yousif-bugsnag commented 1 year ago

Hi @jmoseley 👋🏾

I work on the JS team here at Bugsnag.

It sounds like the reason you're modifying the app version is to have unique app versions for each eas update, in order for sourcemap uploads to match correctly?

Our recommended approach to sourcemap matching for EAS Update is to use the codeBundleId config option rather than modifying appVersion - when codeBundleId is set, it's used in place of the appVersion for matching sourcemaps to events.

You would need to specify this both in your sourcemap upload script and in your app at runtime. There are some examples in our docs that demonstrate setting this using Expo's Update Groups, but the value could be anything you like as long as it uniquely identifies the update: https://docs.bugsnag.com/platforms/react-native/expo/configuration-options/#codebundleid https://docs.bugsnag.com/build-integrations/js/source-maps-react-native/#eas-update

The only thing to be aware of here is that codeBundleId should only be set at runtime if the app is running an EAS Update (Updates.isEmbeddedLaunch = false) and not if running an EAS Build. This way events from EAS builds will be matched to sourcemaps on appVersion and only events from coming from EAS updates will be matched on codeBundleId.

If you did want to configure expo.version dynamically at build time for eas build, Expo already supports this via dynamic configuration: https://docs.expo.dev/workflow/configuration/#dynamic-configuration

Dynamic configuration is evaluated by Expo before being passed to @bugsnag/plugin-expo-eas-sourcemaps. However please note that if you're building for iOS then expo.version needs to adhere to a specific format: https://docs.expo.dev/workflow/configuration/#dynamic-configuration

jmoseley commented 1 year ago

Thanks for the thorough response! I will give this a try.

jmoseley commented 1 year ago

So I was able to get this working, however I am facing a new problem. Now it is telling me that the source maps do not match the code.

image

Any ideas?

Here is the code that uploads the source maps (part of a Github Action):

      - name: Publish update
        id: eas-update
        run: |
          UPDATE_RESULT=$(eas update --auto --json --non-interactive)
          ANDROID_GROUP_ID=$(echo $UPDATE_RESULT | jq -r '.[]| select(.platform == "android")|.id')
          IOS_GROUP_ID=$(echo $UPDATE_RESULT | jq -r '.[]| select(.platform == "ios")|.id')
          echo "androidId=$ANDROID_GROUP_ID" >> $GITHUB_OUTPUT
          echo "iosId=$IOS_GROUP_ID" >> $GITHUB_OUTPUT
        env:
          GIT_SHA: ${{ github.sha }}
          RELEASE_CHANNEL: production

      - name: List bundles
        run: ls ./dist/bundles

      - name: Upload sourcemaps for android
        run: npx bugsnag-source-maps upload-react-native
          --api-key <REDACTED>
          --platform android
          --code-bundle-id "${{ steps.eas-update.outputs.androidId }}"
          --source-map "./dist/bundles/$(ls ./dist/bundles | grep "android.*.map")"
          --bundle "./dist/bundles/$(ls ./dist/bundles | grep "android.*.js")"

      - name: Upload sourcemaps for ios
        run: npx bugsnag-source-maps upload-react-native
          --api-key <REDACTED>
          --platform ios
          --code-bundle-id "${{ steps.eas-update.outputs.iosId }}"
          --source-map "./dist/bundles/$(ls ./dist/bundles | grep "ios.*.map")"
          --bundle "./dist/bundles/$(ls ./dist/bundles | grep "ios.*.js")"

I have verified that the IDs are being extracted correctly, and the bundle files are being found and uploaded.

johnkiely1 commented 1 year ago

Hey @jmoseley, glad to hear it's working for you. With regards the sourcemap matching issue would you mind writing in to support@bugsnag.com with a link (as it appears on your BugSnag dashboard) to that error in question and we will be happy to investigate for you.

jmoseley commented 1 year ago

Sounds good, thanks for the help.