Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/bundle-analysis.yml
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
2 changes: 2 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"type": "module",
"scripts": {
"analyze:android": "yarn reinstall && react-native-bundle-visualizer --platform android --dev",
"analyze:android:ci": "node ./scripts/bundle-analyze-ci.cjs android",
"analyze:ios": "yarn reinstall && react-native-bundle-visualizer --platform ios --dev",
"analyze:ios:ci": "node ./scripts/bundle-analyze-ci.cjs ios",
"android": "react-native run-android",
"build:deps": "yarn workspaces foreach --from @selfxyz/mobile-app --topological --recursive run build",
"bump-version:major": "npm version major && yarn sync-versions",
Expand Down
53 changes: 53 additions & 0 deletions app/scripts/bundle-analyze-ci.cjs
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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 9 in app/scripts/bundle-analyze-ci.cjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
process.exit(1);
}

const warning = Number(process.env.BUNDLE_WARNING_INCREASE || '0');

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

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',
});

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

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check warning on line 49 in app/scripts/bundle-analyze-ci.cjs

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
`\u26A0\uFE0F Bundle increased by ${delta} bytes (threshold ${warning}).`,
);
}
}
Loading