diff --git a/CHANGELOG.md b/CHANGELOG.md index 2287f66146..6ea151f208 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v13.0.5...dev) + +### Added + +- support reading `INSTABUG_APP_TOKEN` variable from env files in automatic sourcemap files uploading ([#1222](https://github.com/Instabug/Instabug-React-Native/pull/1222)) + ## [13.0.5](https://github.com/Instabug/Instabug-React-Native/compare/v13.0.4...v13.0.5) (May 18, 2024) ### Changed diff --git a/android/sourcemaps.gradle b/android/sourcemaps.gradle index f3fe5b59da..e0479643aa 100644 --- a/android/sourcemaps.gradle +++ b/android/sourcemaps.gradle @@ -38,8 +38,8 @@ Task createUploadSourcemapsTask(String flavor) { try { def appProject = project(':app') def appDir = appProject.projectDir - def flavorPath = flavor + (flavor.empty ? '' : '/') - def sourceMapDest = "build/generated/sourcemaps/react/${flavorPath}release/index.android.bundle.map" + def flavorPath = flavor + def sourceMapDest = "build/generated/sourcemaps/react/${flavorPath}${(flavor.empty ? 'release' : 'Release')}/index.android.bundle.map" def sourceMapFile = new File(appDir, sourceMapDest) if (!sourceMapFile.exists()) { @@ -90,15 +90,16 @@ boolean isUploadSourcemapsEnabled() { String resolveVar(String name, String envKey, String defaultValue) { def env = System.getenv() def envValue = env.get(envKey) + def projectEnv = project.findProperty(envKey) - if (envValue != null && envValue != defaultValue) { + if (envValue != null && defaultValue!=null && envValue != defaultValue) { project.logger.warn "Environment variable `${envKey}` might have incorrect value, " + "make sure this was intentional:\n" + " Environment Value: ${envValue}\n" + " Default Value: ${defaultValue}" } - def value = envValue ?: defaultValue + def value = envValue ?: projectEnv ?: defaultValue if (value == null) { throw new InvalidUserDataException("Unable to find ${name}! " + diff --git a/ios/sourcemaps.sh b/ios/sourcemaps.sh index 71de5fd5d9..cd98c87ad1 100644 --- a/ios/sourcemaps.sh +++ b/ios/sourcemaps.sh @@ -54,7 +54,7 @@ generate_sourcemaps() { # 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"; @@ -76,7 +76,7 @@ resolve_var() { local env_value="${!env_key}" - if [[ -n "$env_value" ]] && [[ "$env_value" != default_value ]]; then + if [[ -n "$env_value" ]] && [[ -n "$default_value" ]] && [[ "$env_value" != default_value ]]; then 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" diff --git a/scripts/find-token.sh b/scripts/find-token.sh index 3b162def9e..b2410ed2f8 100644 --- a/scripts/find-token.sh +++ b/scripts/find-token.sh @@ -1,14 +1,26 @@ #!/bin/sh # Searches for app token within source files. +JSON_APP_TOKEN=$( + grep "app_token" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=instabug.json ./ | + sed 's/ //g' | + grep -o ":[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d ":" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + if [ ! -z "${JSON_APP_TOKEN}" ]; then + echo JSON_APP_TOKEN + exit 0 + fi INIT_APP_TOKEN=$( grep "Instabug.init({" -r -A 6 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | grep "token:[[:space:]]*[\"\'][0-9a-zA-Z]*[\"\']" | grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${INIT_APP_TOKEN}" ]; then echo $INIT_APP_TOKEN @@ -20,12 +32,41 @@ START_APP_TOKEN=$( grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | cut -d "\"" -f 2 | cut -d "'" -f 2 -) +) if [ ! -z "${START_APP_TOKEN}" ]; then echo $START_APP_TOKEN exit 0 fi + + + +ENV_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.env ./ | + sed 's/ //g' | + grep -o "[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d "=" -f 2 +) + +if [ ! -z "${ENV_APP_TOKEN}" ]; then + echo $ENV_APP_TOKEN + exit 0 +fi + +CONSTASTS_APP_TOKEN=$( + grep "INSTABUG_APP_TOKEN" -r -A 1 -m 1 --exclude-dir={node_modules,ios,android} --include=\*.{js,ts,jsx,tsx} ./ | + sed 's/ //g' | + grep -o "=[\"\'][0-9a-zA-Z]*[\"\']" | + cut -d "=" -f 2 | + cut -d "\"" -f 2 | + cut -d "'" -f 2 +) + +if [ ! -z "${CONSTASTS_APP_TOKEN}" ]; then + echo $CONSTASTS_APP_TOKEN + exit 0 +fi + echo "Couldn't find Instabug's app token" exit 1