Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND-116: SDK size reporting #1266

Merged
merged 10 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
workflow_dispatch:

concurrency:
group: ${{ github.ref }}
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
Expand Down
125 changes: 125 additions & 0 deletions .github/workflows/sdk-size-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: SDK size checks

on:
pull_request:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
METRICS_PROJECT: "stream-video-android-metrics"
MODULES: "stream-video-android-core stream-video-android-ui-xml stream-video-android-ui-compose"
METRICS_FILE: "metrics/size.json"
MAX_TOLERANCE: 500
FINE_TOLERANCE: 250

jobs:
compare-sdk-sizes:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: ./.github/actions/setup-java
- uses: ./.github/actions/gradle-cache
with:
key-prefix: gradle-build

- name: Assemble release for metrics
run: ./gradlew :metrics:$METRICS_PROJECT:assembleRelease

- name: Get current SDK sizes
run: |
# Reads current SDK sizes from the metrics file
# and define to a variable using a compact JSON format
# so it can be exported for the next job step
CURRENT_SDK_SIZES=$(jq -c .release $METRICS_FILE)
echo "CURRENT_SDK_SIZES=$CURRENT_SDK_SIZES" >> $GITHUB_ENV

- name: Calculate PR branch SDK sizes
run: |
echo '{}' > pr_sdk_sizes.json

# Calculate sizes from the .apk files and save them into a temporary JSON file
# so it can be exported for the next job step
for module in $MODULES; do
baselineFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-baseline/release/$METRICS_PROJECT-$module-baseline-release.apk"
streamFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-stream/release/$METRICS_PROJECT-$module-stream-release.apk"

baselineSize=$(du -k "$baselineFile" | awk '{print $1}')
streamSize=$(du -k "$streamFile" | awk '{print $1}')
size=$((streamSize - baselineSize))

jq -c --arg sdk "$module" --arg size "$size" '. + {($sdk): ($size | tonumber)}' pr_sdk_sizes.json > temp.json && mv temp.json pr_sdk_sizes.json
done

echo "PR_SDK_SIZES=$(cat pr_sdk_sizes.json)" >> $GITHUB_ENV

- name: Post comment on PR
uses: actions/github-script@v6
with:
script: |
const maxTolerance = process.env.MAX_TOLERANCE
const fineTolerance = process.env.FINE_TOLERANCE
const currentSdkSizes = process.env.CURRENT_SDK_SIZES ? JSON.parse(process.env.CURRENT_SDK_SIZES) : {};
const prSdkSizes = JSON.parse(process.env.PR_SDK_SIZES);
const commentHeader = '## SDK Size Comparison 📏';

// Prepare the comparison table

let commentBody = `
${commentHeader}

| SDK | Before | After | Difference | Status |
|-|-|-|-|-|
`;

Object.keys(prSdkSizes).forEach(sdk => {
const currentSize = currentSdkSizes[sdk] || 0;
const prSize = prSdkSizes[sdk];
const diff = prSize - currentSize;
const currentSizeInMb = (currentSize / 1024).toFixed(2);
const prSizeInMb = (prSize / 1024).toFixed(2);
const diffInMb = (diff / 1024).toFixed(2);

let status = "🟢";
if (diff < 0) {
status = "🚀";
} else if (diff >= maxTolerance) {
status = "🔴";
} else if (diff >= fineTolerance) {
status = "🟡";
}

commentBody += `| ${sdk} | ${currentSizeInMb} MB | ${prSizeInMb} MB | ${diffInMb} MB | ${status} |\n`;
});

// Post or update the PR comment

// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
});

const comment = comments.find(c => c.body.includes(commentHeader));

if (comment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: comment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: commentBody,
});
}
95 changes: 95 additions & 0 deletions .github/workflows/sdk-size-updates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: SDK size updates

on:
push:
branches:
- develop

workflow_dispatch:

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: true

env:
METRICS_PROJECT: "stream-video-android-metrics"
MODULES: "stream-video-android-core stream-video-android-ui-xml stream-video-android-ui-compose"
VARIANTS: "debug release"
METRICS_FILE: "metrics/size.json"
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}

jobs:
update-sdk-sizes:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
persist-credentials: false
- uses: ./.github/actions/setup-java
- uses: ./.github/actions/gradle-cache
with:
key-prefix: gradle-build

- name: Assemble release and debug for metrics
run: ./gradlew :metrics:$METRICS_PROJECT:assemble

- name: Update size metrics
run: |
# Create temporary JSON file
echo '{}' > metrics.json

# Calculate sizes
for module in $MODULES; do
for variant in $VARIANTS; do
baselineFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-baseline/$variant/$METRICS_PROJECT-$module-baseline-$variant.apk"
streamFile="metrics/$METRICS_PROJECT/build/outputs/apk/$module-stream/$variant/$METRICS_PROJECT-$module-stream-$variant.apk"

# Ensure files exist
if [[ -f "$baselineFile" && -f "$streamFile" ]]; then
baselineSize=$(du -k "$baselineFile" | awk '{print $1}')
streamSize=$(du -k "$streamFile" | awk '{print $1}')
size=$((streamSize - baselineSize))
else
echo "Warning: $baselineFile or $streamFile not found. Setting size to 0."
size=0
fi

# Update JSON
jq --arg module "$module" --arg variant "$variant" --argjson size "$size" \
".\"$variant\".\"$module\" = $size" metrics.json > temp.json && mv temp.json metrics.json
done
done

