From 5ff7aa9fe13df1aaa23f3a9fe8a1ce2c7108105f Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Sun, 12 Mar 2023 14:19:24 +0200 Subject: [PATCH 1/8] Use RN Internal Sourcemap Script --- .circleci/config.yml | 2 +- .../InstabugExample.xcodeproj/project.pbxproj | 2 +- ios/sourcemaps.sh | 74 ++++++++++++ ios/upload_sourcemap.sh | 105 ------------------ react-native.config.js | 2 +- 5 files changed, 77 insertions(+), 108 deletions(-) create mode 100644 ios/sourcemaps.sh delete mode 100644 ios/upload_sourcemap.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index c0565f1941..a5b7b825fe 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -82,7 +82,7 @@ jobs: command: ls scripts/*.sh | xargs bash -n - run: name: Validate iOS Script - command: bash -n ios/upload_sourcemap.sh + command: bash -n ios/sourcemaps.sh # Make sure that files like yarn.lock and project.pbxproj # are in sync with the latest changes in package.json and diff --git a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj index 42f6a9e880..3edf4947df 100644 --- a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj +++ b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj @@ -401,7 +401,7 @@ name = "[CP-User] [instabug-reactnative] Upload Sourcemap"; runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "#!/bin/sh\ncd ${PROJECT_DIR}\ncd ..\nif [ -s \"$HOME/.nvm/nvm.sh\" ]; then\n. \"$HOME/.nvm/nvm.sh\"\nelif [ -x \"$(command -v brew)\" ] && [ -s \"$(brew --prefix nvm)/nvm.sh\" ]; then\n. \"$(brew --prefix nvm)/nvm.sh\"\nfi\nexport NODE_BINARY=node\n\nINSTABUG_SOURCEMAPS_UPLOAD_DISABLE=$(echo $INSTABUG_SOURCEMAPS_UPLOAD_DISABLE | tr 'A-Z' 'a-z')\nif [ \"${INSTABUG_SOURCEMAPS_UPLOAD_DISABLE}\" = \"true\" ]; then\n echo \"Instabug: Environment variable INSTABUG_SOURCEMAPS_UPLOAD_DISABLE was set to true, skipping sourcemap upload\"\n exit 0\nfi\n\nif [ ! \"$INFOPLIST_FILE\" ] || [ -z \"$INFOPLIST_FILE\" ]; then\n echo \"Instabug: INFOPLIST_FILE not found in Xcode build settings, skipping sourcemap upload\"\n exit 0\nfi\n\nif [ ! \"${PROJECT_DIR}\" ] || [ -z \"${PROJECT_DIR}\" ]; then\n echo \"Instabug: PROJECT_DIR not found in Xcode build settings, skipping sourcemap upload\"\n exit 0\nfi\n\nPLIST_ABS_PATH=\"$PROJECT_DIR/$INFOPLIST_FILE\"\necho \"Instabug: PLIST_ABS_PATH: $PLIST_ABS_PATH\"\n\nif [ ! \"${INSTABUG_APP_TOKEN}\" ] || [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n echo \"Instabug: Looking for Token...\"\n INSTABUG_APP_TOKEN=$(grep -r -A 6 --exclude-dir={node_modules,ios,android} --exclude='*.json' \"Instabug.init({\" ./ -m1 | grep \"token:[[:space:]]*[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | grep -o \"[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | cut -d \"\\\"\" -f 2 | cut -d \"'\" -f 2)\n if [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} --exclude='*.json' \"Instabug.start[WithToken]*([\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" ./ -m 1 | grep -o \"[\\\"\\'][0-9a-zA-Z]*[\\\"\\']\" | cut -d \"\\\"\" -f 2 | cut -d \"'\" -f 2)\n fi\nfi\n\nif [ ! \"${INSTABUG_APP_TOKEN}\" ] || [ -z \"${INSTABUG_APP_TOKEN}\" ]; then\n echo \"Instabug: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.init Or added the environment variable INSTABUG_APP_TOKEN\"\n exit 0\nelse\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n INSTABUG_APP_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' ${PLIST_ABS_PATH} )\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n echo \"CFBundleVersion could not be found, please upload the sourcemap files manually\"\n exit 0\n fi\n INSTABUG_APP_VERSION_CODE_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_CODE | cut -d \"(\" -f2 | cut -d \")\" -f1)\n if !([ ! \"${INSTABUG_APP_VERSION_CODE_ENV}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE_ENV}\" ]); then\n INSTABUG_APP_VERSION_CODE=${!INSTABUG_APP_VERSION_CODE_ENV}\n if [ ! \"${INSTABUG_APP_VERSION_CODE}\" ] || [ -z \"${INSTABUG_APP_VERSION_CODE}\" ]; then\n echo \"Environment variable $INSTABUG_APP_VERSION_CODE_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually\" \n exit 0\n fi\n fi\n fi\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n INSTABUG_APP_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' ${PLIST_ABS_PATH} )\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n echo \"CFBundleShortVersionString could not be found, please upload the sourcemap files manually\"\n exit 0\n fi\n INSTABUG_APP_VERSION_NAME_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_NAME | cut -d \"(\" -f2 | cut -d \")\" -f1)\n if !([ ! \"${INSTABUG_APP_VERSION_NAME_ENV}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME_ENV}\" ]); then\n INSTABUG_APP_VERSION_NAME=${!INSTABUG_APP_VERSION_NAME_ENV}\n if [ ! \"${INSTABUG_APP_VERSION_NAME}\" ] || [ -z \"${INSTABUG_APP_VERSION_NAME}\" ]; then\n echo \"Environment variable $INSTABUG_APP_VERSION_NAME_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually\" \n exit 0\n fi\n fi\n fi\n if [ -z \"${INSTABUG_ENTRY_FILE}\" ]; then \n ENTRY_FILE='index.js'\n else \n ENTRY_FILE=${INSTABUG_ENTRY_FILE}\n fi\n if [ ! -f $ENTRY_FILE ]; then\n echo \"Instabug: err: entry file not found. Make sure\" \"\\\"${ENTRY_FILE}\\\"\" \"exists in your projects root directory. Or add the environment variable INSTABUG_ENTRY_FILE with the name of your entry file\"\n exit 0\n fi\n VERSION='{\"code\":\"'\"$INSTABUG_APP_VERSION_CODE\"'\",\"name\":\"'\"$INSTABUG_APP_VERSION_NAME\"'\"}'\n echo \"Instabug: Token:\" \"\\\"\"${INSTABUG_APP_TOKEN}\"\\\"\"\n echo \"Instabug: VERSION: $VERSION\"\n echo \"Instabug: Entry file found\" \"\\\"\"${ENTRY_FILE}\"\\\"\"\n echo \"Instabug: Generating sourcemap files...\"\n HERMES_ENABLED=$(grep hermes-engine ./ios/Podfile.lock -m 1)\n INSTALLED_RN_VERSION_MAJOR=$(node -p \"require('react-native/package.json').version\" | cut -d \".\" -f2)\n if [[ ! -z \"$HERMES_ENABLED\" && \"$INSTALLED_RN_VERSION_MAJOR\" -ge 65 && \"$INSTALLED_RN_VERSION_MAJOR\" -lt 70 ]]; then\n EXTRA_ARGS=\"--minify false\"\n fi\n #Generate ios sourcemap\n npx react-native bundle --platform ios \\\n --reset-cache \\\n --entry-file $ENTRY_FILE \\\n --dev false \\\n --bundle-output ./ios/main.jsbundle \\\n --sourcemap-output ./ios-sourcemap.json \\\n $EXTRA_ARGS\n \n echo \"Instabug: Uploading files...\"\n #Upload ios sourcemap\n curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F \"app_version=${VERSION}\" -F \"symbols_file=@./ios-sourcemap.json\" -F \"application_token=${INSTABUG_APP_TOKEN}\" -F \"platform=react_native\" -F \"os=ios\" \n rm -rf ios-sourcemap.json\n echo \nfi\n"; + shellScript = "#!/bin/sh\n\nif [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload'\n exit 0\nfi\n\nif [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo '[Instabug] Sourcemaps script must be invoked by Xcode'\n exit 1\nfi\n\n\n## App Token ##\n\nJS_PROJECT_DIR=\"$PROJECT_DIR/..\"\nINSTABUG_DIR=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\nINFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh)\nAPP_TOKEN=\"${INSTABUG_APP_TOKEN:-$INFERRED_TOKEN}\"\n\nif [ -z \"$APP_TOKEN\" ]; then\n echo '[Instabug] Failed to find Instabug App Token! Set the enviroment variable `INSTABUG_APP_TOKEN`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Version Code ##\n\nINFERRED_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\nVERSION_CODE=\"${INSTABUG_APP_VERSION_CODE:-$INFERRED_VERSION_CODE}\"\n\nif [ -z \"$VERSION_CODE\" ]; then\n echo '[Instabug] Failed to find Version Code! Set the enviroment variable `INSTABUG_APP_VERSION_CODE`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Version Name ##\n\nINFERRED_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\nVERSION_NAME=\"${INSTABUG_APP_VERSION_NAME:-$INFERRED_VERSION_NAME}\"\n\nif [ -z \"$VERSION_NAME\" ]; then\n echo '[Instabug] Failed to find Version Name! Set the enviroment variable `INSTABUG_APP_VERSION_NAME`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Generate Sourcemap ##\n\nREACT_NATIVE_DIR=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n# Force generating sourcemap file in Debug configuration\n# This is intentionaly made to not break expected behaviour in previous versions.\nexport FORCE_BUNDLING=true\n\n# Fixes an issue with react-native prior to v0.67.0\n# For more info: https://github.com/facebook/react-native/issues/32168\nexport RN_DIR=$REACT_NATIVE_DIR \n\n# Used withing `react-native-xcode.sh` to generate sourcemap file\nexport SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\nsource \"$REACT_NATIVE_DIR/scripts/react-native-xcode.sh\"\n\n\n## Upload Sourcemap ##\n\nnpx instabug upload-sourcemaps \\\n --platform ios \\\n --token $APP_TOKEN \\\n --name $VERSION_NAME \\\n --code $VERSION_CODE \\\n --file $SOURCEMAP_FILE\n"; }; DD1AA4DBFEAB75A854826F0C /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh new file mode 100644 index 0000000000..73c762b7d1 --- /dev/null +++ b/ios/sourcemaps.sh @@ -0,0 +1,74 @@ +#!/bin/sh + +if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then + echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload' + exit 0 +fi + +if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then + echo '[Instabug] Sourcemaps script must be invoked by Xcode' + exit 1 +fi + + +## App Token ## + +JS_PROJECT_DIR="$PROJECT_DIR/.." +INSTABUG_DIR=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) +INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh) +APP_TOKEN="${INSTABUG_APP_TOKEN:-$INFERRED_TOKEN}" + +if [[ -z "$APP_TOKEN" ]]; then + echo '[Instabug] Failed to find Instabug App Token! Set the enviroment variable `INSTABUG_APP_TOKEN`, to enable automatic sourcemap file uploads' + exit 1 +fi + + +## Version Code ## + +INFERRED_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") +VERSION_CODE="${INSTABUG_APP_VERSION_CODE:-$INFERRED_VERSION_CODE}" + +if [[ -z "$VERSION_CODE" ]]; then + echo '[Instabug] Failed to find Version Code! Set the enviroment variable `INSTABUG_APP_VERSION_CODE`, to enable automatic sourcemap file uploads' + exit 1 +fi + + +## Version Name ## + +INFERRED_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") +VERSION_NAME="${INSTABUG_APP_VERSION_NAME:-$INFERRED_VERSION_NAME}" + +if [[ -z "$VERSION_NAME" ]]; then + echo '[Instabug] Failed to find Version Name! Set the enviroment variable `INSTABUG_APP_VERSION_NAME`, to enable automatic sourcemap file uploads' + exit 1 +fi + + +## Generate Sourcemap ## + +REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) + +# Fixes an issue with react-native prior to v0.67.0 +# For more info: https://github.com/facebook/react-native/issues/32168 +export RN_DIR=$REACT_NATIVE_DIR + +# Force generating sourcemap file in Debug configuration +# This is intentionaly made to not break expected behaviour in previous versions. +export FORCE_BUNDLING=true + +# Used withing `react-native-xcode.sh` to generate sourcemap file +export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; + +source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" + + +## Upload Sourcemap ## + +npx instabug upload-sourcemaps \ + --platform ios \ + --token $APP_TOKEN \ + --name $VERSION_NAME \ + --code $VERSION_CODE \ + --file $SOURCEMAP_FILE diff --git a/ios/upload_sourcemap.sh b/ios/upload_sourcemap.sh deleted file mode 100644 index 967e443ae5..0000000000 --- a/ios/upload_sourcemap.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/sh -cd ${PROJECT_DIR} -cd .. -if [ -s "$HOME/.nvm/nvm.sh" ]; then -. "$HOME/.nvm/nvm.sh" -elif [ -x "$(command -v brew)" ] && [ -s "$(brew --prefix nvm)/nvm.sh" ]; then -. "$(brew --prefix nvm)/nvm.sh" -fi -export NODE_BINARY=node - -INSTABUG_SOURCEMAPS_UPLOAD_DISABLE=$(echo $INSTABUG_SOURCEMAPS_UPLOAD_DISABLE | tr 'A-Z' 'a-z') -if [ "${INSTABUG_SOURCEMAPS_UPLOAD_DISABLE}" = "true" ]; then - echo "Instabug: Environment variable INSTABUG_SOURCEMAPS_UPLOAD_DISABLE was set to true, skipping sourcemap upload" - exit 0 -fi - -if [ ! "$INFOPLIST_FILE" ] || [ -z "$INFOPLIST_FILE" ]; then - echo "Instabug: INFOPLIST_FILE not found in Xcode build settings, skipping sourcemap upload" - exit 0 -fi - -if [ ! "${PROJECT_DIR}" ] || [ -z "${PROJECT_DIR}" ]; then - echo "Instabug: PROJECT_DIR not found in Xcode build settings, skipping sourcemap upload" - exit 0 -fi - -PLIST_ABS_PATH="$PROJECT_DIR/$INFOPLIST_FILE" -echo "Instabug: PLIST_ABS_PATH: $PLIST_ABS_PATH" - -if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ]; then - echo "Instabug: Looking for Token..." - INSTABUG_APP_TOKEN=$(grep -r -A 6 --exclude-dir={node_modules,ios,android} --exclude='*.json' "Instabug.init({" ./ -m1 | grep "token:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2) - if [ -z "${INSTABUG_APP_TOKEN}" ]; then - INSTABUG_APP_TOKEN=$(grep -r --exclude-dir={node_modules,ios,android} --exclude='*.json' "Instabug.start[WithToken]*([\"\'][0-9a-zA-Z]*[\"\']" ./ -m 1 | grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2) - fi -fi - -if [ ! "${INSTABUG_APP_TOKEN}" ] || [ -z "${INSTABUG_APP_TOKEN}" ]; then - echo "Instabug: INSTABUG_APP_TOKEN not found. Make sure you've added the SDK initialization line Instabug.init Or added the environment variable INSTABUG_APP_TOKEN" - exit 0 -else - if [ ! "${INSTABUG_APP_VERSION_CODE}" ] || [ -z "${INSTABUG_APP_VERSION_CODE}" ]; then - INSTABUG_APP_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' ${PLIST_ABS_PATH} ) - if [ ! "${INSTABUG_APP_VERSION_CODE}" ] || [ -z "${INSTABUG_APP_VERSION_CODE}" ]; then - echo "CFBundleVersion could not be found, please upload the sourcemap files manually" - exit 0 - fi - INSTABUG_APP_VERSION_CODE_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_CODE | cut -d "(" -f2 | cut -d ")" -f1) - if !([ ! "${INSTABUG_APP_VERSION_CODE_ENV}" ] || [ -z "${INSTABUG_APP_VERSION_CODE_ENV}" ]); then - INSTABUG_APP_VERSION_CODE=${!INSTABUG_APP_VERSION_CODE_ENV} - if [ ! "${INSTABUG_APP_VERSION_CODE}" ] || [ -z "${INSTABUG_APP_VERSION_CODE}" ]; then - echo "Environment variable $INSTABUG_APP_VERSION_CODE_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually" - exit 0 - fi - fi - fi - if [ ! "${INSTABUG_APP_VERSION_NAME}" ] || [ -z "${INSTABUG_APP_VERSION_NAME}" ]; then - INSTABUG_APP_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' ${PLIST_ABS_PATH} ) - if [ ! "${INSTABUG_APP_VERSION_NAME}" ] || [ -z "${INSTABUG_APP_VERSION_NAME}" ]; then - echo "CFBundleShortVersionString could not be found, please upload the sourcemap files manually" - exit 0 - fi - INSTABUG_APP_VERSION_NAME_ENV=$(grep -o '$(.*)' <<< $INSTABUG_APP_VERSION_NAME | cut -d "(" -f2 | cut -d ")" -f1) - if !([ ! "${INSTABUG_APP_VERSION_NAME_ENV}" ] || [ -z "${INSTABUG_APP_VERSION_NAME_ENV}" ]); then - INSTABUG_APP_VERSION_NAME=${!INSTABUG_APP_VERSION_NAME_ENV} - if [ ! "${INSTABUG_APP_VERSION_NAME}" ] || [ -z "${INSTABUG_APP_VERSION_NAME}" ]; then - echo "Environment variable $INSTABUG_APP_VERSION_NAME_ENV was specified inside Info.plist but was not found, please upload the sourcemap files manually" - exit 0 - fi - fi - fi - if [ -z "${INSTABUG_ENTRY_FILE}" ]; then - ENTRY_FILE='index.js' - else - ENTRY_FILE=${INSTABUG_ENTRY_FILE} - fi - if [ ! -f $ENTRY_FILE ]; then - echo "Instabug: err: entry file not found. Make sure" "\"${ENTRY_FILE}\"" "exists in your projects root directory. Or add the environment variable INSTABUG_ENTRY_FILE with the name of your entry file" - exit 0 - fi - VERSION='{"code":"'"$INSTABUG_APP_VERSION_CODE"'","name":"'"$INSTABUG_APP_VERSION_NAME"'"}' - echo "Instabug: Token:" "\""${INSTABUG_APP_TOKEN}"\"" - echo "Instabug: VERSION: $VERSION" - echo "Instabug: Entry file found" "\""${ENTRY_FILE}"\"" - echo "Instabug: Generating sourcemap files..." - HERMES_ENABLED=$(grep hermes-engine ./ios/Podfile.lock -m 1) - INSTALLED_RN_VERSION_MAJOR=$(node -p "require('react-native/package.json').version" | cut -d "." -f2) - if [[ ! -z "$HERMES_ENABLED" && "$INSTALLED_RN_VERSION_MAJOR" -ge 65 && "$INSTALLED_RN_VERSION_MAJOR" -lt 70 ]]; then - EXTRA_ARGS="--minify false" - fi - #Generate ios sourcemap - npx react-native bundle --platform ios \ - --reset-cache \ - --entry-file $ENTRY_FILE \ - --dev false \ - --bundle-output ./ios/main.jsbundle \ - --sourcemap-output ./ios-sourcemap.json \ - $EXTRA_ARGS - - echo "Instabug: Uploading files..." - #Upload ios sourcemap - curl -X POST 'https://api.instabug.com/api/sdk/v3/symbols_files' -F "app_version=${VERSION}" -F "symbols_file=@./ios-sourcemap.json" -F "application_token=${INSTABUG_APP_TOKEN}" -F "platform=react_native" -F "os=ios" - rm -rf ios-sourcemap.json - echo -fi diff --git a/react-native.config.js b/react-native.config.js index 979c09de5b..84e3947e55 100644 --- a/react-native.config.js +++ b/react-native.config.js @@ -5,7 +5,7 @@ module.exports = { scriptPhases: [ { name: '[instabug-reactnative] Upload Sourcemap', - path: './ios/upload_sourcemap.sh', + path: './ios/sourcemaps.sh', execution_position: 'after_compile', }, ], From b974ead5fb1a4cadd68268133c21fc08bfc431ff Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Tue, 28 Mar 2023 13:01:16 +0200 Subject: [PATCH 2/8] Remove Force Run on Debug Builds --- CHANGELOG.md | 1 + ios/sourcemaps.sh | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf1e0b93c1..064ac0394d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Changed - Improve release variant's build time on Android, by using the react-native-generated source map file, instead of generating it within our scripts ([#938](https://github.com/Instabug/Instabug-React-Native/pull/938)). +- Improve debug variant's build time on iOS, by disabling automatic source map file uploads ([#942](https://github.com/Instabug/Instabug-React-Native/pull/942)). ## [11.9.1](https://github.com/Instabug/Instabug-React-Native/compare/v11.9.0...v11.9.1) (March 01, 2023) diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 73c762b7d1..f7c5dc7371 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -54,10 +54,6 @@ REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json # For more info: https://github.com/facebook/react-native/issues/32168 export RN_DIR=$REACT_NATIVE_DIR -# Force generating sourcemap file in Debug configuration -# This is intentionaly made to not break expected behaviour in previous versions. -export FORCE_BUNDLING=true - # Used withing `react-native-xcode.sh` to generate sourcemap file export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; From 8d59541b40b4ba037a171931cc8b8113a0dfe57e Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Tue, 28 Mar 2023 15:09:54 +0200 Subject: [PATCH 3/8] Change Resolving Order --- ios/sourcemaps.sh | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index f7c5dc7371..2972986967 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -11,6 +11,24 @@ if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then fi +## Generate Sourcemap ## + +REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) + +# Fixes an issue with react-native prior to v0.67.0 +# For more info: https://github.com/facebook/react-native/issues/32168 +export RN_DIR=$REACT_NATIVE_DIR + +# Used withing `react-native-xcode.sh` to generate sourcemap file +export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; + +source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" + +if ![[ -f "$SOURCEMAP_FILE" ]]; then + echo "Unable to find source map file at: $SOURCEMAP_FILE" +fi + + ## App Token ## JS_PROJECT_DIR="$PROJECT_DIR/.." @@ -46,25 +64,11 @@ if [[ -z "$VERSION_NAME" ]]; then fi -## Generate Sourcemap ## - -REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) - -# Fixes an issue with react-native prior to v0.67.0 -# For more info: https://github.com/facebook/react-native/issues/32168 -export RN_DIR=$REACT_NATIVE_DIR - -# Used withing `react-native-xcode.sh` to generate sourcemap file -export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; - -source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" - - ## Upload Sourcemap ## npx instabug upload-sourcemaps \ --platform ios \ + --file $SOURCEMAP_FILE \ --token $APP_TOKEN \ --name $VERSION_NAME \ - --code $VERSION_CODE \ - --file $SOURCEMAP_FILE + --code $VERSION_CODE From b4df0ca8b9ad7f864ec00fdbab266a8d5df9d131 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Wed, 29 Mar 2023 04:55:03 +0200 Subject: [PATCH 4/8] Create `resolve_var` Function --- ios/sourcemaps.sh | 61 ++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 2972986967..758e5b5d21 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -1,5 +1,28 @@ #!/bin/sh +resolve_var() { + local name=$1 + local env_key=$2 + local default_value=$3 + + local env_value="${!env_key}" + + if [[ -n "$env_value" ]] && [[ "$env_value" != default_value ]]; then + echo "Environment variable \`$env_key\` might have incorrect value, make sure this was intentional:" + echo " Environment Value: $env_value" + echo " Default Value: $default_value" + fi + + local value="${env_value:-$default_value}" + + if [[ -z "$value" ]]; then + echo "Unable to find $name! Set the environment variable \`$env_key\` and try again." + exit 1 + fi + + echo $value +} + if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload' exit 0 @@ -10,7 +33,6 @@ if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then exit 1 fi - ## Generate Sourcemap ## REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) @@ -28,43 +50,16 @@ if ![[ -f "$SOURCEMAP_FILE" ]]; then echo "Unable to find source map file at: $SOURCEMAP_FILE" fi - -## App Token ## - JS_PROJECT_DIR="$PROJECT_DIR/.." INSTABUG_DIR=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh) -APP_TOKEN="${INSTABUG_APP_TOKEN:-$INFERRED_TOKEN}" - -if [[ -z "$APP_TOKEN" ]]; then - echo '[Instabug] Failed to find Instabug App Token! Set the enviroment variable `INSTABUG_APP_TOKEN`, to enable automatic sourcemap file uploads' - exit 1 -fi - - -## Version Code ## - -INFERRED_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") -VERSION_CODE="${INSTABUG_APP_VERSION_CODE:-$INFERRED_VERSION_CODE}" - -if [[ -z "$VERSION_CODE" ]]; then - echo '[Instabug] Failed to find Version Code! Set the enviroment variable `INSTABUG_APP_VERSION_CODE`, to enable automatic sourcemap file uploads' - exit 1 -fi - - -## Version Name ## - -INFERRED_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") -VERSION_NAME="${INSTABUG_APP_VERSION_NAME:-$INFERRED_VERSION_NAME}" - -if [[ -z "$VERSION_NAME" ]]; then - echo '[Instabug] Failed to find Version Name! Set the enviroment variable `INSTABUG_APP_VERSION_NAME`, to enable automatic sourcemap file uploads' - exit 1 -fi +APP_TOKEN=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$INFERRED_TOKEN" | tail -n 1) +INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") +VERSION_NAME=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$INFERRED_NAME" | tail -n 1) -## Upload Sourcemap ## +INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") +VERSION_CODE=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$INFERRED_CODE" | tail -n 1) npx instabug upload-sourcemaps \ --platform ios \ From 7022f5aa48940292e90662b5c08e984dfe20a8ab Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Wed, 29 Mar 2023 05:07:38 +0200 Subject: [PATCH 5/8] Create Functions --- ios/sourcemaps.sh | 95 +++++++++++++++++++++++++---------------------- 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 758e5b5d21..95aba568aa 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -1,5 +1,55 @@ #!/bin/sh +main() { + if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then + echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload' + exit 0 + fi + + if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then + echo '[Instabug] Sourcemaps script must be invoked by Xcode' + exit 1 + fi + + generate_sourcemaps + + JS_PROJECT_DIR="$PROJECT_DIR/.." + INSTABUG_DIR=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) + INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh) + APP_TOKEN=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$INFERRED_TOKEN" | tail -n 1) + + INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") + VERSION_NAME=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$INFERRED_NAME" | tail -n 1) + + INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") + VERSION_CODE=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$INFERRED_CODE" | tail -n 1) + + npx instabug upload-sourcemaps \ + --platform ios \ + --file $SOURCEMAP_FILE \ + --token $APP_TOKEN \ + --name $VERSION_NAME \ + --code $VERSION_CODE +} + +generate_sourcemaps() { + REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) + + # Fixes an issue with react-native prior to v0.67.0 + # For more info: https://github.com/facebook/react-native/issues/32168 + export RN_DIR=$REACT_NATIVE_DIR + + # Used withing `react-native-xcode.sh` to generate sourcemap file + export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; + + source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" + + if ![[ -f "$SOURCEMAP_FILE" ]]; then + echo "Unable to find source map file at: $SOURCEMAP_FILE" + exit 1 + fi +} + resolve_var() { local name=$1 local env_key=$2 @@ -23,47 +73,4 @@ resolve_var() { echo $value } -if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then - echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload' - exit 0 -fi - -if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then - echo '[Instabug] Sourcemaps script must be invoked by Xcode' - exit 1 -fi - -## Generate Sourcemap ## - -REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) - -# Fixes an issue with react-native prior to v0.67.0 -# For more info: https://github.com/facebook/react-native/issues/32168 -export RN_DIR=$REACT_NATIVE_DIR - -# Used withing `react-native-xcode.sh` to generate sourcemap file -export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; - -source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" - -if ![[ -f "$SOURCEMAP_FILE" ]]; then - echo "Unable to find source map file at: $SOURCEMAP_FILE" -fi - -JS_PROJECT_DIR="$PROJECT_DIR/.." -INSTABUG_DIR=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) -INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh) -APP_TOKEN=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$INFERRED_TOKEN" | tail -n 1) - -INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") -VERSION_NAME=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$INFERRED_NAME" | tail -n 1) - -INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") -VERSION_CODE=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$INFERRED_CODE" | tail -n 1) - -npx instabug upload-sourcemaps \ - --platform ios \ - --file $SOURCEMAP_FILE \ - --token $APP_TOKEN \ - --name $VERSION_NAME \ - --code $VERSION_CODE +main "$@"; exit From 601312f44e4c8540b445803a76efb06f6a401a13 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Wed, 29 Mar 2023 05:12:38 +0200 Subject: [PATCH 6/8] Add Log Levels --- ios/sourcemaps.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 95aba568aa..147c6b08c7 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -2,12 +2,12 @@ main() { if [[ "$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE" = true ]]; then - echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload' + echo "[Info] \`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\` was set to true, skipping sourcemaps upload..." exit 0 fi if [[ -z "$INFOPLIST_FILE" ]] || [[ -z "$PROJECT_DIR" ]]; then - echo '[Instabug] Sourcemaps script must be invoked by Xcode' + echo "[Error] Instabug sourcemaps script must be invoked by Xcode" exit 1 fi @@ -45,7 +45,7 @@ generate_sourcemaps() { source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" if ![[ -f "$SOURCEMAP_FILE" ]]; then - echo "Unable to find source map file at: $SOURCEMAP_FILE" + echo "[Error] Unable to find source map file at: $SOURCEMAP_FILE" exit 1 fi } @@ -58,7 +58,7 @@ resolve_var() { local env_value="${!env_key}" if [[ -n "$env_value" ]] && [[ "$env_value" != default_value ]]; then - echo "Environment variable \`$env_key\` might have incorrect value, make sure this was intentional:" + echo "[Warning] Environment variable \`$env_key\` might have incorrect value, make sure this was intentional:" echo " Environment Value: $env_value" echo " Default Value: $default_value" fi @@ -66,7 +66,7 @@ resolve_var() { local value="${env_value:-$default_value}" if [[ -z "$value" ]]; then - echo "Unable to find $name! Set the environment variable \`$env_key\` and try again." + echo "[Error] Unable to find $name! Set the environment variable \`$env_key\` and try again." exit 1 fi From 900cb0d673bf9f05fd316543ba2c72bfeac2107b Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Wed, 29 Mar 2023 05:13:37 +0200 Subject: [PATCH 7/8] Sync Project File --- examples/default/ios/InstabugExample.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj index 3edf4947df..5bca47f3e8 100644 --- a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj +++ b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj @@ -401,7 +401,7 @@ name = "[CP-User] [instabug-reactnative] Upload Sourcemap"; runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "#!/bin/sh\n\nif [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo 'Instabug: `INSTABUG_SOURCEMAPS_UPLOAD_DISABLE` was set to true, skipping sourcemap upload'\n exit 0\nfi\n\nif [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo '[Instabug] Sourcemaps script must be invoked by Xcode'\n exit 1\nfi\n\n\n## App Token ##\n\nJS_PROJECT_DIR=\"$PROJECT_DIR/..\"\nINSTABUG_DIR=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\nINFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh)\nAPP_TOKEN=\"${INSTABUG_APP_TOKEN:-$INFERRED_TOKEN}\"\n\nif [ -z \"$APP_TOKEN\" ]; then\n echo '[Instabug] Failed to find Instabug App Token! Set the enviroment variable `INSTABUG_APP_TOKEN`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Version Code ##\n\nINFERRED_VERSION_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\nVERSION_CODE=\"${INSTABUG_APP_VERSION_CODE:-$INFERRED_VERSION_CODE}\"\n\nif [ -z \"$VERSION_CODE\" ]; then\n echo '[Instabug] Failed to find Version Code! Set the enviroment variable `INSTABUG_APP_VERSION_CODE`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Version Name ##\n\nINFERRED_VERSION_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\nVERSION_NAME=\"${INSTABUG_APP_VERSION_NAME:-$INFERRED_VERSION_NAME}\"\n\nif [ -z \"$VERSION_NAME\" ]; then\n echo '[Instabug] Failed to find Version Name! Set the enviroment variable `INSTABUG_APP_VERSION_NAME`, to enable automatic sourcemap file uploads'\n exit 1\nfi\n\n\n## Generate Sourcemap ##\n\nREACT_NATIVE_DIR=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n# Force generating sourcemap file in Debug configuration\n# This is intentionaly made to not break expected behaviour in previous versions.\nexport FORCE_BUNDLING=true\n\n# Fixes an issue with react-native prior to v0.67.0\n# For more info: https://github.com/facebook/react-native/issues/32168\nexport RN_DIR=$REACT_NATIVE_DIR \n\n# Used withing `react-native-xcode.sh` to generate sourcemap file\nexport SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\nsource \"$REACT_NATIVE_DIR/scripts/react-native-xcode.sh\"\n\n\n## Upload Sourcemap ##\n\nnpx instabug upload-sourcemaps \\\n --platform ios \\\n --token $APP_TOKEN \\\n --name $VERSION_NAME \\\n --code $VERSION_CODE \\\n --file $SOURCEMAP_FILE\n"; + shellScript = "#!/bin/sh\n\nmain() {\n if [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo \"[Info] \\`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\\` was set to true, skipping sourcemaps upload...\"\n exit 0\n fi\n\n if [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo \"[Error] Instabug sourcemaps script must be invoked by Xcode\"\n exit 1\n fi\n\n generate_sourcemaps\n\n JS_PROJECT_DIR=\"$PROJECT_DIR/..\"\n INSTABUG_DIR=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\n INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh)\n APP_TOKEN=$(resolve_var \"App Token\" \"INSTABUG_APP_TOKEN\" \"$INFERRED_TOKEN\" | tail -n 1)\n\n INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n VERSION_NAME=$(resolve_var \"Version Name\" \"INSTABUG_APP_VERSION_NAME\" \"$INFERRED_NAME\" | tail -n 1)\n\n INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n VERSION_CODE=$(resolve_var \"Version Code\" \"INSTABUG_APP_VERSION_CODE\" \"$INFERRED_CODE\" | tail -n 1)\n\n npx instabug upload-sourcemaps \\\n --platform ios \\\n --file $SOURCEMAP_FILE \\\n --token $APP_TOKEN \\\n --name $VERSION_NAME \\\n --code $VERSION_CODE\n}\n\ngenerate_sourcemaps() {\n REACT_NATIVE_DIR=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n # Fixes an issue with react-native prior to v0.67.0\n # For more info: https://github.com/facebook/react-native/issues/32168\n export RN_DIR=$REACT_NATIVE_DIR \n\n # Used withing `react-native-xcode.sh` to generate sourcemap file\n export SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\n source \"$REACT_NATIVE_DIR/scripts/react-native-xcode.sh\"\n\n if ![[ -f \"$SOURCEMAP_FILE\" ]]; then\n echo \"[Error] Unable to find source map file at: $SOURCEMAP_FILE\"\n exit 1\n fi\n}\n\nresolve_var() {\n local name=$1\n local env_key=$2\n local default_value=$3\n\n local env_value=\"${!env_key}\"\n\n if [[ -n \"$env_value\" ]] && [[ \"$env_value\" != default_value ]]; then\n echo \"[Warning] Environment variable \\`$env_key\\` might have incorrect value, make sure this was intentional:\"\n echo \" Environment Value: $env_value\"\n echo \" Default Value: $default_value\"\n fi\n\n local value=\"${env_value:-$default_value}\"\n\n if [[ -z \"$value\" ]]; then\n echo \"[Error] Unable to find $name! Set the environment variable \\`$env_key\\` and try again.\"\n exit 1\n fi\n\n echo $value\n}\n\nmain \"$@\"; exit\n"; }; DD1AA4DBFEAB75A854826F0C /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; From 5863e89b5b75428d29f9b61349f407e6f2307450 Mon Sep 17 00:00:00 2001 From: Youssef Raafat Date: Wed, 29 Mar 2023 11:24:27 +0200 Subject: [PATCH 8/8] Localize Variables --- .../InstabugExample.xcodeproj/project.pbxproj | 2 +- ios/sourcemaps.sh | 36 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj index 5bca47f3e8..429442655b 100644 --- a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj +++ b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj @@ -401,7 +401,7 @@ name = "[CP-User] [instabug-reactnative] Upload Sourcemap"; runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "#!/bin/sh\n\nmain() {\n if [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo \"[Info] \\`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\\` was set to true, skipping sourcemaps upload...\"\n exit 0\n fi\n\n if [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo \"[Error] Instabug sourcemaps script must be invoked by Xcode\"\n exit 1\n fi\n\n generate_sourcemaps\n\n JS_PROJECT_DIR=\"$PROJECT_DIR/..\"\n INSTABUG_DIR=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\n INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh)\n APP_TOKEN=$(resolve_var \"App Token\" \"INSTABUG_APP_TOKEN\" \"$INFERRED_TOKEN\" | tail -n 1)\n\n INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n VERSION_NAME=$(resolve_var \"Version Name\" \"INSTABUG_APP_VERSION_NAME\" \"$INFERRED_NAME\" | tail -n 1)\n\n INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n VERSION_CODE=$(resolve_var \"Version Code\" \"INSTABUG_APP_VERSION_CODE\" \"$INFERRED_CODE\" | tail -n 1)\n\n npx instabug upload-sourcemaps \\\n --platform ios \\\n --file $SOURCEMAP_FILE \\\n --token $APP_TOKEN \\\n --name $VERSION_NAME \\\n --code $VERSION_CODE\n}\n\ngenerate_sourcemaps() {\n REACT_NATIVE_DIR=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n # Fixes an issue with react-native prior to v0.67.0\n # For more info: https://github.com/facebook/react-native/issues/32168\n export RN_DIR=$REACT_NATIVE_DIR \n\n # Used withing `react-native-xcode.sh` to generate sourcemap file\n export SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\n source \"$REACT_NATIVE_DIR/scripts/react-native-xcode.sh\"\n\n if ![[ -f \"$SOURCEMAP_FILE\" ]]; then\n echo \"[Error] Unable to find source map file at: $SOURCEMAP_FILE\"\n exit 1\n fi\n}\n\nresolve_var() {\n local name=$1\n local env_key=$2\n local default_value=$3\n\n local env_value=\"${!env_key}\"\n\n if [[ -n \"$env_value\" ]] && [[ \"$env_value\" != default_value ]]; then\n echo \"[Warning] Environment variable \\`$env_key\\` might have incorrect value, make sure this was intentional:\"\n echo \" Environment Value: $env_value\"\n echo \" Default Value: $default_value\"\n fi\n\n local value=\"${env_value:-$default_value}\"\n\n if [[ -z \"$value\" ]]; then\n echo \"[Error] Unable to find $name! Set the environment variable \\`$env_key\\` and try again.\"\n exit 1\n fi\n\n echo $value\n}\n\nmain \"$@\"; exit\n"; + shellScript = "#!/bin/sh\n\nmain() {\n if [[ \"$INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\" = true ]]; then\n echo \"[Info] \\`INSTABUG_SOURCEMAPS_UPLOAD_DISABLE\\` was set to true, skipping sourcemaps upload...\"\n exit 0\n fi\n\n if [[ -z \"$INFOPLIST_FILE\" ]] || [[ -z \"$PROJECT_DIR\" ]]; then\n echo \"[Error] Instabug sourcemaps script must be invoked by Xcode\"\n exit 1\n fi\n\n local source_map_file=$(generate_sourcemaps | tail -n 1)\n\n local js_project_dir=\"$PROJECT_DIR/..\"\n local instabug_dir=$(dirname $(node -p \"require.resolve('instabug-reactnative/package.json')\"))\n local inferred_token=$(cd $js_project_dir && source $instabug_dir/scripts/find-token.sh)\n local app_token=$(resolve_var \"App Token\" \"INSTABUG_APP_TOKEN\" \"$inferred_token\" | tail -n 1)\n\n local inferred_name=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n local version_name=$(resolve_var \"Version Name\" \"INSTABUG_APP_VERSION_NAME\" \"$inferred_name\" | tail -n 1)\n\n local inferred_code=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' \"$PROJECT_DIR/$INFOPLIST_FILE\")\n local version_code=$(resolve_var \"Version Code\" \"INSTABUG_APP_VERSION_CODE\" \"$inferred_code\" | tail -n 1)\n\n npx instabug upload-sourcemaps \\\n --platform ios \\\n --file $source_map_file \\\n --token $app_token \\\n --name $version_name \\\n --code $version_code\n}\n\ngenerate_sourcemaps() {\n local react_native_dir=$(dirname $(node -p \"require.resolve('react-native/package.json')\"))\n\n # Fixes an issue with react-native prior to v0.67.0\n # For more info: https://github.com/facebook/react-native/issues/32168\n export RN_DIR=$react_native_dir \n\n # Used withing `react-native-xcode.sh` to generate sourcemap file\n export SOURCEMAP_FILE=\"$(pwd)/main.jsbundle.map\";\n\n source \"$react_native_dir/scripts/react-native-xcode.sh\"\n\n if [[ ! -f \"$SOURCEMAP_FILE\" ]]; then\n echo \"[Error] Unable to find source map file at: $SOURCEMAP_FILE\"\n exit 1\n fi\n\n echo $SOURCEMAP_FILE\n}\n\nresolve_var() {\n local name=$1\n local env_key=$2\n local default_value=$3\n\n local env_value=\"${!env_key}\"\n\n if [[ -n \"$env_value\" ]] && [[ \"$env_value\" != default_value ]]; then\n echo \"[Warning] Environment variable \\`$env_key\\` might have incorrect value, make sure this was intentional:\"\n echo \" Environment Value: $env_value\"\n echo \" Default Value: $default_value\"\n fi\n\n local value=\"${env_value:-$default_value}\"\n\n if [[ -z \"$value\" ]]; then\n echo \"[Error] Unable to find $name! Set the environment variable \\`$env_key\\` and try again.\"\n exit 1\n fi\n\n echo $value\n}\n\nmain \"$@\"; exit\n"; }; DD1AA4DBFEAB75A854826F0C /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 147c6b08c7..70b812ab65 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -11,43 +11,45 @@ main() { exit 1 fi - generate_sourcemaps + local source_map_file=$(generate_sourcemaps | tail -n 1) - JS_PROJECT_DIR="$PROJECT_DIR/.." - INSTABUG_DIR=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) - INFERRED_TOKEN=$(cd $JS_PROJECT_DIR && source $INSTABUG_DIR/scripts/find-token.sh) - APP_TOKEN=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$INFERRED_TOKEN" | tail -n 1) + local js_project_dir="$PROJECT_DIR/.." + local instabug_dir=$(dirname $(node -p "require.resolve('instabug-reactnative/package.json')")) + local inferred_token=$(cd $js_project_dir && source $instabug_dir/scripts/find-token.sh) + local app_token=$(resolve_var "App Token" "INSTABUG_APP_TOKEN" "$inferred_token" | tail -n 1) - INFERRED_NAME=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") - VERSION_NAME=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$INFERRED_NAME" | tail -n 1) + local inferred_name=$(/usr/libexec/PlistBuddy -c 'print CFBundleShortVersionString' "$PROJECT_DIR/$INFOPLIST_FILE") + local version_name=$(resolve_var "Version Name" "INSTABUG_APP_VERSION_NAME" "$inferred_name" | tail -n 1) - INFERRED_CODE=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") - VERSION_CODE=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$INFERRED_CODE" | tail -n 1) + local inferred_code=$(/usr/libexec/PlistBuddy -c 'print CFBundleVersion' "$PROJECT_DIR/$INFOPLIST_FILE") + local version_code=$(resolve_var "Version Code" "INSTABUG_APP_VERSION_CODE" "$inferred_code" | tail -n 1) npx instabug upload-sourcemaps \ --platform ios \ - --file $SOURCEMAP_FILE \ - --token $APP_TOKEN \ - --name $VERSION_NAME \ - --code $VERSION_CODE + --file $source_map_file \ + --token $app_token \ + --name $version_name \ + --code $version_code } generate_sourcemaps() { - REACT_NATIVE_DIR=$(dirname $(node -p "require.resolve('react-native/package.json')")) + local react_native_dir=$(dirname $(node -p "require.resolve('react-native/package.json')")) # Fixes an issue with react-native prior to v0.67.0 # For more info: https://github.com/facebook/react-native/issues/32168 - export RN_DIR=$REACT_NATIVE_DIR + export RN_DIR=$react_native_dir # Used withing `react-native-xcode.sh` to generate sourcemap file export SOURCEMAP_FILE="$(pwd)/main.jsbundle.map"; - source "$REACT_NATIVE_DIR/scripts/react-native-xcode.sh" + source "$react_native_dir/scripts/react-native-xcode.sh" - if ![[ -f "$SOURCEMAP_FILE" ]]; then + if [[ ! -f "$SOURCEMAP_FILE" ]]; then echo "[Error] Unable to find source map file at: $SOURCEMAP_FILE" exit 1 fi + + echo $SOURCEMAP_FILE } resolve_var() {