-
-
Notifications
You must be signed in to change notification settings - Fork 359
fix(ios): Respect SENTRY_ALLOW_FAILURE in Xcode build scripts #5616
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
266 changes: 266 additions & 0 deletions
266
packages/core/test/scripts/sentry-xcode-scripts.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,266 @@ | ||
| import { execSync } from 'child_process'; | ||
| import * as fs from 'fs'; | ||
| import * as os from 'os'; | ||
| import * as path from 'path'; | ||
|
|
||
| const SCRIPTS_DIR = path.resolve(__dirname, '../../scripts'); | ||
| const DEBUG_FILES_SCRIPT = path.join(SCRIPTS_DIR, 'sentry-xcode-debug-files.sh'); | ||
| const XCODE_SCRIPT = path.join(SCRIPTS_DIR, 'sentry-xcode.sh'); | ||
|
|
||
| describe('sentry-xcode-debug-files.sh', () => { | ||
| let tempDir: string; | ||
| let mockSentryCliScript: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Create a temporary directory for test artifacts | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sentry-xcode-test-')); | ||
|
|
||
| // Create a mock sentry-cli script that can simulate success or failure | ||
| mockSentryCliScript = path.join(tempDir, 'mock-sentry-cli.js'); | ||
| fs.writeFileSync( | ||
| mockSentryCliScript, | ||
| ` | ||
| const exitCode = process.env.MOCK_CLI_EXIT_CODE || '0'; | ||
| const output = process.env.MOCK_CLI_OUTPUT || 'Mock upload output'; | ||
| console.log(output); | ||
| process.exit(parseInt(exitCode)); | ||
| `, | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up temp directory | ||
| if (tempDir && fs.existsSync(tempDir)) { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| const runScript = (env: Record<string, string> = {}): { stdout: string; stderr: string; exitCode: number } => { | ||
| const defaultEnv = { | ||
| NODE_BINARY: process.execPath, | ||
| SENTRY_CLI_EXECUTABLE: mockSentryCliScript, | ||
| DWARF_DSYM_FOLDER_PATH: tempDir, | ||
| CONFIGURATION: 'Release', | ||
| PROJECT_DIR: tempDir, | ||
| DERIVED_FILE_DIR: tempDir, | ||
| }; | ||
|
|
||
| try { | ||
| const stdout = execSync(`bash "${DEBUG_FILES_SCRIPT}"`, { | ||
| env: { ...process.env, ...defaultEnv, ...env }, | ||
| encoding: 'utf8', | ||
| stdio: 'pipe', | ||
| }); | ||
| return { stdout, stderr: '', exitCode: 0 }; | ||
| } catch (error: any) { | ||
| return { | ||
| stdout: error.stdout?.toString() || '', | ||
| stderr: error.stderr?.toString() || '', | ||
| exitCode: error.status || 1, | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| it('exits with 0 when upload succeeds', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '0', | ||
| MOCK_CLI_OUTPUT: 'Upload successful', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('Upload successful'); | ||
| }); | ||
|
|
||
| it('exits with 0 when SENTRY_ALLOW_FAILURE=true and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed: API error', | ||
| SENTRY_ALLOW_FAILURE: 'true', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('warning: sentry-cli'); | ||
| expect(result.stdout).toContain('continuing build because SENTRY_ALLOW_FAILURE=true'); | ||
| expect(result.stdout).toContain('Upload failed: API error'); | ||
| }); | ||
|
|
||
| it('exits with 0 but prints error when SENTRY_ALLOW_FAILURE not set and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed: API error', | ||
| }); | ||
|
|
||
| // Original behavior: script exits 0, but Xcode fails build due to "error:" prefix | ||
lucas-zimerman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('error: sentry-cli'); | ||
| expect(result.stdout).toContain('SENTRY_ALLOW_FAILURE=true'); | ||
| expect(result.stdout).toContain('Upload failed: API error'); | ||
| }); | ||
|
|
||
| it('exits with 0 but prints error when SENTRY_ALLOW_FAILURE=false and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed: Network error', | ||
| SENTRY_ALLOW_FAILURE: 'false', | ||
| }); | ||
|
|
||
| // Original behavior: script exits 0, but Xcode fails build due to "error:" prefix | ||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('error: sentry-cli'); | ||
| }); | ||
|
|
||
| it('skips upload when SENTRY_DISABLE_AUTO_UPLOAD=true', () => { | ||
| const result = runScript({ | ||
| SENTRY_DISABLE_AUTO_UPLOAD: 'true', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('SENTRY_DISABLE_AUTO_UPLOAD=true'); | ||
| expect(result.stdout).toContain('skipping debug files upload'); | ||
| }); | ||
|
|
||
| it('skips upload for Debug configuration', () => { | ||
| const result = runScript({ | ||
| CONFIGURATION: 'Debug', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('Skipping debug files upload for *Debug* configuration'); | ||
| }); | ||
|
|
||
| it('skips upload for debug configuration (case insensitive)', () => { | ||
| const result = runScript({ | ||
| CONFIGURATION: 'debug', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('Skipping debug files upload for *Debug* configuration'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('sentry-xcode.sh', () => { | ||
| let tempDir: string; | ||
| let mockSentryCliScript: string; | ||
| let mockReactNativeScript: string; | ||
|
|
||
| beforeEach(() => { | ||
| // Create a temporary directory for test artifacts | ||
| tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sentry-xcode-test-')); | ||
|
|
||
| // Create a mock sentry-cli script | ||
| mockSentryCliScript = path.join(tempDir, 'mock-sentry-cli.js'); | ||
| fs.writeFileSync( | ||
| mockSentryCliScript, | ||
| ` | ||
| const exitCode = process.env.MOCK_CLI_EXIT_CODE || '0'; | ||
| const output = process.env.MOCK_CLI_OUTPUT || 'Mock upload output'; | ||
| console.log(output); | ||
| process.exit(parseInt(exitCode)); | ||
| `, | ||
| ); | ||
|
|
||
| // Create a mock react-native-xcode.sh script | ||
| mockReactNativeScript = path.join(tempDir, 'react-native-xcode.sh'); | ||
| fs.writeFileSync( | ||
| mockReactNativeScript, | ||
| `#!/bin/bash | ||
| echo "Mock React Native bundle" | ||
| exit 0 | ||
| `, | ||
| ); | ||
| fs.chmodSync(mockReactNativeScript, '755'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| // Clean up temp directory | ||
| if (tempDir && fs.existsSync(tempDir)) { | ||
| fs.rmSync(tempDir, { recursive: true, force: true }); | ||
| } | ||
| }); | ||
|
|
||
| const runScript = (env: Record<string, string> = {}): { stdout: string; stderr: string; exitCode: number } => { | ||
| // Create a mock collect-modules.sh script to prevent script failure | ||
| const mockCollectModulesScript = path.join(tempDir, 'collect-modules.sh'); | ||
| fs.writeFileSync(mockCollectModulesScript, '#!/bin/bash\nexit 0\n'); | ||
| fs.chmodSync(mockCollectModulesScript, '755'); | ||
|
|
||
| const defaultEnv = { | ||
| NODE_BINARY: process.execPath, | ||
| SENTRY_CLI_EXECUTABLE: mockSentryCliScript, | ||
| PROJECT_DIR: tempDir, | ||
| DERIVED_FILE_DIR: tempDir, | ||
| SENTRY_COLLECT_MODULES: mockCollectModulesScript, // Set this to avoid package resolution failure | ||
| }; | ||
|
|
||
| try { | ||
| const stdout = execSync(`bash "${XCODE_SCRIPT}" "${mockReactNativeScript}"`, { | ||
| env: { ...process.env, ...defaultEnv, ...env }, | ||
| encoding: 'utf8', | ||
| stdio: 'pipe', | ||
| }); | ||
| return { stdout, stderr: '', exitCode: 0 }; | ||
| } catch (error: any) { | ||
| return { | ||
| stdout: error.stdout?.toString() || '', | ||
| stderr: error.stderr?.toString() || '', | ||
| exitCode: error.status || 1, | ||
| }; | ||
| } | ||
| }; | ||
|
|
||
| it('exits with 0 when upload succeeds', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '0', | ||
| MOCK_CLI_OUTPUT: 'Source maps uploaded successfully', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('Source maps uploaded successfully'); | ||
| }); | ||
|
|
||
| it('exits with 0 when SENTRY_ALLOW_FAILURE=true and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed: Connection timeout', | ||
| SENTRY_ALLOW_FAILURE: 'true', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('warning: sentry-cli'); | ||
| expect(result.stdout).toContain('continuing build because SENTRY_ALLOW_FAILURE=true'); | ||
| expect(result.stdout).toContain('Upload failed: Connection timeout'); | ||
| }); | ||
|
|
||
| it('exits with 1 when SENTRY_ALLOW_FAILURE not set and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed: Invalid auth token', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(1); | ||
| expect(result.stdout).toContain('error: sentry-cli'); | ||
| expect(result.stdout).toContain('SENTRY_ALLOW_FAILURE=true'); | ||
| expect(result.stdout).toContain('Upload failed: Invalid auth token'); | ||
| }); | ||
|
|
||
| it('exits with 1 when SENTRY_ALLOW_FAILURE=false and upload fails', () => { | ||
| const result = runScript({ | ||
| MOCK_CLI_EXIT_CODE: '1', | ||
| MOCK_CLI_OUTPUT: 'Upload failed', | ||
| SENTRY_ALLOW_FAILURE: 'false', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(1); | ||
| expect(result.stdout).toContain('error: sentry-cli'); | ||
| }); | ||
|
|
||
| it('skips upload when SENTRY_DISABLE_AUTO_UPLOAD=true', () => { | ||
| const result = runScript({ | ||
| SENTRY_DISABLE_AUTO_UPLOAD: 'true', | ||
| }); | ||
|
|
||
| expect(result.exitCode).toBe(0); | ||
| expect(result.stdout).toContain('SENTRY_DISABLE_AUTO_UPLOAD=true'); | ||
| expect(result.stdout).toContain('skipping sourcemaps upload'); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised that the
Fixessection is in the wrong position. I moved it in the correct place in a next PR with 5202581