adding size comparison #73
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Size Comparison | |
on: | |
push: | |
branches: ["main"] | |
paths-ignore: | |
- "**.md" | |
- "LICENSE" | |
pull_request: | |
branches: ["main"] | |
jobs: | |
windows: | |
name: windows-size-comparison | |
runs-on: windows-2019 | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build windows | |
$baseSize = (Get-ChildItem -Recurse "build\windows\x64\runner\Release\" | Measure-Object -Property Length -Sum).Sum / 1KB | |
echo "BASE_SIZE=$baseSize" | Out-File -FilePath $env:GITHUB_ENV -Append | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build windows | |
$coreSize = (Get-ChildItem -Recurse "build\windows\x64\runner\Release\" | Measure-Object -Property Length -Sum).Sum / 1KB | |
echo "CORE_SIZE=$coreSize" | Out-File -FilePath $env:GITHUB_ENV -Append | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build windows | |
$dartSize = (Get-ChildItem -Recurse "build\windows\x64\runner\Release\" | Measure-Object -Property Length -Sum).Sum / 1KB | |
echo "DART_SIZE=$dartSize" | Out-File -FilePath $env:GITHUB_ENV -Append | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
$report = @{ | |
'platform' = 'windows' | |
'base_size' = $env:BASE_SIZE | |
'opencv_core' = @{ | |
'total_size' = $env:CORE_SIZE | |
'package_size' = [int]$env:CORE_SIZE - [int]$env:BASE_SIZE | |
} | |
'opencv_dart' = @{ | |
'total_size' = $env:DART_SIZE | |
'package_size' = [int]$env:DART_SIZE - [int]$env:BASE_SIZE | |
} | |
} | |
$report | ConvertTo-Json | Out-File windows_size_report.json | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: windows-size-report | |
path: windows_size_report.json | |
android: | |
name: android-size-comparison | |
runs-on: ubuntu-latest | |
steps: | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-java@v4 | |
with: | |
distribution: "temurin" | |
java-version: "17" | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi | |
BASE_SIZE_ARM64=$(stat -c%s "build/app/outputs/apk/release/app-arm64-v8a-release.apk" || echo "0") | |
BASE_SIZE_ARMV7=$(stat -c%s "build/app/outputs/apk/release/app-armeabi-v7a-release.apk" || echo "0") | |
BASE_SIZE_X64=$(stat -c%s "build/app/outputs/apk/release/app-x86_64-release.apk" || echo "0") | |
echo "BASE_SIZE_ARM64=$BASE_SIZE_ARM64" >> $GITHUB_ENV | |
echo "BASE_SIZE_ARMV7=$BASE_SIZE_ARMV7" >> $GITHUB_ENV | |
echo "BASE_SIZE_X64=$BASE_SIZE_X64" >> $GITHUB_ENV | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi | |
CORE_SIZE_ARM64=$(stat -c%s "build/app/outputs/apk/release/app-arm64-v8a-release.apk" || echo "0") | |
CORE_SIZE_ARMV7=$(stat -c%s "build/app/outputs/apk/release/app-armeabi-v7a-release.apk" || echo "0") | |
CORE_SIZE_X64=$(stat -c%s "build/app/outputs/apk/release/app-x86_64-release.apk" || echo "0") | |
echo "CORE_SIZE_ARM64=$CORE_SIZE_ARM64" >> $GITHUB_ENV | |
echo "CORE_SIZE_ARMV7=$CORE_SIZE_ARMV7" >> $GITHUB_ENV | |
echo "CORE_SIZE_X64=$CORE_SIZE_X64" >> $GITHUB_ENV | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build apk --release --target-platform android-arm64,android-arm,android-x64 --split-per-abi | |
DART_SIZE_ARM64=$(stat -c%s "build/app/outputs/apk/release/app-arm64-v8a-release.apk" || echo "0") | |
DART_SIZE_ARMV7=$(stat -c%s "build/app/outputs/apk/release/app-armeabi-v7a-release.apk" || echo "0") | |
DART_SIZE_X64=$(stat -c%s "build/app/outputs/apk/release/app-x86_64-release.apk" || echo "0") | |
echo "DART_SIZE_ARM64=$DART_SIZE_ARM64" >> $GITHUB_ENV | |
echo "DART_SIZE_ARMV7=$DART_SIZE_ARMV7" >> $GITHUB_ENV | |
echo "DART_SIZE_X64=$DART_SIZE_X64" >> $GITHUB_ENV | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
cat > android_size_report.json << EOL | |
{ | |
"platform": "android", | |
"base_size": { | |
"arm64-v8a": ${BASE_SIZE_ARM64:-0}, | |
"armeabi-v7a": ${BASE_SIZE_ARMV7:-0}, | |
"x86_64": ${BASE_SIZE_X64:-0} | |
}, | |
"opencv_core": { | |
"arm64-v8a": { | |
"total_size": ${CORE_SIZE_ARM64:-0}, | |
"package_size": $(( ${CORE_SIZE_ARM64:-0} - ${BASE_SIZE_ARM64:-0} )) | |
}, | |
"armeabi-v7a": { | |
"total_size": ${CORE_SIZE_ARMV7:-0}, | |
"package_size": $(( ${CORE_SIZE_ARMV7:-0} - ${BASE_SIZE_ARMV7:-0} )) | |
}, | |
"x86_64": { | |
"total_size": ${CORE_SIZE_X64:-0}, | |
"package_size": $(( ${CORE_SIZE_X64:-0} - ${BASE_SIZE_X64:-0} )) | |
} | |
}, | |
"opencv_dart": { | |
"arm64-v8a": { | |
"total_size": ${DART_SIZE_ARM64:-0}, | |
"package_size": $(( ${DART_SIZE_ARM64:-0} - ${BASE_SIZE_ARM64:-0} )) | |
}, | |
"armeabi-v7a": { | |
"total_size": ${DART_SIZE_ARMV7:-0}, | |
"package_size": $(( ${DART_SIZE_ARMV7:-0} - ${BASE_SIZE_ARMV7:-0} )) | |
}, | |
"x86_64": { | |
"total_size": ${DART_SIZE_X64:-0}, | |
"package_size": $(( ${DART_SIZE_X64:-0} - ${BASE_SIZE_X64:-0} )) | |
} | |
} | |
} | |
EOL | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: android-size-report | |
path: android_size_report.json | |
linux: | |
name: linux-size-comparison | |
runs-on: ubuntu-latest | |
steps: | |
- name: Setup dependencies | |
run: | | |
sudo apt-get update -y | |
sudo apt-get install -y curl git unzip xz-utils zip libglu1-mesa | |
sudo apt-get install clang cmake git \ | |
ninja-build pkg-config \ | |
libgtk-3-dev liblzma-dev \ | |
libstdc++-12-dev | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- uses: actions/checkout@v4 | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build linux | |
BASE_SIZE=$(du -sk "build/linux/x64/release/bundle" | cut -f1) | |
echo "BASE_SIZE=$BASE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build linux | |
CORE_SIZE=$(du -sk "build/linux/x64/release/bundle" | cut -f1) | |
echo "CORE_SIZE=$CORE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build linux | |
DART_SIZE=$(du -sk "build/linux/x64/release/bundle" | cut -f1) | |
echo "DART_SIZE=$DART_SIZE" >> $GITHUB_ENV | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
base_size=${BASE_SIZE:-0} | |
core_size=${CORE_SIZE:-0} | |
dart_size=${DART_SIZE:-0} | |
core_diff=$((core_size - base_size)) | |
dart_diff=$((dart_size - base_size)) | |
cat > linux_size_report.json << EOL | |
{ | |
"platform": "linux", | |
"base_size": $base_size, | |
"opencv_core": { | |
"total_size": $core_size, | |
"package_size": $core_diff | |
}, | |
"opencv_dart": { | |
"total_size": $dart_size, | |
"package_size": $dart_diff | |
} | |
} | |
EOL | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: linux-size-report | |
path: linux_size_report.json | |
ios: | |
name: ios-size-comparison | |
runs-on: macos-14 | |
steps: | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- uses: actions/checkout@v4 | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build ios --release --no-codesign | |
BASE_SIZE=$(du -sk "build/ios/iphoneos/Runner.app" | cut -f1) | |
echo "BASE_SIZE=$BASE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build ios --release --no-codesign | |
CORE_SIZE=$(du -sk "build/ios/iphoneos/Runner.app" | cut -f1) | |
echo "CORE_SIZE=$CORE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build ios --release --no-codesign | |
DART_SIZE=$(du -sk "build/ios/iphoneos/Runner.app" | cut -f1) | |
echo "DART_SIZE=$DART_SIZE" >> $GITHUB_ENV | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
base_size=${BASE_SIZE:-0} | |
core_size=${CORE_SIZE:-0} | |
dart_size=${DART_SIZE:-0} | |
core_diff=$((core_size - base_size)) | |
dart_diff=$((dart_size - base_size)) | |
cat > ios_size_report.json << EOL | |
{ | |
"platform": "ios", | |
"base_size": $base_size, | |
"opencv_core": { | |
"total_size": $core_size, | |
"package_size": $core_diff | |
}, | |
"opencv_dart": { | |
"total_size": $dart_size, | |
"package_size": $dart_diff | |
} | |
} | |
EOL | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ios-size-report | |
path: ios_size_report.json | |
macos: | |
name: macos-size-comparison | |
runs-on: macos-13 | |
steps: | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- uses: actions/checkout@v4 | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build macos | |
BASE_SIZE=$(du -sk "build/macos/Build/Products/Release/base_project.app" | cut -f1) | |
echo "BASE_SIZE=$BASE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build macos | |
CORE_SIZE=$(du -sk "build/macos/Build/Products/Release/opencv_core_example.app" | cut -f1) | |
echo "CORE_SIZE=$CORE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build macos | |
DART_SIZE=$(du -sk "build/macos/Build/Products/Release/opencv_dart_example.app" | cut -f1) | |
echo "DART_SIZE=$DART_SIZE" >> $GITHUB_ENV | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
base_size=${BASE_SIZE:-0} | |
core_size=${CORE_SIZE:-0} | |
dart_size=${DART_SIZE:-0} | |
core_diff=$((core_size - base_size)) | |
dart_diff=$((dart_size - base_size)) | |
cat > macos_size_report.json << EOL | |
{ | |
"platform": "macos", | |
"base_size": $base_size, | |
"opencv_core": { | |
"total_size": $core_size, | |
"package_size": $core_diff | |
}, | |
"opencv_dart": { | |
"total_size": $dart_size, | |
"package_size": $dart_diff | |
} | |
} | |
EOL | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: macos-size-report | |
path: macos_size_report.json | |
macos-arm: | |
name: macos-arm-size-comparison | |
runs-on: macos-14 | |
steps: | |
- uses: subosito/flutter-action@v2 | |
with: | |
channel: "stable" | |
- uses: actions/checkout@v4 | |
# Create and build base project | |
- name: Create base project | |
run: | | |
mkdir size_comparison | |
cd size_comparison | |
flutter create base_project | |
cd base_project | |
flutter build macos | |
BASE_SIZE=$(du -sk "build/macos/Build/Products/Release/base_project.app" | cut -f1) | |
echo "BASE_SIZE=$BASE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_core | |
- name: opencv_core size | |
run: | | |
cd packages/opencv_core/example | |
flutter build macos | |
CORE_SIZE=$(du -sk "build/macos/Build/Products/Release/opencv_core_example.app" | cut -f1) | |
echo "CORE_SIZE=$CORE_SIZE" >> $GITHUB_ENV | |
# Build and measure opencv_dart | |
- name: opencv_dart size | |
run: | | |
cd packages/opencv_dart/example | |
flutter build macos | |
DART_SIZE=$(du -sk "build/macos/Build/Products/Release/opencv_dart_example.app" | cut -f1) | |
echo "DART_SIZE=$DART_SIZE" >> $GITHUB_ENV | |
# Generate size comparison JSON | |
- name: Generate size report | |
run: | | |
base_size=${BASE_SIZE:-0} | |
core_size=${CORE_SIZE:-0} | |
dart_size=${DART_SIZE:-0} | |
core_diff=$((core_size - base_size)) | |
dart_diff=$((dart_size - base_size)) | |
cat > macos_arm_size_report.json << EOL | |
{ | |
"platform": "macos-arm", | |
"base_size": $base_size, | |
"opencv_core": { | |
"total_size": $core_size, | |
"package_size": $core_diff | |
}, | |
"opencv_dart": { | |
"total_size": $dart_size, | |
"package_size": $dart_diff | |
} | |
} | |
EOL | |
- name: Upload size report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: macos-arm-size-report | |
path: macos_arm_size_report.json | |
combine-reports: | |
needs: [windows, android, ios, linux, macos, macos-arm] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: size-reports | |
- name: Generate Combined JSON Report | |
run: | | |
cat << 'EOF' > generate_combined_json.py | |
import json | |
import os | |
import glob | |
from datetime import datetime | |
def convert_to_mb(value): | |
try: | |
return round(float(value) / 1024, 2) | |
except (ValueError, TypeError): | |
return value | |
def process_dict(data): | |
if isinstance(data, dict): | |
return {k: process_dict(v) for k, v in data.items()} | |
elif isinstance(data, list): | |
return [process_dict(item) for item in data] | |
else: | |
return convert_to_mb(data) | |
def consolidate_data(reports): | |
combined = {"timestamp": datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")} | |
packages_data = {} | |
for report_path in reports: | |
platform = os.path.basename(os.path.dirname(report_path)).replace('-size-report', '') | |
with open(report_path) as f: | |
data = json.load(f) | |
processed_data = process_dict(data) | |
for package, sizes in processed_data.items(): | |
if package not in packages_data: | |
packages_data[package] = {} | |
packages_data[package][platform] = sizes | |
combined["packages"] = packages_data | |
return combined | |
reports = glob.glob('size-reports/*/*.json') | |
combined_data = consolidate_data(reports) | |
with open("combined_size_report.json", "w") as f: | |
json.dump(combined_data, f, indent=2) | |
EOF | |
python3 generate_combined_json.py | |
- name: Display Combined JSON Report | |
run: | | |
echo "Combined JSON Report:" | |
cat combined_size_report.json | |
- name: Upload Combined JSON Report | |
uses: actions/upload-artifact@v4 | |
with: | |
name: combined-size-report | |
path: combined_size_report.json | |
- name: Generate SVGs for Each Package | |
run: | | |
cat << 'EOF' > generate_svgs.py | |
import json | |
from pathlib import Path | |
def generate_svg_for_package(package_name, data): | |
platforms = list(data.keys()) | |
max_archs = 0 | |
for platform_data in data.values(): | |
if isinstance(platform_data, dict): | |
max_archs = max(max_archs, len(platform_data)) | |
svg_height = len(platforms) * (40 + max_archs * 20) + 100 | |
svg_width = 800 | |
svg_content = f''' | |
<svg xmlns="http://www.w3.org/2000/svg" width="{svg_width}" height="{svg_height}"> | |
<style> | |
.title {{ font-size: 24px; font-weight: bold; fill: #333; text-anchor: middle; }} | |
.header {{ font-size: 16px; font-weight: bold; fill: #444; }} | |
.platform {{ font-size: 14px; font-weight: bold; fill: #222; }} | |
.arch-header {{ font-size: 12px; font-weight: bold; fill: #666; }} | |
.row {{ font-size: 12px; fill: #555; }} | |
.table {{ border-collapse: collapse; }} | |
.table th, .table td {{ border: 1px solid #ddd; padding: 8px; }} | |
</style> | |
<text x="{svg_width/2}" y="40" class="title">Consolidated Size Report for {package_name}</text> | |
<table class="table" x="10" y="80"> | |
<tr> | |
<th>Platform</th> | |
<th>Architecture</th> | |
<th>Total Size (MB)</th> | |
<th>Package Size (MB)</th> | |
</tr> | |
''' | |
for platform, sizes in data.items(): | |
if isinstance(sizes, dict): | |
for arch, arch_sizes in sizes.items(): | |
total_size = arch_sizes.get("total_size", "N/A") if isinstance(arch_sizes, dict) else arch_sizes | |
package_size = arch_sizes.get("package_size", "N/A") if isinstance(arch_sizes, dict) else "N/A" | |
svg_content += f''' | |
<tr> | |
<td>{platform}</td> | |
<td>{arch}</td> | |
<td>{total_size}</td> | |
<td>{package_size}</td> | |
</tr>''' | |
else: | |
total_size = sizes if isinstance(sizes, str) else sizes.get("total_size", "N/A") | |
package_size = "N/A" if isinstance(sizes, str) else sizes.get("package_size", "N/A") | |
svg_content += f''' | |
<tr> | |
<td>{platform}</td> | |
<td>N/A</td> | |
<td>{total_size}</td> | |
<td>{package_size}</td> | |
</tr>''' | |
svg_content += '</table></svg>' | |
svg_path = Path("svg-reports") / f"{package_name}_consolidated_size_report.svg" | |
svg_path.parent.mkdir(exist_ok=True) | |
with svg_path.open("w") as f: | |
f.write(svg_content) | |
with open("combined_size_report.json") as f: | |
combined_data = json.load(f) | |
for package, data in combined_data["packages"].items(): | |
generate_svg_for_package(package, data) | |
EOF | |
python3 generate_svgs.py | |
- name: Upload SVG reports | |
uses: actions/upload-artifact@v4 | |
with: | |
name: svg-size-reports | |
path: svg-reports |