adding size comparison #72
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): | |
svg_height = len(data) * 60 + 100 | |
svg_content = f''' | |
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="{svg_height}"> | |
<style> | |
.title {{ font-size: 18px; font-weight: bold; fill: #333; }} | |
.header {{ font-size: 14px; font-weight: bold; fill: #444; }} | |
.arch-header {{ font-size: 12px; font-weight: bold; fill: #666; }} | |
.row {{ font-size: 12px; fill: #555; }} | |
.platform {{ font-size: 14px; font-weight: bold; fill: #222; }} | |
</style> | |
<text x="10" y="30" class="title">Consolidated Size Report for {package_name}</text> | |
<text x="10" y="60" class="header">Platform</text> | |
<text x="150" y="60" class="header">Architecture</text> | |
<text x="300" y="60" class="header">Total Size (MB)</text> | |
<text x="450" y="60" class="header">Package Size (MB)</text> | |
''' | |
y_pos = 90 | |
for platform, sizes in data.items(): | |
if isinstance(sizes, dict): # Handle platforms with multiple architectures | |
svg_content += f'<text x="10" y="{y_pos}" class="platform">{platform}</text>' | |
y_pos += 20 | |
for arch, arch_sizes in sizes.items(): | |
total_size = arch_sizes["total_size"] if isinstance(arch_sizes, dict) and "total_size" in arch_sizes else str(arch_sizes) | |
package_size = arch_sizes["package_size"] if isinstance(arch_sizes, dict) and "package_size" in arch_sizes else "N/A" | |
svg_content += f''' | |
<text x="150" y="{y_pos}" class="arch-header">{arch}</text> | |
<text x="300" y="{y_pos}" class="row">{total_size}</text> | |
<text x="450" y="{y_pos}" class="row">{package_size}</text> | |
''' | |
y_pos += 20 | |
else: # Handle single architecture platforms | |
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''' | |
<text x="10" y="{y_pos}" class="platform">{platform}</text> | |
<text x="300" y="{y_pos}" class="row">{total_size}</text> | |
<text x="450" y="{y_pos}" class="row">{package_size}</text> | |
''' | |
y_pos += 20 | |
svg_content += '</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 |