-
Notifications
You must be signed in to change notification settings - Fork 181
Add bundle analysis workflow #802
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 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
140f5d6
Add bundle analysis workflow
transphorm 23a67c8
Fix bundle analysis workflow
transphorm adea26c
Add adjustable bundle size warning
transphorm 8fc21e8
pretty
transphorm 61db0f3
update pull request paths
transphorm b2a7a50
update Gemfile.lock
transphorm c5ce1a7
rename
transphorm 0f3a9e2
pipeline tweaks
transphorm 0fe39b2
fix tests
transphorm 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 |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| name: Mobile Bundle Analysis | ||
|
|
||
| env: | ||
| NODE_VERSION: 18 | ||
| RUBY_VERSION: 3.2 | ||
| JAVA_VERSION: 17 | ||
| WORKSPACE: ${{ github.workspace }} | ||
| APP_PATH: ${{ github.workspace }}/app | ||
| WARNING_INCREASE: 0 | ||
|
|
||
| on: | ||
| push: | ||
| paths: | ||
| - "app/**" | ||
| - ".github/workflows/bundle-analysis.yml" | ||
| - ".github/actions/**" | ||
| pull_request: | ||
| paths: | ||
| - "app/**" | ||
| - ".github/workflows/bundle-analysis.yml" | ||
| - ".github/actions/**" | ||
| workflow_dispatch: | ||
|
|
||
| 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: BUNDLE_WARNING_INCREASE=${{ env.WARNING_INCREASE }} yarn analyze:android:ci | ||
| 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: BUNDLE_WARNING_INCREASE=${{ env.WARNING_INCREASE }} yarn analyze:ios:ci | ||
| 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 |
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,53 @@ | ||
| #!/usr/bin/env node | ||
| const { execSync } = require('child_process'); | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
|
|
||
| const platform = process.argv[2]; | ||
| if (!platform) { | ||
| console.error('Usage: bundle-analyze-ci.cjs <platform>'); | ||
|
Check warning on line 9 in app/scripts/bundle-analyze-ci.cjs
|
||
| process.exit(1); | ||
| } | ||
|
|
||
| const warning = Number(process.env.BUNDLE_WARNING_INCREASE || '0'); | ||
|
|
||
| function sanitize(str) { | ||
| return str ? str.replace(/[^\w]/g, '') : str; | ||
| } | ||
transphorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function getAppName() { | ||
| try { | ||
| const pkg = JSON.parse( | ||
| fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'), | ||
| ); | ||
| if (pkg.name) return sanitize(pkg.name); | ||
| } catch {} | ||
| try { | ||
| const appJson = JSON.parse( | ||
| fs.readFileSync(path.join(__dirname, '..', 'app.json'), 'utf8'), | ||
| ); | ||
| return sanitize(appJson.name || (appJson.expo && appJson.expo.name)); | ||
| } catch {} | ||
| return 'UnknownApp'; | ||
| } | ||
|
|
||
| const baseDir = path.join(os.tmpdir(), 'react-native-bundle-visualizer'); | ||
| const tmpDir = path.join(baseDir, getAppName()); | ||
| const bundleFile = path.join(tmpDir, `${platform}.bundle`); | ||
| let prevSize = 0; | ||
| if (fs.existsSync(bundleFile)) prevSize = fs.statSync(bundleFile).size; | ||
|
|
||
| execSync(`react-native-bundle-visualizer --platform ${platform} --dev`, { | ||
| stdio: 'inherit', | ||
| }); | ||
transphorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (fs.existsSync(bundleFile) && warning > 0) { | ||
| const newSize = fs.statSync(bundleFile).size; | ||
| const delta = newSize - prevSize; | ||
| if (delta > warning) { | ||
| console.warn( | ||
|
Check warning on line 49 in app/scripts/bundle-analyze-ci.cjs
|
||
| `\u26A0\uFE0F Bundle increased by ${delta} bytes (threshold ${warning}).`, | ||
| ); | ||
| } | ||
| } | ||
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.