Repository navigation
feat(cli): add iOS, Apple Snapshots and React Native to sentry wizard #2544
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
Show all changes
23 commits
Select commit
Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] 76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] 0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] 7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] 2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] 4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] cbdf2f7
feat(cli): add iOS, Apple Snapshots and React Native to sentry wizard
sentry-junior[bot] d084aa4
Merge remote-tracking branch 'origin/feat/cli-wizard-shared-ast-helpe…
sentry-junior[bot] 10026f1
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] 3fbc541
refactor(cli): drop the Apple wizard flags and fit the new wizard base
sentry-junior[bot] ed81e1d
fix(cli): include the xcode typings in the script typecheck
sentry-junior[bot] 2394297
feat(cli): run sentry through npx in the Xcode build phase when missing
sentry-junior[bot] 033ff19
Merge origin/main into feat/cli-wizard-apple-react-native
sentry-junior[bot] 7ba80fb
fix(cli): clear the CodeQL and dependency-review findings in the Appl…
sentry-junior[bot] acae79a
fix(cli): close a shell injection and two prompt bugs in the Apple an…
sentry-junior[bot] 5f0bbd2
fix(cli): exit the React Native wizard when the test-event prompt is …
sentry-junior[bot] b53a30f
fix(cli): add Sentry.init after semicolon-less imports in the React N…
sentry-junior[bot] a514951
fix(cli): only treat real imports as the semicolon-less Sentry.init a…
sentry-junior[bot] 0277642
fix(cli): resolve Xcode file references without sourceTree as <group>
sentry-junior[bot] 2e212cf
fix(cli): don't duplicate withSentryConfig when re-patching a Metro c…
sentry-junior[bot] 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,6 +154,7 @@ | |
| "valibot": "^1.4.2", | ||
| "vitest": "catalog:", | ||
| "wrap-ansi": "^10.0.0", | ||
| "xcode": "3.0.1", | ||
| "yauzl": "3.4.0" | ||
| } | ||
| } | ||
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,132 @@ | ||
| /** | ||
| * The iOS wizard (`sentry wizard ios`): adds the Sentry Cocoa SDK through | ||
| * Swift Package Manager, a debug-symbol upload build phase, the SDK init | ||
| * snippet, and an optional Fastlane upload step to an Xcode project. | ||
| */ | ||
|
|
||
| import { clack } from "../utils/clack/prompts.js"; | ||
| import chalk from "chalk"; | ||
|
|
||
| import { withTelemetry } from "../telemetry.js"; | ||
| import { | ||
| confirmContinueIfNoOrDirtyGitRepo, | ||
| featureSelectionPrompt, | ||
| getOrAskForProjectData, | ||
| printWelcome, | ||
| } from "../utils/clack/index.js"; | ||
| import { offerProjectScopedMcpConfig } from "../utils/clack/mcp-config.js"; | ||
| import { Sentry } from "../telemetry.js"; | ||
|
|
||
| import { checkInstalledCLI } from "./check-installed-cli.js"; | ||
| import { configureFastlane } from "./configure-fastlane.js"; | ||
| import { configureSentryCLI } from "./configure-sentry-cli.js"; | ||
| import { configureXcodeProject } from "./configure-xcode-project.js"; | ||
| import { injectCodeSnippet } from "./inject-code-snippet.js"; | ||
| import { | ||
| lookupXcodeProject, | ||
| selectXcodeTarget, | ||
| } from "./lookup-xcode-project.js"; | ||
| import { type AppleWizardOptions } from "./options.js"; | ||
| import { abortIfSpotlightNotSupported } from "../utils/abort-if-sportlight-not-supported.js"; | ||
|
|
||
| export async function runAppleWizard( | ||
| options: AppleWizardOptions, | ||
| ): Promise<void> { | ||
| return await withTelemetry( | ||
| { | ||
| enabled: options.telemetryEnabled, | ||
| integration: "ios", | ||
| wizardOptions: options, | ||
| }, | ||
| () => runAppleWizardWithTelementry(options), | ||
| ); | ||
| } | ||
|
|
||
| async function runAppleWizardWithTelementry( | ||
| options: AppleWizardOptions, | ||
| ): Promise<void> { | ||
| // Define options with defaults | ||
| const projectDir = options.projectDir ?? process.cwd(); | ||
|
|
||
| // Step - Welcome Message | ||
| printWelcome({ | ||
| wizardName: "Sentry Apple Wizard", | ||
| }); | ||
|
|
||
| // Step - Git Status Check | ||
| await confirmContinueIfNoOrDirtyGitRepo({ | ||
| ignoreGitChanges: options.ignoreGitChanges, | ||
| cwd: projectDir, | ||
| }); | ||
|
|
||
| // Step - Sentry CLI Check | ||
| checkInstalledCLI(); | ||
|
|
||
| // Step - Xcode Project Lookup | ||
| // This step should be run before the Sentry Project and API Key step | ||
| // because it can abort the wizard if no Xcode project is found. | ||
| const xcProject = await lookupXcodeProject({ projectDir }); | ||
| const target = await selectXcodeTarget(xcProject); | ||
|
|
||
| // Step - Sentry Project and API Key | ||
| const projectData = await getOrAskForProjectData(options, "apple-ios"); | ||
|
|
||
| if (projectData.spotlight) { | ||
| return await abortIfSpotlightNotSupported("Apple/iOS"); | ||
| } | ||
|
|
||
| const { selectedProject, authToken } = projectData; | ||
|
|
||
| // Step - Sentry CLI Configuration Setup | ||
| configureSentryCLI({ | ||
| projectDir, | ||
| authToken: authToken, | ||
| orgSlug: selectedProject.organization.slug, | ||
| projectSlug: selectedProject.slug, | ||
| }); | ||
|
|
||
| Sentry.setTag("package-manager", "SPM"); | ||
|
|
||
| // Step - Configure Xcode Project | ||
| configureXcodeProject({ | ||
| xcProject, | ||
| project: selectedProject, | ||
| target, | ||
| }); | ||
|
|
||
| // Step - Feature Selection | ||
| const selectedFeatures = await featureSelectionPrompt([ | ||
| { | ||
| id: "logs", | ||
| prompt: `Do you want to enable ${chalk.bold( | ||
| "Logs", | ||
| )} to send your application logs to Sentry?`, | ||
| enabledHint: "optional", | ||
| }, | ||
| ]); | ||
|
|
||
| // Step - Add Code Snippet | ||
| injectCodeSnippet({ | ||
| project: xcProject, | ||
| target, | ||
| dsn: selectedProject.keys[0].dsn.public, | ||
| enableLogs: selectedFeatures["logs"] ?? false, | ||
| }); | ||
|
|
||
| // Step - Fastlane Configuration | ||
| await configureFastlane({ | ||
| projectDir, | ||
| orgSlug: selectedProject.organization.slug, | ||
| projectSlug: selectedProject.slug, | ||
| }); | ||
|
|
||
| // Offer optional project-scoped MCP config for Sentry with org and project scope | ||
| await offerProjectScopedMcpConfig( | ||
| selectedProject.organization.slug, | ||
| selectedProject.slug, | ||
| ); | ||
|
|
||
| clack.log.success( | ||
| "Sentry was successfully added to your project! Run your project to send your first event to Sentry. Go to Sentry.io to see whether everything is working fine.", | ||
| ); | ||
| } | ||
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,92 @@ | ||
| /** | ||
| * Check that the debug-file upload build phase can find `sentry`. | ||
| * | ||
| * The user runs the wizard through `sentry`, so the CLI is installed, but an | ||
| * Xcode build phase doesn't see the user's shell `PATH`: it searches the | ||
| * system directories plus the ones the generated script adds (see | ||
| * {@link xcodeSearchDirs}). Without `sentry` there, the build phase runs it | ||
| * with `npx`, so the wizard only notes that builds would be faster with the | ||
| * CLI installed. With neither, it warns and prints how to install it where | ||
| * Xcode finds it. | ||
| */ | ||
|
|
||
| import { homedir } from "node:os"; | ||
| import path from "node:path"; | ||
|
|
||
| import { whichSync } from "../../which.js"; | ||
| import { Sentry } from "../telemetry.js"; | ||
| import { clack } from "../utils/clack/prompts.js"; | ||
| import { debug } from "../utils/debug.js"; | ||
|
|
||
| /** | ||
| * The directories a Sentry build phase searches for `sentry`: the | ||
| * standalone installer's (`~/.local/bin`, `~/bin`), Homebrew's, and the | ||
| * system ones in Xcode's default `PATH`. | ||
| */ | ||
| export function xcodeSearchDirs(home: string = homedir()): string[] { | ||
| return [ | ||
| path.join(home, ".local", "bin"), | ||
| path.join(home, "bin"), | ||
| "/opt/homebrew/bin", | ||
| "/usr/local/bin", | ||
| "/usr/bin", | ||
| "/bin", | ||
| ]; | ||
| } | ||
|
|
||
| /** Commands that install the Sentry CLI where an Xcode build phase finds it. */ | ||
| const SENTRY_CLI_INSTALL_COMMANDS = [ | ||
| " brew install getsentry/tools/sentry", | ||
| " curl https://cli.sentry.dev/install -fsS | bash", | ||
| " npm install -g sentry", | ||
| ]; | ||
|
|
||
| /** Default warning when `sentry` is out of the build phase's reach. */ | ||
| const DEFAULT_WARNING = | ||
| "Xcode build phases can't find the `sentry` CLI, so your builds won't upload debug symbols to Sentry."; | ||
|
|
||
| /** | ||
| * Whether an Xcode build phase finds `sentry`, or `npx` to run it with, | ||
| * warning with install instructions when it finds neither. | ||
| * | ||
| * @param warning - Explains what doesn't work without `sentry`. | ||
| * @returns The path of the `sentry` or `npx` the build phase would run, if any. | ||
| */ | ||
| export function checkInstalledCLI( | ||
| warning: string = DEFAULT_WARNING, | ||
| ): string | undefined { | ||
| debug("Checking whether Xcode build phases can find sentry"); | ||
| const searchDirs = xcodeSearchDirs(); | ||
| const searchPath = { PATH: searchDirs.join(path.delimiter) }; | ||
| const cliPath = whichSync("sentry", searchPath) ?? undefined; | ||
| Sentry.setTag("has-cli", cliPath !== undefined); | ||
| if (cliPath) { | ||
| debug(`Xcode build phases will run ${cliPath}`); | ||
| return cliPath; | ||
| } | ||
|
|
||
| const npxPath = whichSync("npx", searchPath) ?? undefined; | ||
| if (npxPath) { | ||
| debug(`Xcode build phases will run the Sentry CLI with ${npxPath}`); | ||
| clack.log.info( | ||
| [ | ||
| "Xcode build phases will run the Sentry CLI with `npx sentry`, which downloads it on the first build.", | ||
| "For faster builds, install it with one of:", | ||
| ...SENTRY_CLI_INSTALL_COMMANDS, | ||
| ].join("\n"), | ||
| ); | ||
| return npxPath; | ||
| } | ||
|
|
||
| clack.log.warn( | ||
| [ | ||
| warning, | ||
| "Xcode doesn't use your shell's PATH: it looks in", | ||
| `${searchDirs.join(", ")}.`, | ||
| "", | ||
| "Install the Sentry CLI with one of:", | ||
| ...SENTRY_CLI_INSTALL_COMMANDS, | ||
| ].join("\n"), | ||
| ); | ||
| return undefined; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.