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(plugin): Add support for .env.sentry-build-plugin #4281

Merged
merged 7 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,4 @@ node_modules.bak

# Sentry React Native Monorepo
/packages/core/README.md
.env.sentry-build-plugin
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 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))
Expand Down
16 changes: 16 additions & 0 deletions packages/core/scripts/expo-upload-sourcemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions packages/core/scripts/sentry-xcode-debug-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions packages/core/scripts/sentry-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'))")
Expand Down
3 changes: 3 additions & 0 deletions packages/core/sentry.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
1 change: 1 addition & 0 deletions samples/expo/.env.sentry-build-plugin.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SENTRY_AUTH_TOKEN=your_token_here
1 change: 1 addition & 0 deletions samples/react-native/.env.sentry-build-plugin.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SENTRY_AUTH_TOKEN=your_token_here
Loading