# Validate Generated JSON
jq . metrics.json

# Move temporary JSON file to the final file
mv metrics.json $METRICS_FILE

- name: Update size badges
run: |
for module in $MODULES; do
size=$(jq --arg module "$module" ".release.\"$module\"" $METRICS_FILE)
sizeInMb=$(echo "scale=2; $size / 1024" | bc)
badgeUrl="https://img.shields.io/badge/${module//-/--}-$sizeInMb%20MB-lightgreen"
sed -i "s|!\[$module\](.*)|![$module](${badgeUrl})|" README.md
done

- name: Commit changes
run: |
git fetch origin $BRANCH_NAME
git checkout $BRANCH_NAME

git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"

git add $METRICS_FILE README.md
git commit -m "[skip ci] Update SDK sizes" || echo "No changes to commit"

- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.STREAM_PUBLIC_BOT_TOKEN }}
branch: ${{ env.BRANCH_NAME }}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
<a href="https://search.maven.org/search?q=stream-video-android"><img src="https://img.shields.io/maven-central/v/io.getstream/stream-video-android-core.svg?label=Maven%20Central" /></a>
</p>

<div align="center">

![stream-video-android-core](https://img.shields.io/badge/stream--video--android--core-15.89%20MB-lightgreen)
![stream-video-android-ui-xml](https://img.shields.io/badge/stream--video--android--ui--xml-21.70%20MB-lightgreen)
![stream-video-android-ui-compose](https://img.shields.io/badge/stream--video--android--ui--compose-21.68%20MB-lightgreen)

</div>

This is the official Android SDK for [Stream Video](https://getstream.io/video?utm_source=Github&utm_medium=Github_Repo_Content_Ad&utm_content=Developer&utm_campaign=Github_Android_Video_SDK&utm_term=DevRelOss), a service for building video calls, audio rooms, and live-streaming applications. This library includes both a low-level video SDK and a set of reusable UI components.
Most users start with the Compose UI components and fall back to the lower-level API when they want to customize things.

Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ subprojects {
}

// TODO - re-enable the core module once coordinator is stable
if (name.startsWith("stream-video-android") && !name.startsWith("stream-video-android-core")) {
if (name.startsWith("stream-video-android")
&& !name.startsWith("stream-video-android-core")
&& !name.contains("metrics")) {
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.freeCompilerArgs += listOf(
"-Xexplicit-api=strict"
Expand Down
12 changes: 12 additions & 0 deletions metrics/size.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"debug": {
"stream-video-android-core": 0,
"stream-video-android-ui-xml": 0,
"stream-video-android-ui-compose": 0
},
"release": {
"stream-video-android-core": 0,
"stream-video-android-ui-xml": 0,
"stream-video-android-ui-compose": 0
}
}
79 changes: 79 additions & 0 deletions metrics/stream-video-android-metrics/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import io.getstream.video.android.Configuration

plugins {
id("io.getstream.android.application")
}

android {
namespace = "io.getstream.video.android.metrics"
compileSdk = Configuration.compileSdk

defaultConfig {
minSdk = Configuration.minSdk
ndk {
abiFilters += "armeabi-v7a"
}
}

buildTypes {
release {
signingConfig = signingConfigs.findByName("debug")
}
}

flavorDimensions += "sdk"

productFlavors {
create("stream-video-android-core-baseline") {
dimension = "sdk"
}
create("stream-video-android-core-stream") {
dimension = "sdk"
}
create("stream-video-android-ui-xml-baseline") {
dimension = "sdk"
}
create("stream-video-android-ui-xml-stream") {
dimension = "sdk"
}
create("stream-video-android-ui-compose-baseline") {
dimension = "sdk"
}
create("stream-video-android-ui-compose-stream") {
dimension = "sdk"
}
}
}

afterEvaluate {
android.productFlavors.forEach { flavor ->
val flavorName = flavor.name
// For compose flavors, we apply the compose plugin,
// set up build features and add common compose dependencies.
if (flavorName.contains("compose")) {
val composePlugin = libs.plugins.compose.compiler.get()
// plugins.apply(composePlugin.pluginId) // Enable with Kotlin 2.0+
android.buildFeatures.compose = true
val configurationName = "${flavorName}Implementation"
dependencies.add(configurationName, libs.androidx.compose.ui)
dependencies.add(configurationName, libs.androidx.compose.ui.tooling)
dependencies.add(configurationName, libs.androidx.compose.foundation)
dependencies.add(configurationName, libs.androidx.activity.compose)
dependencies.add(configurationName, libs.androidx.lifecycle.runtime.compose)
dependencies.add(configurationName, libs.androidx.lifecycle.viewmodel.compose)
}
}
}

dependencies {
implementation(libs.kotlinx.coroutines.core)
implementation(libs.androidx.appcompat)

"stream-video-android-core-streamImplementation"(project(":stream-video-android-core"))

"stream-video-android-ui-xml-baselineImplementation"(project(":stream-video-android-core"))
"stream-video-android-ui-xml-streamImplementation"(project(":stream-video-android-ui-xml"))

"stream-video-android-ui-compose-baselineImplementation"(project(":stream-video-android-core"))
"stream-video-android-ui-compose-streamImplementation"(project(":stream-video-android-ui-compose"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.

Licensed under the Stream License;
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

https://github.com/GetStream/stream-video-android/blob/main/LICENSE

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
>

<application>
<activity
android:name=".MainActivity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading
Loading