-
Notifications
You must be signed in to change notification settings - Fork 0
117 lines (98 loc) · 4.19 KB
/
rn-bundle-analysis.yml
File metadata and controls
117 lines (98 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
name: React Native Bundle Analysis
on:
pull_request:
paths:
- 'frontend/**'
branches: [ main, master ]
push:
paths:
- 'frontend/**'
branches: [ main, master ]
jobs:
rn-bundle-analysis:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Install Dependencies
run: npm install
working-directory: ./frontend
- name: Analyze React Native Bundle Size
working-directory: ./frontend
run: |
echo "📊 Analyzing React Native bundle size..."
# Install bundle analysis tools
npm install --no-save metro-visualizer
# Create bundle for Android (this usually works better than web)
echo "🤖 Creating Android bundle for analysis..."
if npx expo export --platform android --output-dir android-build --max-workers 1; then
echo "✅ Android export successful"
# Find and analyze the bundle
if [ -f "android-build/bundles/android-*.js" ]; then
BUNDLE_FILE=$(find android-build/bundles -name "android-*.js" | head -1)
BUNDLE_SIZE=$(stat -c%s "$BUNDLE_FILE")
BUNDLE_SIZE_MB=$(echo "scale=2; $BUNDLE_SIZE / 1024 / 1024" | bc -l)
echo "# React Native Bundle Analysis Report" > bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Bundle Size Summary" >> bundle-analysis.md
echo "- Platform: Android (React Native)" >> bundle-analysis.md
echo "- Bundle size: **${BUNDLE_SIZE_MB} MB**" >> bundle-analysis.md
echo "- Bundler: Metro (Expo)" >> bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Bundle Details" >> bundle-analysis.md
echo "- File: $(basename "$BUNDLE_FILE")" >> bundle-analysis.md
echo "- Size: ${BUNDLE_SIZE_MB} MB" >> bundle-analysis.md
echo "📊 Bundle analysis complete: ${BUNDLE_SIZE_MB} MB"
else
echo "❌ No Android bundle found"
ls -la android-build/
fi
else
echo "⚠️ Android export failed, analyzing dependencies instead..."
# Fallback: analyze key dependencies
echo "# React Native Bundle Analysis Report (Dependencies)" > bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Dependencies Analysis" >> bundle-analysis.md
echo "Bundle creation failed, analyzing key dependencies:" >> bundle-analysis.md
echo "" >> bundle-analysis.md
# Get sizes of major dependencies
if command -v du >/dev/null 2>&1; then
echo "### Core Dependencies" >> bundle-analysis.md
for dep in react react-native expo @react-navigation; do
if [ -d "node_modules/$dep" ]; then
size=$(du -sh "node_modules/$dep" 2>/dev/null | cut -f1)
echo "- $dep: $size" >> bundle-analysis.md
fi
done
fi
echo "" >> bundle-analysis.md
echo "Note: Bundle size analysis requires successful export. Check React Native compatibility." >> bundle-analysis.md
fi
# Install bc for calculations if needed
sudo apt-get update && sudo apt-get install -y bc
# Display the report
if [ -f "bundle-analysis.md" ]; then
cat bundle-analysis.md
fi
- name: Upload RN Bundle Analysis Report
if: always() && hashFiles('frontend/bundle-analysis.md') != ''
uses: actions/upload-artifact@v5
with:
name: rn-bundle-analysis-report
path: frontend/bundle-analysis.md
retention-days: 30
- name: RN Bundle Analysis Skipped
if: github.actor == 'dependabot[bot]'
run: echo "📦 React Native bundle analysis skipped for Dependabot PR"