Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Jul 29, 2025

Summary

  • create workflow to run mobile bundle analysis on push or manual trigger

Testing

  • yarn lint
  • yarn build
  • yarn workspace @selfxyz/contracts build (fails: Hardhat config error)
  • yarn types
  • yarn workspace @selfxyz/common test
  • yarn workspace @selfxyz/circuits test (fails: circom missing)
  • yarn workspace @selfxyz/mobile-app test

https://chatgpt.com/codex/tasks/task_b_68886317be64832da01d88b60982e9da

Summary by CodeRabbit

  • New Features
    • Introduced automated bundle size analysis for Android and iOS during pull requests, with clear reporting and artifact uploads.
  • Chores
    • Added new scripts to streamline mobile bundle analysis in CI.
    • Implemented a dedicated CI workflow for mobile bundle analysis.
  • Tests
    • Added tests to ensure reliability and correctness of the bundle analysis script.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 29, 2025

Walkthrough

This change introduces a new automated workflow for analyzing React Native bundle sizes for Android and iOS. It adds platform-specific analysis scripts, a Node.js CLI utility to enforce bundle size thresholds, a corresponding test suite, and a GitHub Actions workflow to run these checks on pull requests and upload bundle reports as artifacts.

Changes

Cohort / File(s) Change Summary
NPM Scripts & Configuration
app/package.json
Added analyze:android:ci and analyze:ios:ci scripts to invoke the new bundle analysis CLI for Android and iOS, replacing the previous bundle visualizer invocation. Updated the test script to run Node.js tests alongside Jest.
Bundle Analysis CLI Script
app/scripts/bundle-analyze-ci.cjs
Introduced a Node.js CLI script to analyze bundle size for a given platform. Enforces platform-specific thresholds, runs the bundle visualizer, checks output, and fails if limits are exceeded. Provides detailed error messages and logs.
CI Workflow
.github/workflows/mobile-bundle-analysis.yml
Added a GitHub Actions workflow to run bundle analysis for Android and iOS on PRs and workflow dispatch. Installs dependencies, runs the analysis scripts, and uploads bundle reports as artifacts.
Test Suite for CLI Script
app/scripts/tests/bundle-analyze-ci.test.cjs
Added tests for the bundle analysis CLI script, verifying argument handling, threshold definitions, error handling, function modularity, and removal of deprecated constants.

Sequence Diagram(s)

sequenceDiagram
    participant GitHub Actions
    participant Runner (macOS)
    participant CLI Script
    participant Bundle Visualizer
    participant File System

    GitHub Actions->>Runner (macOS): Trigger workflow (PR or manual)
    Runner (macOS)->>Runner (macOS): Checkout repo, install deps
    Runner (macOS)->>CLI Script: Run analyze:android:ci or analyze:ios:ci
    CLI Script->>Bundle Visualizer: Execute with platform argument
    Bundle Visualizer->>File System: Generate bundle file
    CLI Script->>File System: Check bundle file exists, get size
    CLI Script->>Runner (macOS): Log result, exit success/failure
    Runner (macOS)->>GitHub Actions: Upload bundle report artifact
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~9 minutes

Poem

A bundle check for every PR,
Ensures our app won’t grow too far.
With scripts and tests and CI flair,
Our mobile code stays light as air.
Reports are stored, the limits clear—
Ship with confidence, have no fear!
📦✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0f3a9e2 and 0fe39b2.

📒 Files selected for processing (2)
  • app/package.json (2 hunks)
  • app/scripts/tests/bundle-analyze-ci.test.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/scripts/tests/bundle-analyze-ci.test.cjs
  • app/package.json
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: analyze-ios
  • GitHub Check: analyze-android
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/add-github-workflows-for-yarn-commands

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
.github/workflows/bundle-analysis.yml (2)

18-57: Reduce duplication with a matrix & add concurrency guard

