[CI] Add MessageList E2E tests #97
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: SDK size checks | |
on: | |
pull_request: | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
env: | |
METRICS_PROJECT: "stream-chat-android-metrics" | |
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 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, | |
}); | |
} |