Skip to content

fix(apple): Added methods to add and update Sentry build phase script - #1029

Merged
philprime merged 12 commits into
masterfrom
philprime/update-existing-upload-symbols-script
Jul 29, 2025
Merged

philprime merged 12 commits into
masterfrom
philprime/update-existing-upload-symbols-script

Conversation

@philprime

@philprime philprime commented Jul 24, 2025 •

Copy link
Copy Markdown
Member

This PR should be merged after #1028 is merged.

This PR fixes #987 by updating existing Sentry build phase scripts instead of re-creating them.

It can be tested by using the following command from the project root:

yarn try --debug -i ios --xcode-project-dir fixtures/test-applications/apple/project-with-synchronized-folders --preSelectedProject.authToken AUTH_TOKEN --preSelectedProject.dsn MY_DSN --preSelectedProject.orgSlug MY_ORG_SLUG --preSelectedProejct.projectSlug MY_PROJECT_SLUG --ignore-git-changes
  • Use git to view the changes in fixtures/test-applications/apple/project-with-synchronized-folders/Project.xcodeproj/project.pbxproj and it will have added a new script called Upload Debug Symbols to Sentry.
  • Stage the changes then run the command again. No further changes should show up.
    Closes Fix Xcode build script injection to remove orphaned build scripts #987

@philprime
philprime requested a review from philippsuess July 24, 2025 10:10
@philprime philprime self-assigned this Jul 24, 2025
@codecov

codecov Bot commented Jul 24, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 28.61%. Comparing base (45ec3d3) to head (08cf16b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1029      +/-   ##
==========================================
+ Coverage   28.09%   28.61%   +0.51%     
==========================================
  Files         128      128              
  Lines       14452    14539      +87     
  Branches      904      932      +28     
==========================================
+ Hits         4061     4160      +99     
+ Misses      10374    10362      -12     
  Partials       17       17              
Flag Coverage Δ
unit-tests 28.61% <100.00%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@philprime
philprime marked this pull request as ready for review July 25, 2025 09:55
Base automatically changed from philprime/refactor-upload-symbols-script to master July 25, 2025 09:55
@philprime
philprime marked this pull request as draft July 25, 2025 09:56
@philprime
philprime marked this pull request as ready for review July 25, 2025 09:59
inputPaths: string[] = [],
): string {
const buildPhaseUuid = this.project.generateUuid();
const escapedScript = script.replace(/"/g, '\\"');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

To fix the issue, we need to ensure that backslashes in the script parameter are properly escaped before the string is used. This can be achieved by first replacing all backslashes (\) with double backslashes (\\) and then escaping double quotes ("). This ensures that both backslashes and double quotes are correctly handled.

The best way to implement this fix is to use two replace calls in sequence:

  1. Replace all backslashes with double backslashes.
  2. Replace all double quotes with escaped double quotes.

Alternatively, a single regular expression can be used to handle both cases, but the two-step approach is simpler and easier to understand.


Suggested changeset 1
src/apple/xcode-manager.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apple/xcode-manager.ts b/src/apple/xcode-manager.ts
--- a/src/apple/xcode-manager.ts
+++ b/src/apple/xcode-manager.ts
@@ -528,3 +528,3 @@
     const buildPhaseUuid = this.project.generateUuid();
-    const escapedScript = script.replace(/"/g, '\\"');
+    const escapedScript = script.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
 
EOF
@@ -528,3 +528,3 @@
const buildPhaseUuid = this.project.generateUuid();
const escapedScript = script.replace(/"/g, '\\"');
const escapedScript = script.replace(/\\/g, '\\\\').replace(/"/g, '\\"');

Copilot is powered by AI and may make mistakes. Always verify output.
@philprime philprime committed this autofix suggestion about 1 year ago.
return;
}

const escapedScript = script.replace(/"/g, '\\"');

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

To fix the problem, we should ensure that both backslashes and double quotes are escaped in the script string before embedding it in the shell script. This can be done by first replacing all backslashes with double backslashes, and then replacing all double quotes with escaped double quotes, using regular expressions with the global flag. The fix should be applied to line 581 in the updateScriptBuildPhase method, making it consistent with the escaping logic used in the addScriptBuildPhase method on line 529. No new imports or dependencies are required.

Suggested changeset 1
src/apple/xcode-manager.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/apple/xcode-manager.ts b/src/apple/xcode-manager.ts
--- a/src/apple/xcode-manager.ts
+++ b/src/apple/xcode-manager.ts
@@ -580,3 +580,3 @@
 
-    const escapedScript = script.replace(/"/g, '\\"');
+    const escapedScript = script.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
     buildPhase.shellScript = `"${escapedScript}"`;
EOF
@@ -580,3 +580,3 @@

const escapedScript = script.replace(/"/g, '\\"');
const escapedScript = script.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
buildPhase.shellScript = `"${escapedScript}"`;
Copilot is powered by AI and may make mistakes. Always verify output.
@philprime philprime committed this autofix suggestion about 1 year ago.
philprime and others added 3 commits July 28, 2025 09:49
…ing or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ing or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@philprime

Copy link
Copy Markdown
Member Author

Converting back to draft because tests are failing

@philprime
philprime marked this pull request as draft July 28, 2025 07:57
@philprime
philprime marked this pull request as ready for review July 28, 2025 08:26

@philippsuess philippsuess left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, the PR description mentions how to test this change. Is it worth the effort to add these manual test to the test suite?

@philprime

Copy link
Copy Markdown
Member Author

Looking at the change in code coverage from Codecov, I'll add additional tests to keep coverage up.

We should implement the command as an integration test case in #888.

@philprime
philprime marked this pull request as draft July 28, 2025 11:38
@philippsuess

Copy link
Copy Markdown
Contributor

You can still merge the PR, if you want to and follow up with the tests. Up to you @philprime.

@philprime
philprime marked this pull request as ready for review July 29, 2025 14:37
@philprime
philprime merged commit d4d2459 into master Jul 29, 2025
@philprime
philprime deleted the philprime/update-existing-upload-symbols-script branch July 29, 2025 14:37
@github-actions

Copy link
Copy Markdown
Fails
🚫 Please consider adding a changelog entry for the next release.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

- Added methods to add and update Sentry build phase script ([#1029](https://github.com/getsentry/sentry-wizard/pull/1029))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description.

Generated by 🚫 dangerJS against 08cf16b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix Xcode build script injection to remove orphaned build scripts

3 participants