Both jobs are identical minus the platform. A matrix keeps the file concise, makes future tweaks one-liner changes, and shares caching between runs.
At the same time, heavy bundle analysis should cancel stale runs on the same branch to save CI minutes.

-jobs:
-  analyze-android:
-    runs-on: macos-14
-    steps:
-      - uses: actions/checkout@v4
-      - name: Install Mobile Dependencies
-        uses: ./.github/actions/mobile-setup
-        with:
-          app_path: ${{ env.APP_PATH }}
-          node_version: ${{ env.NODE_VERSION }}
-          ruby_version: ${{ env.RUBY_VERSION }}
-          workspace: ${{ env.WORKSPACE }}
-      - name: Run Android analysis
-        run: yarn analyze:android
-        working-directory: ./app
-      - name: Upload Android bundle report
-        uses: actions/upload-artifact@v4
-        with:
-          name: android-bundle-${{ github.sha }}
-          path: /tmp/react-native-bundle-visualizer/OpenPassport/output/explorer.html
-
-  analyze-ios:
-    runs-on: macos-14
-    steps:
-      - uses: actions/checkout@v4
-      - name: Install Mobile Dependencies
-        uses: ./.github/actions/mobile-setup
-        with:
-          app_path: ${{ env.APP_PATH }}
-          node_version: ${{ env.NODE_VERSION }}
-          ruby_version: ${{ env.RUBY_VERSION }}
-          workspace: ${{ env.WORKSPACE }}
-      - name: Run iOS analysis
-        run: yarn analyze:ios
-        working-directory: ./app
-      - name: Upload iOS bundle report
-        uses: actions/upload-artifact@v4
-        with:
-          name: ios-bundle-${{ github.sha }}
-          path: /tmp/react-native-bundle-visualizer/OpenPassport/output/explorer.html
+jobs:
+  analyze:
+    runs-on: macos-14
+    strategy:
+      matrix:
+        platform: [android, ios]
+    concurrency:
+      group: bundle-${{ github.ref }}-${{ matrix.platform }}
+      cancel-in-progress: true
+    steps:
+      - uses: actions/checkout@v4
+      - name: Install Mobile Dependencies
+        uses: ./.github/actions/mobile-setup
+        with:
+          app_path: ${{ env.APP_PATH }}
+          node_version: ${{ env.NODE_VERSION }}
+          ruby_version: ${{ env.RUBY_VERSION }}
+          workspace: ${{ env.WORKSPACE }}
+      - name: Run ${{ matrix.platform }} analysis
+        run: yarn analyze:${{ matrix.platform }}
+        working-directory: ./app
+      - name: Upload ${{ matrix.platform }} bundle report
+        uses: actions/upload-artifact@v4
+        with:
+          name: ${{ matrix.platform }}-bundle-${{ github.sha }}
+          path: /tmp/react-native-bundle-visualizer/OpenPassport/output/explorer.html

30-33: Harden against missing scripts

If yarn analyze:android/ios is absent or renamed, the workflow bails out late. Add --if-present to fail softly and surface a clearer log, or enforce presence via yarn workspaces info before the run.

-        run: yarn analyze:${{ matrix.platform }}
+        run: yarn analyze:${{ matrix.platform }} --if-present

Alternatively, insert a script-existence assertion step first.

Also applies to: 51-52

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee297e7 and 0f89aeb.

📒 Files selected for processing (1)
  • .github/workflows/bundle-analysis.yml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
.github/workflows/bundle-analysis.yml (1)

Learnt from: transphorm
PR: #795
File: app/android/app/build.gradle:157-158
Timestamp: 2025-07-29T01:08:28.530Z
Learning: For this React Native project, the team prefers build flexibility over fail-fast behavior for release builds in app/android/app/build.gradle. They intentionally allow fallback to debug signing for local development runs, relying on Google Play Console validation to catch any improperly signed releases during upload.

🔇 Additional comments (1)
.github/workflows/bundle-analysis.yml (1)

3-8: Verify Node version usage & remove unused JAVA_VERSION

