Skip to content

Instantly share code, notes, and snippets.

@incognitojam
Last active January 31, 2025 21:52
Show Gist options
  • Save incognitojam/743d516fd113de1758ea90fc0e6a4ba5 to your computer and use it in GitHub Desktop.
Save incognitojam/743d516fd113de1758ea90fc0e6a4ba5 to your computer and use it in GitHub Desktop.
Build the app and check the bundle size (gzip compressed) for every commit in a repo, writing the results to a CSV file
import subprocess
import csv
import shutil
from pathlib import Path
from datetime import datetime
from tqdm import tqdm
def run_cmd(cmd):
try:
return subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError:
return None
commits = run_cmd('git log --format="%H,%ct" master')
if not commits:
exit(1)
commit_list = commits.stdout.strip().split('\n')
with open('bundle_sizes.csv', 'wt', newline='', buffering=1) as f:
writer = csv.writer(f)
writer.writerow(['commit', 'date', 'size_kib'])
for line in tqdm(commit_list, desc="Processing commits"):
commit_hash, timestamp = line.strip('"').split(',')
if not run_cmd(f'git checkout {commit_hash}'):
continue
if not run_cmd('bun install --frozen-lockfile'):
continue
if Path('dist').exists():
shutil.rmtree('dist')
if not run_cmd('bun run build'):
continue
size = run_cmd('find dist -type f ! -name "*.map" -exec sh -c \'gzip -9c "{}" | wc -c\' \\; | awk \'{total += $1} END {print int(total/1024)}\'')
if not size:
continue
date = datetime.fromtimestamp(int(timestamp)).isoformat()
writer.writerow([commit_hash, date, size.stdout.strip()])
run_cmd('git checkout master')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment