-
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
2 changed files
with
130 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,116 @@ | ||
name: SDK size checks | ||
|
||
on: | ||
pull_request: | ||
|
||
env: | ||
SDKS: "stream-chat-android-client stream-chat-android-offline stream-chat-android-ui-components stream-chat-android-compose" | ||
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: Get develop SDK sizes | ||
run: | | ||
# Reads the develop SDK sizes from JSON file | ||
# and define to a variable using a compact JSON format | ||
# so it can be exported for the next job step | ||
DEVELOP_SDK_SIZES=$(jq -c .debug stream-chat-android.json) | ||
echo "DEVELOP_SDK_SIZES=$DEVELOP_SDK_SIZES" >> $GITHUB_ENV | ||
- name: Assemble SDKs | ||
run: | | ||
for sdk in $SDKS; do | ||
modules+=" :$sdk:assembleDebug" | ||
done | ||
./gradlew $modules | ||
- name: Calculate PR branch SDK sizes | ||
run: | | ||
echo '{}' > pr_sdk_sizes.json | ||
# Calculate sizes from the .aar files and save them into a temporary JSON file | ||
# so it can be exported for the next job step | ||
for sdk in $SDKS; do | ||
size=$(du -k $sdk/build/outputs/aar/*.aar | awk '{print $1}') | ||
jq -c --arg sdk "$sdk" --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 developSdkSizes = JSON.parse(process.env.DEVELOP_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 developSize = developSdkSizes[sdk] || 0; | ||
const prSize = prSdkSizes[sdk]; | ||
const diff = prSize - developSize; | ||
let status; | ||
if (diff < 0) { | ||
status = "🚀"; | ||
} else if (diff >= maxTolerance) { | ||
status = "🔴"; | ||
} else if (diff >= fineTolerance) { | ||
status = "🟡"; | ||
} else { | ||
status = "🟢"; | ||
} | ||
commentBody += `| ${sdk} | ${developSize} KB | ${prSize} KB | ${diff} KB | ${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, | ||
}); | ||
} |
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": 2400, | ||
"stream-chat-android-offline": 740, | ||
"stream-chat-android-ui-components": 2000, | ||
"stream-chat-android-compose": 5000 | ||
}, | ||
"release": { | ||
"stream-chat-android-client": 2400, | ||
"stream-chat-android-offline": 740, | ||
"stream-chat-android-ui-components": 2000, | ||
"stream-chat-android-compose": 5000 | ||
} | ||
} |