I didn’t find any references to JAVA_VERSION or NODE_VERSION in the workflow steps:

.github/workflows/bundle-analysis.yml env block declares

  • NODE_VERSION: 18
  • JAVA_VERSION: 17

• Ripgrep checks show

  • No JAVA_VERSION usages anywhere in the repo
  • No actions/setup-node or node-version settings in this workflow
  • No interpolations of ${{ env.NODE_VERSION }}

Please confirm how you’re selecting or installing Node in this job. If you do rely on NODE_VERSION, update it to 20 for active-LTS. Otherwise, drop the entire NODE_VERSION entry. In either case, JAVA_VERSION can be removed as dead weight.

@transphorm transphorm force-pushed the codex/add-github-workflows-for-yarn-commands branch from 905166e to 61db0f3 Compare July 29, 2025 15:20
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
app/scripts/bundle-analyze-ci.cjs (3)

13-13: Enhance number parsing robustness.

Consider validating the parsed number to handle invalid environment variable values gracefully.

-const warning = Number(process.env.BUNDLE_WARNING_INCREASE || '0');
+const warning = parseInt(process.env.BUNDLE_WARNING_INCREASE || '0', 10) || 0;

This ensures the warning threshold is always a valid integer, even if the environment variable contains invalid data.


15-33: Good defensive programming with room for improvement.

The utility functions handle edge cases well. Consider these enhancements for better robustness:

 function sanitize(str) {
-  return str ? str.replace(/[^\w]/g, '') : str;
+  return str ? str.replace(/[^\w-]/g, '') : str;
 }

Allow hyphens in app names as they're common and safe for file paths.

-    return sanitize(appJson.name || (appJson.expo && appJson.expo.name));
+    return sanitize(appJson.name || appJson.expo?.name);

Use optional chaining for safer property access (requires Node.js 14+).


41-43: Command execution is well-implemented.

Good use of stdio: 'inherit' for CI visibility. The command construction is safe given the platform validation.

Consider adding platform validation for extra security:

