-
Notifications
You must be signed in to change notification settings - Fork 67
353 lines (289 loc) · 12.1 KB
/
build-size-comparison.yml
File metadata and controls
353 lines (289 loc) · 12.1 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
name: Build Size Comparison
on:
pull_request:
branches: [ master, develop ]
jobs:
build-and-compare:
runs-on: ubuntu-latest
steps:
- name: Checkout current PR
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Checkout base branch
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}
path: base-branch
- name: Checkout Premium Repo (Current PR)
uses: actions/checkout@v4
with:
repository: 'bfintal/Stackable-Premium'
ref: 'v3'
path: 'pro__premium_only'
token: '${{ secrets.ACCESS_KEY }}'
- name: Checkout Premium Repo (Base Branch)
uses: actions/checkout@v4
with:
repository: 'bfintal/Stackable-Premium'
ref: 'v3'
path: 'base-branch/pro__premium_only'
token: '${{ secrets.ACCESS_KEY }}'
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 14.x
cache: 'npm'
- name: Install Dependencies (Current PR)
run: |
npm ci --legacy-peer-deps
cd pro__premium_only
npm ci --legacy-peer-deps
- name: Install Dependencies (Base Branch)
run: |
cd base-branch
npm ci --legacy-peer-deps
cd pro__premium_only
npm ci --legacy-peer-deps
- name: Build Current PR
run: |
npm run build:no-translate
- name: Build Base Branch
run: |
cd base-branch
npm run build:no-translate
- name: Create Zip Files
run: |
# Create zip for current PR
cd build/stackable
zip -r ../../current-build.zip . -x "*.map" "node_modules/*"
# Create zip for base branch
cd ../../base-branch/build/stackable
zip -r ../../../base-build.zip . -x "*.map" "node_modules/*"
# Move zip files to root directory for easier access
cd ../../../
ls -la *.zip
- name: Extract and Compare Files
run: |
# Extract both zip files
mkdir -p current-files base-files
unzip -q current-build.zip -d current-files/
unzip -q base-build.zip -d base-files/
# Create comparison script
cat > compare_files.py << 'EOF'
import os
import json
from pathlib import Path
def get_file_size(filepath):
if os.path.exists(filepath):
return os.path.getsize(filepath)
return 0
def format_bytes(bytes):
for unit in ['B', 'KB', 'MB', 'GB']:
if bytes < 1024.0:
return f"{bytes:.1f}{unit}"
bytes /= 1024.0
return f"{bytes:.1f}TB"
def compare_directories(current_dir, base_dir):
current_path = Path(current_dir)
base_path = Path(base_dir)
all_files = set()
# Get all files from both directories
for file_path in current_path.rglob('*'):
if file_path.is_file():
rel_path = file_path.relative_to(current_path)
all_files.add(str(rel_path))
for file_path in base_path.rglob('*'):
if file_path.is_file():
rel_path = file_path.relative_to(base_path)
all_files.add(str(rel_path))
changes = []
total_current = 0
total_base = 0
for file_path in sorted(all_files):
current_file = current_path / file_path
base_file = base_path / file_path
current_size = get_file_size(current_file)
base_size = get_file_size(base_file)
total_current += current_size
total_base += base_size
if current_size != base_size:
diff = current_size - base_size
if base_size > 0:
percent = (diff / base_size) * 100
else:
percent = 100 if current_size > 0 else 0
status = "🆕" if base_size == 0 else "❌" if current_size == 0 else "📝"
changes.append({
'file': file_path,
'current_size': current_size,
'base_size': base_size,
'diff': diff,
'percent': percent,
'status': status
})
return changes, total_current, total_base
# Compare files
changes, total_current, total_base = compare_directories('current-files', 'base-files')
# Create summary
total_diff = total_current - total_base
total_percent = (total_diff / total_base * 100) if total_base > 0 else 0
# Flag large changes (>10% or >100KB)
flagged_changes = [c for c in changes if abs(c['percent']) > 10 or abs(c['diff']) > 102400]
# Generate report
report = {
'total_current': total_current,
'total_base': total_base,
'total_diff': total_diff,
'total_percent': total_percent,
'changes': changes,
'flagged_changes': flagged_changes
}
with open('comparison_report.json', 'w') as f:
json.dump(report, f, indent=2)
# Print summary to console
print(f"Total size change: {format_bytes(total_diff)} ({total_percent:+.1f}%)")
print(f"Files changed: {len(changes)}")
print(f"Flagged changes: {len(flagged_changes)}")
EOF
python3 compare_files.py
- name: Generate PR Comment
id: pr_comment
run: |
# Read the comparison report
python3 -c "
import json
with open('comparison_report.json', 'r') as f:
report = json.load(f)
def format_bytes(bytes):
for unit in ['B', 'KB', 'MB', 'GB']:
if bytes < 1024.0:
return f'{bytes:.1f}{unit}'
bytes /= 1024.0
return f'{bytes:.1f}TB'
# Generate comment
comment = '## 📦 Build Size Comparison\n\n'
# Overall summary
total_current = report['total_current']
total_base = report['total_base']
total_diff = report['total_diff']
total_percent = report['total_percent']
comment += '| Build | Size |\n'
comment += '|-------|------|\n'
comment += f'| **Current PR** | **{format_bytes(total_current)}** |\n'
comment += f'| Base Branch | {format_bytes(total_base)} |\n\n'
if total_diff > 0:
comment += f'📈 **Total size increased by** {format_bytes(total_diff)} (+{total_percent:.1f}%)\n\n'
elif total_diff < 0:
comment += f'📉 **Total size decreased by** {format_bytes(abs(total_diff))} ({total_percent:.1f}%)\n\n'
else:
comment += '✅ **No total size change**\n\n'
# File changes summary
changes = report['changes']
flagged = report['flagged_changes']
comment += f'**Files changed:** {len(changes)}\n'
comment += f'**Large changes flagged:** {len(flagged)}\n\n'
if flagged:
comment += '## ⚠️ Large Changes (Requires Review)\n\n'
comment += '| File | Current | Base | Change | % | Status |\n'
comment += '|------|---------|------|--------|---|--------|\n'
for change in flagged:
status_icon = change['status']
file_name = change['file']
current_size = format_bytes(change['current_size'])
base_size = format_bytes(change['base_size'])
diff_size = format_bytes(abs(change['diff']))
percent = change['percent']
if change['diff'] > 0:
change_str = f'+{diff_size}'
elif change['diff'] < 0:
change_str = f'-{diff_size}'
else:
change_str = '0B'
comment += f'| `{file_name}` | {current_size} | {base_size} | {change_str} | {percent:+.1f}% | {status_icon} |\n'
comment += '\n'
# All changes table (if not too many)
if len(changes) <= 50:
comment += '## 📋 All File Changes\n\n'
comment += '| File | Current | Base | Change | % | Status |\n'
comment += '|------|---------|------|--------|---|--------|\n'
for change in changes:
status_icon = change['status']
file_name = change['file']
current_size = format_bytes(change['current_size'])
base_size = format_bytes(change['base_size'])
diff_size = format_bytes(abs(change['diff']))
percent = change['percent']
if change['diff'] > 0:
change_str = f'+{diff_size}'
elif change['diff'] < 0:
change_str = f'-{diff_size}'
else:
change_str = '0B'
comment += f'| `{file_name}` | {current_size} | {base_size} | {change_str} | {percent:+.1f}% | {status_icon} |\n'
else:
comment += f'## 📋 File Changes (showing first 50 of {len(changes)})\n\n'
comment += '| File | Current | Base | Change | % | Status |\n'
comment += '|------|---------|------|--------|---|--------|\n'
for change in changes[:50]:
status_icon = change['status']
file_name = change['file']
current_size = format_bytes(change['current_size'])
base_size = format_bytes(change['base_size'])
diff_size = format_bytes(abs(change['diff']))
percent = change['percent']
if change['diff'] > 0:
change_str = f'+{diff_size}'
elif change['diff'] < 0:
change_str = f'-{diff_size}'
else:
change_str = '0B'
comment += f'| `{file_name}` | {current_size} | {base_size} | {change_str} | {percent:+.1f}% | {status_icon} |\n'
# Save comment to file
with open('pr_comment.md', 'w') as f:
f.write(comment)
print('PR comment generated')
"
- name: Post/Update PR Comment
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const comment = fs.readFileSync('pr_comment.md', 'utf8');
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existingComment = comments.find(comment =>
comment.user.type === 'Bot' &&
comment.body.includes('📦 Build Size Comparison')
);
if (existingComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: comment
});
console.log('Updated existing PR comment');
} else {
// Create new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: comment
});
console.log('Created new PR comment');
}
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-comparison
path: |
current-build.zip
base-build.zip
retention-days: 7