Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
17 changes: 11 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
```
- Add expo constants on event context ([#5748](https://github.com/getsentry/sentry-react-native/pull/5748))
- Capture dynamic route params as span attributes for Expo Router navigations ([#5750](https://github.com/getsentry/sentry-react-native/pull/5750))
- EAS Build Hooks ([#5666](https://github.com/getsentry/sentry-react-native/pull/5666))
- Capture EAS build events in Sentry. Add the following to your `package.json`
```json
{
"scripts": {
"eas-build-on-complete": "sentry-eas-build-on-complete"
}
}
```
Set `SENTRY_DSN` in your EAS secrets, and optionally `SENTRY_EAS_BUILD_CAPTURE_SUCCESS=true` to also capture successful builds.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That all would require documentation changes; will make sure to handle them next.



### Fixes

Expand Down Expand Up @@ -68,12 +79,6 @@
- Bump Android SDK Stubs from v8.32.0 to v8.33.0 ([#5697](https://github.com/getsentry/sentry-react-native/pull/5697))
- [changelog](https://github.com/getsentry/sentry-java/blob/main/CHANGELOG.md#8330)
- [diff](https://github.com/getsentry/sentry-java/compare/8.32.0...8.33.0)
- Bump Cocoa SDK from v9.4.1 to v9.5.1 ([#5685](https://github.com/getsentry/sentry-react-native/pull/5685), [#5724](https://github.com/getsentry/sentry-react-native/pull/5724))
- [changelog](https://github.com/getsentry/sentry-cocoa/blob/main/CHANGELOG.md#951)
- [diff](https://github.com/getsentry/sentry-cocoa/compare/9.4.1...9.5.1)
- Bump CLI from v3.2.0 to v3.2.2 ([#5692](https://github.com/getsentry/sentry-react-native/pull/5692))
- [changelog](https://github.com/getsentry/sentry-cli/blob/master/CHANGELOG.md#322)
- [diff](https://github.com/getsentry/sentry-cli/compare/3.2.0...3.2.2)

## 8.1.0

Expand Down
3 changes: 3 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
"lint:prettier": "prettier --config ../../.prettierrc.json --ignore-path ../../.prettierignore --check \"{src,test,scripts,plugin/src}/**/**.ts\""
},
"bin": {
"sentry-eas-build-on-complete": "scripts/eas/build-on-complete.js",
"sentry-eas-build-on-error": "scripts/eas/build-on-error.js",
"sentry-eas-build-on-success": "scripts/eas/build-on-success.js",
"sentry-expo-upload-sourcemaps": "scripts/expo-upload-sourcemaps.js"
},
"keywords": [
Expand Down
53 changes: 53 additions & 0 deletions packages/core/scripts/eas/build-on-complete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env node
/**
* EAS Build Hook: on-complete
*
* This script captures EAS build completion events and reports them to Sentry.
* It uses the EAS_BUILD_STATUS environment variable to determine whether
* the build succeeded or failed.
*
* Add it to your package.json scripts:
*
* "eas-build-on-complete": "sentry-eas-build-on-complete"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have docs for these features and add a small mention on how to use them on changelog.

*
* NOTE: Use EITHER this hook OR the separate on-error/on-success hooks, not both.
* Using both will result in duplicate events being sent to Sentry.
*
* Required environment variables:
* - SENTRY_DSN: Your Sentry DSN
*
* Optional environment variables:
* - SENTRY_EAS_BUILD_CAPTURE_SUCCESS: Set to 'true' to also capture successful builds
* - SENTRY_EAS_BUILD_TAGS: JSON string of additional tags
* - SENTRY_EAS_BUILD_ERROR_MESSAGE: Custom error message for failed builds
* - SENTRY_EAS_BUILD_SUCCESS_MESSAGE: Custom success message for successful builds
*
* EAS Build provides:
* - EAS_BUILD_STATUS: 'finished' or 'errored'
*
* @see https://docs.expo.dev/build-reference/npm-hooks/
* @see https://docs.sentry.io/platforms/react-native/
*
*/

const { loadEnv, loadHooksModule, parseBaseOptions, runHook } = require('./utils');

async function main() {
loadEnv();

const hooks = loadHooksModule();
const options = {
...parseBaseOptions(),
errorMessage: process.env.SENTRY_EAS_BUILD_ERROR_MESSAGE,
successMessage: process.env.SENTRY_EAS_BUILD_SUCCESS_MESSAGE,
captureSuccessfulBuilds: process.env.SENTRY_EAS_BUILD_CAPTURE_SUCCESS === 'true',
};

await runHook('on-complete', () => hooks.captureEASBuildComplete(options));
}

main().catch(error => {
// eslint-disable-next-line no-console
console.error('[Sentry] Unexpected error in eas-build-on-complete hook:', error);
process.exit(1);
});
Comment thread
alwx marked this conversation as resolved.
Outdated
42 changes: 42 additions & 0 deletions packages/core/scripts/eas/build-on-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env node
/**
* EAS Build Hook: on-error
*
* This script captures EAS build failures and reports them to Sentry.
* Add it to your package.json scripts:
*
* "eas-build-on-error": "sentry-eas-build-on-error"
Comment thread
alwx marked this conversation as resolved.
Outdated
*
* NOTE: Use EITHER this hook (with on-success) OR the on-complete hook, not both.
* Using both will result in duplicate events being sent to Sentry.
*
* Required environment variables:
* - SENTRY_DSN: Your Sentry DSN
*
* Optional environment variables:
* - SENTRY_EAS_BUILD_TAGS: JSON string of additional tags
* - SENTRY_EAS_BUILD_ERROR_MESSAGE: Custom error message
*
* @see https://docs.expo.dev/build-reference/npm-hooks/
* @see https://docs.sentry.io/platforms/react-native/
*/

const { loadEnv, loadHooksModule, parseBaseOptions, runHook } = require('./utils');

async function main() {
loadEnv();

const hooks = loadHooksModule();
const options = {
...parseBaseOptions(),
errorMessage: process.env.SENTRY_EAS_BUILD_ERROR_MESSAGE,
};

await runHook('on-error', () => hooks.captureEASBuildError(options));
}

main().catch(error => {
// eslint-disable-next-line no-console
console.error('[Sentry] Unexpected error in eas-build-on-error hook:', error);
process.exit(1);
});
44 changes: 44 additions & 0 deletions packages/core/scripts/eas/build-on-success.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
/**
* EAS Build Hook: on-success
*
* This script captures EAS build successes and reports them to Sentry.
* Add it to your package.json scripts:
*
* "eas-build-on-success": "sentry-eas-build-on-success"
Comment thread
alwx marked this conversation as resolved.
Outdated
*
* NOTE: Use EITHER this hook (with on-error) OR the on-complete hook, not both.
* Using both will result in duplicate events being sent to Sentry.
*
* Required environment variables:
* - SENTRY_DSN: Your Sentry DSN
* - SENTRY_EAS_BUILD_CAPTURE_SUCCESS: Set to 'true' to capture successful builds
*
* Optional environment variables:
* - SENTRY_EAS_BUILD_TAGS: JSON string of additional tags
* - SENTRY_EAS_BUILD_SUCCESS_MESSAGE: Custom success message
*
* @see https://docs.expo.dev/build-reference/npm-hooks/
* @see https://docs.sentry.io/platforms/react-native/
*/

const { loadEnv, loadHooksModule, parseBaseOptions, runHook } = require('./utils');

async function main() {
Comment thread
alwx marked this conversation as resolved.
Outdated
loadEnv();

const hooks = loadHooksModule();
const options = {
...parseBaseOptions(),
successMessage: process.env.SENTRY_EAS_BUILD_SUCCESS_MESSAGE,
captureSuccessfulBuilds: process.env.SENTRY_EAS_BUILD_CAPTURE_SUCCESS === 'true',
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
};

await runHook('on-success', () => hooks.captureEASBuildSuccess(options));
}

main().catch(error => {
// eslint-disable-next-line no-console
console.error('[Sentry] Unexpected error in eas-build-on-success hook:', error);
process.exit(1);
});
124 changes: 124 additions & 0 deletions packages/core/scripts/eas/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Shared utilities for EAS Build Hook scripts.
*
* @see https://docs.expo.dev/build-reference/npm-hooks/
*/

/* eslint-disable no-console */

const path = require('path');
const fs = require('fs');

/**
* Merges parsed env vars into process.env without overwriting existing values.
* This preserves EAS secrets and other pre-set environment variables.
* @param {object} parsed - Parsed environment variables from dotenv
*/
function mergeEnvWithoutOverwrite(parsed) {
for (const key of Object.keys(parsed)) {
if (process.env[key] === undefined) {
process.env[key] = parsed[key];
}
}
}

/**
* Loads environment variables from various sources:
* - @expo/env (if available)
* - .env file (via dotenv, if available)
* - .env.sentry-build-plugin file
*
* NOTE: Existing environment variables (like EAS secrets) are NOT overwritten.
*/
function loadEnv() {
// Try @expo/env first
try {
require('@expo/env').load('.');
} catch (_e) {
// Fallback to dotenv if available
try {
const dotenvPath = path.join(process.cwd(), '.env');
if (fs.existsSync(dotenvPath)) {
const dotenvFile = fs.readFileSync(dotenvPath, 'utf-8');
const dotenv = require('dotenv');
mergeEnvWithoutOverwrite(dotenv.parse(dotenvFile));
}
} catch (_e2) {
// No dotenv available, continue with existing env vars
}
}

// Also load .env.sentry-build-plugin if it exists
try {
const sentryEnvPath = path.join(process.cwd(), '.env.sentry-build-plugin');
if (fs.existsSync(sentryEnvPath)) {
const dotenvFile = fs.readFileSync(sentryEnvPath, 'utf-8');
const dotenv = require('dotenv');
mergeEnvWithoutOverwrite(dotenv.parse(dotenvFile));
}
} catch (_e) {
// Continue without .env.sentry-build-plugin
}
}

/**
* Loads the EAS build hooks module from the compiled output.
* @returns {object} The hooks module exports
* @throws {Error} If the module cannot be loaded
*/
function loadHooksModule() {
try {
return require('../../dist/js/tools/easBuildHooks.js');
} catch (_e) {
console.error('[Sentry] Could not load EAS build hooks module. Make sure @sentry/react-native is properly installed.');
process.exit(1);
}
}

/**
* Parses common options from environment variables.
* @returns {object} Parsed options object
*/
function parseBaseOptions() {
const options = {
dsn: process.env.SENTRY_DSN,
};

// Parse additional tags if provided
if (process.env.SENTRY_EAS_BUILD_TAGS) {
try {
const parsed = JSON.parse(process.env.SENTRY_EAS_BUILD_TAGS);
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
options.tags = parsed;
} else {
console.warn('[Sentry] SENTRY_EAS_BUILD_TAGS must be a JSON object (e.g., {"key":"value"}). Ignoring.');
}
} catch (_e) {
console.warn('[Sentry] Could not parse SENTRY_EAS_BUILD_TAGS as JSON. Ignoring.');
}
}
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

return options;
}

/**
* Wraps an async hook function with error handling.
* @param {string} hookName - Name of the hook for logging
* @param {Function} hookFn - Async function to execute
*/
async function runHook(hookName, hookFn) {
try {
await hookFn();
console.log(`[Sentry] EAS build ${hookName} hook completed.`);
} catch (error) {
console.error(`[Sentry] Error in eas-build-${hookName} hook:`, error);
// Don't fail the build hook itself
}
}

module.exports = {
loadEnv,
loadHooksModule,
parseBaseOptions,
runHook,
};
Loading
Loading