+// Validate platform is one of expected values
+if (!['android', 'ios'].includes(platform)) {
+  console.error('Platform must be either "android" or "ios"');
+  process.exit(1);
+}
+
 execSync(`react-native-bundle-visualizer --platform ${platform} --dev`, {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 11f8798 and 61db0f3.

📒 Files selected for processing (3)
  • .github/workflows/bundle-analysis.yml (1 hunks)
  • app/package.json (1 hunks)
  • app/scripts/bundle-analyze-ci.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/package.json
  • .github/workflows/bundle-analysis.yml
🧰 Additional context used
🪛 GitHub Check: lint
app/scripts/bundle-analyze-ci.cjs

[warning] 49-49:
Unexpected console statement


[warning] 9-9:
Unexpected console statement

🔇 Additional comments (4)
app/scripts/bundle-analyze-ci.cjs (4)

1-5: LGTM! Clean module imports and proper shebang.

The Node.js shebang and standard library imports are appropriate for this CI script's functionality.


7-11: Platform validation looks good.

The argument validation is robust with clear error messaging. The console.error usage is appropriate for CLI scripts despite static analysis warnings.


35-39: Solid file handling and path construction.

Good use of OS temp directory and defensive file existence checking. The path isolation by app name prevents conflicts between different projects.


45-53: Excellent bundle size monitoring implementation.

The size comparison logic is thorough and provides valuable CI feedback. The warning message is informative with good visual indicators. Console usage is appropriate for CLI scripts despite static analysis flags.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (1)
app/scripts/bundle-analyze-ci.cjs (1)

23-37: Add error logging for configuration file issues.

While the try-catch blocks handle errors gracefully, silent failures make debugging difficult in CI environments. Consider adding debug logging.

 function getAppName() {
   try {
     const pkg = JSON.parse(
       fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'),
     );
     if (pkg.name) return sanitize(pkg.name);
-  } catch {}
+  } catch (error) {
+    console.warn('Warning: Could not read package.json:', error.message);
+  }
   try {
     const appJson = JSON.parse(
       fs.readFileSync(path.join(__dirname, '..', 'app.json'), 'utf8'),
     );
     return sanitize(appJson.name || (appJson.expo && appJson.expo.name));
-  } catch {}
+  } catch (error) {
+    console.warn('Warning: Could not read app.json:', error.message);
+  }
   return 'UnknownApp';
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2a7a50 and 0f3a9e2.

📒 Files selected for processing (3)
  • .github/workflows/mobile-bundle-analysis.yml (1 hunks)
  • app/scripts/bundle-analyze-ci.cjs (1 hunks)
  • app/scripts/tests/bundle-analyze-ci.test.cjs (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .github/workflows/mobile-bundle-analysis.yml
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: transphorm
PR: selfxyz/self#795
File: app/android/app/build.gradle:157-158
Timestamp: 2025-07-29T01:08:28.530Z
Learning: For this React Native project, the team prefers build flexibility over fail-fast behavior for release builds in app/android/app/build.gradle. They intentionally allow fallback to debug signing for local development runs, relying on Google Play Console validation to catch any improperly signed releases during upload.
Learnt from: transphorm
PR: selfxyz/self#636
File: app/android/app/build.gradle:76-76
Timestamp: 2025-06-30T15:51:11.193Z
Learning: For React Native 0.80, the correct JSC version is `io.github.react-native-community:jsc-android:2026004.+`. This version was specifically built with Android NDK r23 to align with React Native 0.80's NDK requirements and prevent compatibility issues. The `2026004` version pattern is the official version for RN 0.80, not an outdated pin.
🪛 GitHub Check: lint
app/scripts/bundle-analyze-ci.cjs

[warning] 69-69:
Unexpected console statement


[warning] 63-63:
Unexpected console statement


[warning] 62-62:
Unexpected console statement


[warning] 61-61:
Unexpected console statement


[warning] 60-60:
Unexpected console statement


[warning] 57-57:
Unexpected console statement


[warning] 51-51:
Unexpected console statement


[warning] 50-50:
Unexpected console statement


[warning] 46-46:
'platform' is already declared in the upper scope on line 7 column 7


[warning] 9-9:
Unexpected console statement

⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: analyze-android
  • GitHub Check: build
🔇 Additional comments (6)
app/scripts/bundle-analyze-ci.cjs (1)

9-9: Console statements are appropriate for CLI tools.

The static analysis warnings about console statements can be ignored here since this is a CLI tool where console output is expected and necessary for user feedback.

Also applies to: 50-64, 69-69

app/scripts/tests/bundle-analyze-ci.test.cjs (5)

11-15: Good coverage for missing platform argument.

The test correctly validates that the script exits with an error when no platform is provided. This is essential for CLI argument validation.


45-49: Excellent error handling validation.

The test properly validates that the script handles missing bundle files gracefully with appropriate error messages and exit codes.


51-58: Good user experience validation.

Testing for helpful error messages ensures developers understand how to resolve threshold issues. This promotes maintainability.


60-65: Comprehensive function validation.

The test ensures the DRY principle is followed with proper return values for the checkBundleSize function. This validates the refactoring from previous implementations.


17-21: Verify platform‐validation in the CLI

The test in app/scripts/tests/bundle-analyze-ci.test.cjs (lines 17–21) assumes an invalid platform argument will cause the script to exit with an error. However, we haven’t been able to locate any code in the CLI that explicitly validates or rejects unrecognized platform strings. Please confirm:

  • That the scriptPath in the test points to the correct entrypoint for your bundle-analyze-ci tool.
  • Whether the implementation maintains a whitelist of valid platforms (e.g. ['ios', 'android', 'web']) and throws or calls process.exit(1) on anything else.
  • If no such validation exists, either add a guard in the CLI (and tests for each supported platform) or adjust the test to reflect the real behavior.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants