From d47715e8f7c5a6f2e11a521fe9c11ed47b430c3d Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 15 Nov 2024 15:55:04 +0000 Subject: [PATCH 1/5] feat(plugin): Add support for `.env.sentry-build-plugin` --- .gitignore | 1 + CHANGELOG.md | 8 ++++++++ packages/core/scripts/expo-upload-sourcemaps.js | 16 ++++++++++++++++ .../core/scripts/sentry-xcode-debug-files.sh | 4 ++++ packages/core/scripts/sentry-xcode.sh | 4 ++++ packages/core/sentry.gradle | 3 +++ 6 files changed, 36 insertions(+) diff --git a/.gitignore b/.gitignore index 1419bce38d..1870007b3f 100644 --- a/.gitignore +++ b/.gitignore @@ -90,3 +90,4 @@ node_modules.bak # Sentry React Native Monorepo /packages/core/README.md +.env.sentry-build-plugin diff --git a/CHANGELOG.md b/CHANGELOG.md index 86370af132..f5c6a426db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,14 @@ export SENTRY_DISABLE_NATIVE_DEBUG_UPLOAD=true ``` +- Add support for `.env.sentry-build-plugin` ([#4281](https://github.com/getsentry/sentry-react-native/pull/4281)) + + Don't committing the file to your repository. Use it to set your Sentry Auth Token. + + ``` + SENTRY_AUTH_TOKEN=your_token_here + ``` + ### Fixes - Ignore JavascriptException to filter out obfuscated duplicate JS Errors on Android ([#4232](https://github.com/getsentry/sentry-react-native/pull/4232)) diff --git a/packages/core/scripts/expo-upload-sourcemaps.js b/packages/core/scripts/expo-upload-sourcemaps.js index 0f244f2ac1..997f2c84d3 100755 --- a/packages/core/scripts/expo-upload-sourcemaps.js +++ b/packages/core/scripts/expo-upload-sourcemaps.js @@ -102,6 +102,20 @@ function groupAssets(assetPaths) { return groups; } +function loadDotenv(dotenvPath) { + try { + const dotenvFile = fs.readFileSync(dotenvPath, 'utf-8'); + // NOTE: Do not use the dotenv.config API directly to read the dotenv file! For some ungodly reason, it falls back to reading `${process.cwd()}/.env` which is absolutely not what we want. + // dotenv is dependency of @expo/env, so we can just require it here + const dotenvResult = require('dotenv').parse(dotenvFile); + + Object.assign(process.env, dotenvResult); + } catch (error) { + console.warn('⚠️ Failed to load environment variables using dotenv.'); + console.warn(error); + } +} + process.env.NODE_ENV = process.env.NODE_ENV || 'development'; // Ensures precedence .env.development > .env (the same as @expo/cli) const projectRoot = '.'; // Assume script is run from the project root try { @@ -111,6 +125,8 @@ try { console.warn(error); } +loadDotenv(path.join(projectRoot, '.env.sentry-build-plugin')); + let sentryOrg = getEnvVar(SENTRY_ORG); let sentryUrl = getEnvVar(SENTRY_URL); let sentryProject = getEnvVar(SENTRY_PROJECT); diff --git a/packages/core/scripts/sentry-xcode-debug-files.sh b/packages/core/scripts/sentry-xcode-debug-files.sh index 60cca3661f..dc6e48aed7 100755 --- a/packages/core/scripts/sentry-xcode-debug-files.sh +++ b/packages/core/scripts/sentry-xcode-debug-files.sh @@ -17,7 +17,11 @@ set -e LOCAL_NODE_BINARY=${NODE_BINARY:-node} +# The project root by default is one level up from the ios directory +RN_PROJECT_ROOT="${PROJECT_DIR}/.." + [ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties +[ -z "$SENTRY_DOTENV_PATH" ] && export SENTRY_DOTENV_PATH="$RN_PROJECT_ROOT/.env.sentry-build-plugin" [ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_PACKAGE_PATH=$("$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))") [ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_EXECUTABLE="${SENTRY_CLI_PACKAGE_PATH}/bin/sentry-cli" diff --git a/packages/core/scripts/sentry-xcode.sh b/packages/core/scripts/sentry-xcode.sh index e7b9d5479e..43a897471a 100755 --- a/packages/core/scripts/sentry-xcode.sh +++ b/packages/core/scripts/sentry-xcode.sh @@ -9,7 +9,11 @@ set -x -e LOCAL_NODE_BINARY=${NODE_BINARY:-node} +# The project root by default is one level up from the ios directory +RN_PROJECT_ROOT="$PROJECT_DIR"/.. + [ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties +[ -z "$SENTRY_DOTENV_PATH" ] && export SENTRY_DOTENV_PATH="$RN_PROJECT_ROOT/.env.sentry-build-plugin" [ -z "$SOURCEMAP_FILE" ] && export SOURCEMAP_FILE="$DERIVED_FILE_DIR/main.jsbundle.map" [ -z "$SENTRY_CLI_EXECUTABLE" ] && SENTRY_CLI_PACKAGE_PATH=$("$LOCAL_NODE_BINARY" --print "require('path').dirname(require.resolve('@sentry/cli/package.json'))") diff --git a/packages/core/sentry.gradle b/packages/core/sentry.gradle index f0adc88a7f..fbbf567412 100644 --- a/packages/core/sentry.gradle +++ b/packages/core/sentry.gradle @@ -203,6 +203,9 @@ gradle.projectsEvaluated { project.logger.lifecycle("Sentry-CLI arguments: ${args}") def osCompatibility = Os.isFamily(Os.FAMILY_WINDOWS) ? ['cmd', '/c', 'node'] : [] + if (!System.getenv('SENTRY_DOTENV_PATH')) { + environment('SENTRY_DOTENV_PATH', "$reactRoot/.env.sentry-build-plugin") + } commandLine(*osCompatibility, *args) } } From 99478273964f6f8384ea9a0705be0de8ddfca05c Mon Sep 17 00:00:00 2001 From: Krystof Woldrich Date: Fri, 15 Nov 2024 16:08:18 +0000 Subject: [PATCH 2/5] add dot env example files --- packages/core/scripts/sentry-xcode.sh | 2 +- samples/expo/.env.sentry-build-plugin.example | 1 + samples/react-native/.env.sentry-build-plugin.example | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 samples/expo/.env.sentry-build-plugin.example create mode 100644 samples/react-native/.env.sentry-build-plugin.example diff --git a/packages/core/scripts/sentry-xcode.sh b/packages/core/scripts/sentry-xcode.sh index 43a897471a..78970c4c60 100755 --- a/packages/core/scripts/sentry-xcode.sh +++ b/packages/core/scripts/sentry-xcode.sh @@ -10,7 +10,7 @@ set -x -e LOCAL_NODE_BINARY=${NODE_BINARY:-node} # The project root by default is one level up from the ios directory -RN_PROJECT_ROOT="$PROJECT_DIR"/.. +RN_PROJECT_ROOT="${PROJECT_DIR}/.." [ -z "$SENTRY_PROPERTIES" ] && export SENTRY_PROPERTIES=sentry.properties [ -z "$SENTRY_DOTENV_PATH" ] && export SENTRY_DOTENV_PATH="$RN_PROJECT_ROOT/.env.sentry-build-plugin" diff --git a/samples/expo/.env.sentry-build-plugin.example b/samples/expo/.env.sentry-build-plugin.example new file mode 100644 index 0000000000..82f38b516b --- /dev/null +++ b/samples/expo/.env.sentry-build-plugin.example @@ -0,0 +1 @@ +SENTRY_AUTH_TOKEN=your_token_here diff --git a/samples/react-native/.env.sentry-build-plugin.example b/samples/react-native/.env.sentry-build-plugin.example new file mode 100644 index 0000000000..82f38b516b --- /dev/null +++ b/samples/react-native/.env.sentry-build-plugin.example @@ -0,0 +1 @@ +SENTRY_AUTH_TOKEN=your_token_here From 0a4165c5cb6affd9b427d44f4084bfbc97b07dab Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Mon, 18 Nov 2024 10:07:17 +0100 Subject: [PATCH 3/5] Update CHANGELOG.md Co-authored-by: Antonis Lilis --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c6a426db..d7a323ac0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,7 +33,7 @@ - Add support for `.env.sentry-build-plugin` ([#4281](https://github.com/getsentry/sentry-react-native/pull/4281)) - Don't committing the file to your repository. Use it to set your Sentry Auth Token. + Don't commit the file to your repository. Use it to set your Sentry Auth Token. ``` SENTRY_AUTH_TOKEN=your_token_here From 5f53f2ef7ecf17a7c45a1268acb57fcfbacb42bb Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:50:53 +0100 Subject: [PATCH 4/5] Update CHANGELOG.md --- CHANGELOG.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa08c095ec..a21b0a0a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,16 @@ ## Unreleased +### Features + +- Add support for `.env.sentry-build-plugin` ([#4281](https://github.com/getsentry/sentry-react-native/pull/4281)) + + Don't commit the file to your repository. Use it to set your Sentry Auth Token. + + ``` + SENTRY_AUTH_TOKEN=your_token_here + ``` + ### Fixes - Prevents exception capture context from being overwritten by native scope sync ([#4124](https://github.com/getsentry/sentry-react-native/pull/4124)) @@ -47,14 +57,6 @@ export SENTRY_DISABLE_NATIVE_DEBUG_UPLOAD=true ``` -- Add support for `.env.sentry-build-plugin` ([#4281](https://github.com/getsentry/sentry-react-native/pull/4281)) - - Don't commit the file to your repository. Use it to set your Sentry Auth Token. - - ``` - SENTRY_AUTH_TOKEN=your_token_here - ``` - ### Fixes - Ignore JavascriptException to filter out obfuscated duplicate JS Errors on Android ([#4232](https://github.com/getsentry/sentry-react-native/pull/4232)) From ccac381e74a53a87afa3e19689f17adb46543862 Mon Sep 17 00:00:00 2001 From: Krystof Woldrich <31292499+krystofwoldrich@users.noreply.github.com> Date: Tue, 19 Nov 2024 11:52:31 +0100 Subject: [PATCH 5/5] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ea8b71123..4a0ce21803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ Don't commit the file to your repository. Use it to set your Sentry Auth Token. - ```sh + ``` SENTRY_AUTH_TOKEN=your_token_here ```