Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: read INSTABUG_APP_TOKEN from env in sourcemap uploading #1222

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
9 changes: 5 additions & 4 deletions android/sourcemaps.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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}! " +
Expand Down
4 changes: 2 additions & 2 deletions ios/sourcemaps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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"
Expand Down
45 changes: 43 additions & 2 deletions scripts/find-token.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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