Last active
September 24, 2021 03:49
-
-
Save 0x0a0d/e68552bf33be7849a572ae305dfc5f78 to your computer and use it in GitHub Desktop.
Sentry script build and upload sourcemaps for react native project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put script above in
scripts/sentry-sourcemaps-ios-build-and-upload.sh
Add
sentry:sourcemaps:ios
toscripts
inpackage.json
Upload by executed
If script failed to detect
app_bundle
,app_version
,app_build_number
, it will throw an errorYou must manually set it