Skip to content

Instantly share code, notes, and snippets.

@0x0a0d
Last active September 24, 2021 03:49
Show Gist options
  • Save 0x0a0d/e68552bf33be7849a572ae305dfc5f78 to your computer and use it in GitHub Desktop.
Save 0x0a0d/e68552bf33be7849a572ae305dfc5f78 to your computer and use it in GitHub Desktop.
Sentry script build and upload sourcemaps for react native project
#!/bin/bash
# PROJECT ROOT PATH HERE IF YOU DON'T CALL BY scripts IN package.json
CURRENT_PATH=$(pwd)
IOS_PATH="$CURRENT_PATH/ios"
get_version() {
MARKETING_VERSION=$(grep 'MARKETING_VERSION' $IOS_PATH/*.xcodeproj/project.pbxproj | head -n1 | rev | cut -d ';' -f2 | cut -d ' ' -f1 | rev)
}
get_build() {
CURRENT_PROJECT_VERSION=$(grep 'CURRENT_PROJECT_VERSION' $IOS_PATH/*.xcodeproj/project.pbxproj | head -n1 | rev | cut -d ';' -f2 | cut -d ' ' -f1 | rev)
}
get_app_bundle() {
PRODUCT_BUNDLE_IDENTIFIER=$(grep 'PRODUCT_BUNDLE_IDENTIFIER' $IOS_PATH/*.xcodeproj/project.pbxproj | head -n1 | rev | cut -d ';' -f2 | cut -d '"' -f2 | rev)
}
sentry_upload()
{
PRODUCT_BUNDLE_IDENTIFIER=$1
[[ "$PRODUCT_BUNDLE_IDENTIFIER" == "" ]] && get_app_bundle
MARKETING_VERSION=$2
[[ "$MARKETING_VERSION" == "" ]] && get_version
CURRENT_PROJECT_VERSION=$3
[[ "$CURRENT_PROJECT_VERSION" == "" ]] && get_build
if [[ "$PRODUCT_BUNDLE_IDENTIFIER" == "" || "$MARKETING_VERSION" == "" || "$CURRENT_PROJECT_VERSION" == "" ]]
then
echo "Usage: yarn sentry:sourcemaps:ios:upload <com.app.bundle.name> <version> <build_number>"
exit 1
fi
react-native bundle --dev false --platform ios --entry-file $CURRENT_PATH/index.js --bundle-output $CURRENT_PATH/main.jsbundle --sourcemap-output $CURRENT_PATH/main.jsbundle.map
SENTRY_PROPERTIES=$IOS_PATH/sentry.properties node_modules/@sentry/cli/bin/sentry-cli releases files "$PRODUCT_BUNDLE_IDENTIFIER@$MARKETING_VERSION+$CURRENT_PROJECT_VERSION" upload-sourcemaps --dist $CURRENT_PROJECT_VERSION --strip-prefix $CURRENT_PATH main.jsbundle main.jsbundle.map
}
sentry_upload $@
@0x0a0d
Copy link
Author

0x0a0d commented Sep 16, 2021

Put script above in scripts/sentry-sourcemaps-ios-build-and-upload.sh
Add sentry:sourcemaps:ios to scripts in package.json

// package.json
{
  scripts: {
    "sentry:sourcemaps:ios": "/bin/bash scripts/sentry-sourcemaps-ios-build-and-upload.sh"
  }
}

Upload by executed

yarn sentry:sourcemaps:ios

If script failed to detect app_bundle, app_version, app_build_number, it will throw an error
You must manually set it

# bundle com.my.app.bundle
# version 1.0.1
# build_number 12
yarn sentry:sourcemaps:ios com.my.app.bundle 1.0.1 12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment