-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
917 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
name: SDK size checks | ||
|
||
on: | ||
pull_request: | ||
|
||
env: | ||
MODULES: "stream-chat-android-client stream-chat-android-offline stream-chat-android-ui-components stream-chat-android-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 SDKs | ||
run: | | ||
for module in $MODULES; do | ||
modules+=" :metrics:$module-metrics-baseline:assemble :metrics:$module-metrics-stream:assemble" | ||
done | ||
./gradlew $modules | ||
- 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 .debug $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/$module-metrics-baseline/build/outputs/apk/debug/$module-metrics-baseline-debug.apk" | ||
streamFile="metrics/$module-metrics-stream/build/outputs/apk/debug/$module-metrics-stream-debug.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`; | ||
}); | ||
commentBody += `\* Based on debug builds\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, | ||
}); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
name: SDK size updates | ||
|
||
on: | ||
# push: | ||
# branches: | ||
# - develop | ||
pull_request: | ||
|
||
workflow_dispatch: | ||
|
||
#concurrency: | ||
# group: ${{ github.ref }} | ||
# cancel-in-progress: true | ||
|
||
env: | ||
MODULES: "stream-chat-android-client stream-chat-android-offline stream-chat-android-ui-components stream-chat-android-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 | ||
- uses: ./.github/actions/setup-java | ||
- uses: ./.github/actions/gradle-cache | ||
with: | ||
key-prefix: gradle-build | ||
|
||
- name: Assemble SDKs | ||
run: | | ||
for module in $MODULES; do | ||
modules+=" :metrics:$module-metrics-baseline:assemble :metrics:$module-metrics-stream:assemble" | ||
done | ||
./gradlew $modules | ||
- 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/$module-metrics-baseline/build/outputs/apk/$variant/$module-metrics-baseline-$variant.apk" | ||
streamFile="metrics/$module-metrics-stream/build/outputs/apk/$variant/$module-metrics-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 and Push JSON | ||
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" | ||
# Add and commit updated metrics file | ||
git add $METRICS_FILE | ||
git commit -m "Update SDK size metrics" || echo "No metrics changes to commit" | ||
# Add and commit updated README file | ||
git add README.md | ||
git commit -m "Update SDK size badges" || echo "No README changes to commit" | ||
git push origin HEAD:$BRANCH_NAME |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"debug": { | ||
"stream-chat-android-client": 15036, | ||
"stream-chat-android-offline": 15336, | ||
"stream-chat-android-ui-components": 21028, | ||
"stream-chat-android-compose": 23484 | ||
}, | ||
"release": { | ||
"stream-chat-android-client": 3092, | ||
"stream-chat-android-offline": 3300, | ||
"stream-chat-android-ui-components": 8072, | ||
"stream-chat-android-compose": 9940 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
metrics/stream-chat-android-client-metrics-baseline/build.gradle.kts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import io.getstream.chat.android.Dependencies | ||
|
||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
apply(from = "$rootDir/scripts/android.gradle") | ||
|
||
android { | ||
namespace = "io.getstream.chat.android.client.metrics.baseline" | ||
buildTypes { | ||
release { | ||
signingConfig = signingConfigs.findByName("debug") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
detektPlugins(Dependencies.detektFormatting) | ||
|
||
implementation(Dependencies.coroutinesCore) | ||
implementation(Dependencies.androidxAppCompat) | ||
} |
33 changes: 33 additions & 0 deletions
33
metrics/stream-chat-android-client-metrics-baseline/src/main/AndroidManifest.xml
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
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-chat-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> |
21 changes: 21 additions & 0 deletions
21
...aseline/src/main/kotlin/io/getstream/chat/android/client/metrics/baseline/MainActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* 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-chat-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. | ||
*/ | ||
|
||
package io.getstream.chat.android.client.metrics.baseline | ||
|
||
import androidx.activity.ComponentActivity | ||
|
||
class MainActivity : ComponentActivity() |
26 changes: 26 additions & 0 deletions
26
metrics/stream-chat-android-client-metrics-stream/build.gradle.kts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import io.getstream.chat.android.Dependencies | ||
|
||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
apply(from = "$rootDir/scripts/android.gradle") | ||
|
||
android { | ||
namespace = "io.getstream.chat.android.client.metrics.stream" | ||
buildTypes { | ||
release { | ||
signingConfig = signingConfigs.findByName("debug") | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
detektPlugins(Dependencies.detektFormatting) | ||
|
||
implementation(Dependencies.coroutinesCore) | ||
implementation(Dependencies.androidxAppCompat) | ||
|
||
implementation(project(":stream-chat-android-client")) | ||
} |
Oops, something went wrong.