-
Notifications
You must be signed in to change notification settings - Fork 25
166 lines (145 loc) · 6.78 KB
/
bundle-analysis.yml
File metadata and controls
166 lines (145 loc) · 6.78 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Bundle Analysis
on:
pull_request:
paths:
- 'frontend/**'
branches: [ main, master ]
push:
paths:
- 'frontend/**'
branches: [ main, master ]
jobs:
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: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install Dependencies
run: npm install
working-directory: ./frontend
- name: Setup EAS
uses: expo/expo-github-action@v8
with:
eas-version: latest
token: ${{ secrets.EXPO_TOKEN }}
- name: Build for Bundle Analysis
run: |
# Try to build with Expo for web, but handle React Native compatibility issues
if npx expo export --platform web --output-dir web-build 2>/dev/null; then
echo "✅ Expo web export successful"
else
echo "⚠️ Web export failed, using alternative bundle analysis approach"
# Create a basic bundle using Metro bundler directly
npx metro build --entry-file index.js --platform web --bundle-output web-build/bundle.js --assets-dest web-build/static || true
# If that also fails, create a minimal analysis report
if [ ! -f "web-build/bundle.js" ]; then
echo "📊 Creating basic size analysis from node_modules..."
mkdir -p web-build/static/js
# Analyze the main dependencies that would be bundled
echo "# Bundle Analysis Report (Estimated)" > bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Bundle Size Analysis" >> bundle-analysis.md
echo "- React Native web build failed due to platform-specific modules" >> bundle-analysis.md
echo "- This is common with React Native apps that use platform-specific code" >> bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Key Dependencies Analysis" >> bundle-analysis.md
du -sh node_modules/react node_modules/react-native node_modules/@expo 2>/dev/null | while read size dir; do
echo "- ${dir}: ${size}" >> bundle-analysis.md
done || echo "- Unable to analyze individual dependencies" >> bundle-analysis.md
exit 0
fi
fi
working-directory: ./frontend
- name: Analyze Bundle Size
working-directory: ./frontend
run: |
# Install analysis tools
npm install --no-save @expo/metro-config metro-visualizer
sudo apt-get update && sudo apt-get install -y bc
echo "📊 Analyzing bundle size for Expo/React Native project..."
# Check if bundle analysis report already exists (from build step failure handling)
if [ -f "bundle-analysis.md" ]; then
echo "� Using existing analysis report from build step"
cat bundle-analysis.md
exit 0
fi
# Check if web-build directory exists
if [ -d "web-build" ]; then
echo "✅ Web build directory found"
ls -la web-build/
# Look for JavaScript bundles in various locations
BUNDLE_FOUND=false
# Check standard Expo web build structure
if [ -d "web-build/static/js" ] && [ "$(ls -A web-build/static/js 2>/dev/null)" ]; then
echo "📁 JavaScript bundle files in static/js:"
find web-build/static/js -name "*.js" -type f -exec ls -lh {} \; | awk '{print $5 " " $9}'
# Calculate total bundle size
TOTAL_SIZE=$(find web-build/static/js -name "*.js" -type f -exec stat -c%s {} \; | awk '{sum+=$1} END {print sum}')
TOTAL_SIZE_MB=$(echo "scale=2; $TOTAL_SIZE / 1024 / 1024" | bc -l)
echo "📊 Total JavaScript bundle size: ${TOTAL_SIZE_MB} MB"
BUNDLE_FOUND=true
elif [ -f "web-build/bundle.js" ]; then
echo "📁 Single bundle file found:"
ls -lh web-build/bundle.js
BUNDLE_SIZE=$(stat -c%s web-build/bundle.js)
TOTAL_SIZE_MB=$(echo "scale=2; $BUNDLE_SIZE / 1024 / 1024" | bc -l)
echo "📊 Bundle size: ${TOTAL_SIZE_MB} MB"
BUNDLE_FOUND=true
fi
if [ "$BUNDLE_FOUND" = true ]; then
# Create analysis report
echo "# Bundle Analysis Report" > bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Bundle Size Summary" >> bundle-analysis.md
echo "- Total JavaScript bundle size: **${TOTAL_SIZE_MB} MB**" >> bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Build Details" >> bundle-analysis.md
echo "- Platform: Web (React Native)" >> bundle-analysis.md
echo "- Bundler: Metro (Expo)" >> bundle-analysis.md
echo "" >> bundle-analysis.md
if [ -d "web-build/static/js" ]; then
echo "## Individual Files" >> bundle-analysis.md
find web-build/static/js -name "*.js" -type f -exec ls -lh {} \; | awk '{print "- " $9 ": " $5}' >> bundle-analysis.md
fi
cat bundle-analysis.md
else
echo "❌ No JavaScript bundles found in expected locations"
echo "📁 Available files in web-build:"
find web-build -type f -name "*.js" -o -name "*.json" | head -10
fi
else
echo "❌ No web-build directory found"
echo "📁 Available directories:"
ls -la
# Create fallback analysis
echo "# Bundle Analysis Report (Fallback)" > bundle-analysis.md
echo "" >> bundle-analysis.md
echo "## Analysis Status" >> bundle-analysis.md
echo "- Web build failed - this is common for React Native apps with platform-specific code" >> bundle-analysis.md
echo "- Bundle analysis skipped for this build" >> bundle-analysis.md
fi
- name: Upload Bundle Analysis Report
if: always() && hashFiles('frontend/bundle-analysis.md') != ''
uses: actions/upload-artifact@v4
with:
name: bundle-analysis-report
path: frontend/bundle-analysis.md
retention-days: 30
- name: Upload Bundle Analysis to Codecov
uses: codecov/codecov-action@v5
if: github.actor != 'dependabot[bot]' && hashFiles('frontend/bundle-analysis.md') != ''
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: bundle,frontend,javascript
name: "Bundle Analysis"
fail_ci_if_error: false
- name: Bundle Analysis Skipped
if: github.actor == 'dependabot[bot]'
run: echo "📦 Bundle analysis skipped for Dependabot PR"