-
-
Notifications
You must be signed in to change notification settings - Fork 82
fix(apple): Dynamic SDK version, enableLogs fix, dSYM guidance, and doctor command #1247
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
Open
filipealva
wants to merge
1
commit into
getsentry:master
Choose a base branch
from
filipealva:fix-apple-wizard-issues
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // @ts-expect-error - clack is ESM and TS complains about that. It works though | ||
| import clack from '@clack/prompts'; | ||
| import chalk from 'chalk'; | ||
|
|
||
| import { withTelemetry } from '../../telemetry'; | ||
| import { abortIfCancelled, printWelcome } from '../../utils/clack'; | ||
| import { lookupXcodeProject } from '../lookup-xcode-project'; | ||
| import type { AppleWizardOptions } from '../options'; | ||
| import { checkBuildPhase } from './checks/check-build-phase'; | ||
| import { checkCodeInit } from './checks/check-code-init'; | ||
| import { checkSdkVersion } from './checks/check-sdk-version'; | ||
| import { checkSentryCli } from './checks/check-sentry-cli'; | ||
| import { checkSentryCliRc } from './checks/check-sentryclirc'; | ||
| import type { DiagnosticResult } from './types'; | ||
|
|
||
| export async function runAppleDoctorWizard( | ||
| options: AppleWizardOptions, | ||
| ): Promise<void> { | ||
| return withTelemetry( | ||
| { | ||
| enabled: options.telemetryEnabled, | ||
| integration: 'ios', | ||
| wizardOptions: options, | ||
| }, | ||
| () => runAppleDoctorWithTelemetry(options), | ||
| ); | ||
| } | ||
|
|
||
| async function runAppleDoctorWithTelemetry( | ||
| options: AppleWizardOptions, | ||
| ): Promise<void> { | ||
| const projectDir = options.projectDir ?? process.cwd(); | ||
|
|
||
| printWelcome({ wizardName: 'Sentry Apple Doctor' }); | ||
|
|
||
| const { xcProject, target } = await lookupXcodeProject({ projectDir }); | ||
|
|
||
| clack.log.info('Running diagnostic checks...\n'); | ||
|
|
||
| const results: DiagnosticResult[] = [ | ||
| checkSentryCli(), | ||
| checkSentryCliRc({ projectDir }), | ||
| await checkSdkVersion({ xcProject }), | ||
| checkBuildPhase({ xcProject, target }), | ||
| checkCodeInit({ xcProject, target }), | ||
| ]; | ||
|
|
||
| let hasFailures = false; | ||
| let hasFixable = false; | ||
|
|
||
| for (const result of results) { | ||
| if (result.status === 'pass') { | ||
| clack.log.success( | ||
| `${chalk.green('PASS')} ${result.name}: ${result.message}`, | ||
| ); | ||
| } else if (result.status === 'warn') { | ||
| clack.log.warn( | ||
| `${chalk.yellow('WARN')} ${result.name}: ${result.message}`, | ||
| ); | ||
| } else { | ||
| clack.log.error(`${chalk.red('FAIL')} ${result.name}: ${result.message}`); | ||
| hasFailures = true; | ||
| } | ||
|
|
||
| if (result.fixAvailable && result.status !== 'pass') { | ||
| hasFixable = true; | ||
| } | ||
| } | ||
|
|
||
| if (hasFixable) { | ||
| const shouldFix = await abortIfCancelled( | ||
| clack.confirm({ | ||
| message: 'Would you like to attempt to fix the issues found?', | ||
| }), | ||
| ); | ||
|
|
||
| if (shouldFix) { | ||
| for (const result of results) { | ||
| if (result.fixAvailable && result.status !== 'pass' && result.fix) { | ||
| clack.log.step(`Fixing: ${result.name}...`); | ||
| const fixed = await result.fix(); | ||
| if (fixed) { | ||
| clack.log.success(`Fixed: ${result.name}`); | ||
| } else { | ||
| clack.log.warn(`Could not automatically fix: ${result.name}`); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } else if (!hasFailures) { | ||
| clack.log.success( | ||
| 'All checks passed! Your Sentry integration looks healthy.', | ||
| ); | ||
| } | ||
| } | ||
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,80 @@ | ||
| import type { PBXNativeTarget, PBXShellScriptBuildPhase } from 'xcode'; | ||
| import type { XcodeProject } from '../../xcode-manager'; | ||
| import type { DiagnosticResult } from '../types'; | ||
|
|
||
| export function checkBuildPhase({ | ||
| xcProject, | ||
| target, | ||
| }: { | ||
| xcProject: XcodeProject; | ||
| target: string; | ||
| }): DiagnosticResult { | ||
| const xcObjects = xcProject.objects; | ||
|
|
||
| const targetKey = Object.keys(xcObjects.PBXNativeTarget ?? {}).find((key) => { | ||
| const value = xcObjects.PBXNativeTarget?.[key]; | ||
| return ( | ||
| !key.endsWith('_comment') && | ||
| typeof value !== 'string' && | ||
| value?.name === target | ||
| ); | ||
| }); | ||
|
|
||
| if (!targetKey) { | ||
| return { | ||
| name: 'dSYM Upload Build Phase', | ||
| status: 'fail', | ||
| message: `Target "${target}" not found in project.`, | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
|
|
||
| const nativeTarget = xcObjects.PBXNativeTarget?.[ | ||
| targetKey | ||
| ] as PBXNativeTarget; | ||
|
|
||
| let sentryBuildPhase: PBXShellScriptBuildPhase | undefined; | ||
| for (const phase of nativeTarget.buildPhases ?? []) { | ||
| const bp = xcObjects.PBXShellScriptBuildPhase?.[phase.value]; | ||
| if (typeof bp !== 'string' && bp?.shellScript?.includes('sentry-cli')) { | ||
| sentryBuildPhase = bp; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!sentryBuildPhase) { | ||
| return { | ||
| name: 'dSYM Upload Build Phase', | ||
| status: 'fail', | ||
| message: | ||
| 'No Sentry dSYM upload build phase found in target. Re-run the wizard to add it.', | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
|
|
||
| const issues: string[] = []; | ||
| const script = sentryBuildPhase.shellScript ?? ''; | ||
|
|
||
| if (!script.includes('SENTRY_ORG')) { | ||
| issues.push('Missing SENTRY_ORG'); | ||
| } | ||
| if (!script.includes('SENTRY_PROJECT')) { | ||
| issues.push('Missing SENTRY_PROJECT'); | ||
| } | ||
|
|
||
| if (issues.length === 0) { | ||
| return { | ||
| name: 'dSYM Upload Build Phase', | ||
| status: 'pass', | ||
| message: 'Sentry dSYM upload build phase is correctly configured.', | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| name: 'dSYM Upload Build Phase', | ||
| status: 'warn', | ||
| message: `Issues found: ${issues.join('; ')}`, | ||
| fixAvailable: false, | ||
| }; | ||
| } |
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,60 @@ | ||
| import * as fs from 'node:fs'; | ||
| import type { XcodeProject } from '../../xcode-manager'; | ||
| import type { DiagnosticResult } from '../types'; | ||
|
|
||
| export function checkCodeInit({ | ||
| xcProject, | ||
| target, | ||
| }: { | ||
| xcProject: XcodeProject; | ||
| target: string; | ||
| }): DiagnosticResult { | ||
| const files = xcProject.getSourceFilesForTarget(target); | ||
|
|
||
| if (!files || files.length === 0) { | ||
| return { | ||
| name: 'Sentry Initialization Code', | ||
| status: 'warn', | ||
| message: | ||
| 'Could not resolve source files for the target to check for initialization code.', | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
|
|
||
| for (const filePath of files) { | ||
| if (!fs.existsSync(filePath)) continue; | ||
|
|
||
| let content: string; | ||
| try { | ||
| content = fs.readFileSync(filePath, 'utf8'); | ||
| } catch { | ||
| continue; | ||
| } | ||
|
|
||
| // Check for active (non-commented) Sentry initialization | ||
| const lines = content.split('\n'); | ||
| for (const line of lines) { | ||
| const trimmed = line.trim(); | ||
| if (trimmed.startsWith('//') || trimmed.startsWith('/*')) continue; | ||
| if ( | ||
| trimmed.includes('SentrySDK.start') || | ||
| trimmed.includes('[SentrySDK start') | ||
| ) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return { | ||
| name: 'Sentry Initialization Code', | ||
| status: 'pass', | ||
| message: `Sentry initialization found in ${filePath}.`, | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| name: 'Sentry Initialization Code', | ||
| status: 'fail', | ||
| message: | ||
| 'No active Sentry initialization code found in source files. SDK will not start.', | ||
| fixAvailable: false, | ||
| }; | ||
| } | ||
Oops, something went wrong.
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.
Warnings still reported as fully healthy
Medium Severity
The final summary prints
All checks passedwhenever there are nofailresults, even if earlier checks returnedwarn. This makesrunAppleDoctorWizardreport a healthy integration after warning findings, which can hide real configuration problems from users.