name: APK Size Difference CI on: workflow_call: jobs: generate-apk-diff: runs-on: [ default ] steps: - name: Checkout Repository uses: actions/checkout@v4 - name: Clear Cache run: sudo rm -rf ~/Python - name: Download Artifact uses: actions/download-artifact@v4 with: name: app-qa-debug path: current - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.9.7' - name: Install dependencies run: pip install -r .github/actions/s3_file_transfer/dependencies.txt - name: Download File run: python .github/actions/s3_file_transfer/script.py download ${{ secrets.AWS_ACCESS_KEY_GITHUB_CACHE }} ${{ secrets.AWS_SECRET_KEY_GITHUB_CACHE }} previous/apk_from_bundle/qaDebug/app-qa-debug-universal.apk - name: Compare APK Size Difference id: apk-diff run: | previous_apk_path="previous/apk_from_bundle/qaDebug/app-qa-debug-universal.apk" current_apk_path="current/apk_from_bundle/qaDebug/app-qa-debug-universal.apk" previous_apk_size=$(stat -c %s $previous_apk_path) current_apk_size=$(stat -c %s $current_apk_path) size_diff=$((current_apk_size - previous_apk_size)) echo "size_diff=$size_diff" >> $GITHUB_OUTPUT echo "The previous value is $previous_apk_size" echo "The latest value is $current_apk_size" - name: Check Size Difference id: size-diff-check run: | size_diff=${{ steps.apk-diff.outputs.size_diff }} if [[ $size_diff -gt 204800 ]]; then echo "job_status=failure" >> $GITHUB_OUTPUT elif [[ $size_diff -gt 102400 ]]; then echo "job_status=warning" >> $GITHUB_OUTPUT else echo "job_status=success" >> $GITHUB_OUTPUT fi - name: Write PR Comment uses: actions/github-script@v7 with: github-token: ${{ secrets.GH_ANDROID_BOT_PAT }} script: | const sizeDiff = ${{ steps.apk-diff.outputs.size_diff }}; const apkSizeDifferenceInKilobytes = Math.round(sizeDiff / 1024); const codeOwners = ['@navi-android/leads', '@navi-android/codeowners']; const codeOwnerTags = codeOwners.join(' '); const additionalInfo = ` APK size can increase due to various factors. Some common reasons include: - Adding external libraries: Before including any external libraries, it's advisable to seek signoff from ${codeOwnerTags}. - Using high-resolution vectors: For vector XMLs larger than 48dp, consider using WebP format to optimize file size. - Including Lottie JSON files: When adding Lottie animations, it's recommended to prioritize remote Lottie files over local ones. - Adding assets/resources: The addition of assets and resources can contribute to APK size growth. `; let comment; if (apkSizeDifferenceInKilobytes > 200) { comment = `### :exclamation: APK Size Exceeded Limit The APK size has increased by ${apkSizeDifferenceInKilobytes}KB compared to the previous version. Please provide the justification for this increase. ${additionalInfo}`; } else if (apkSizeDifferenceInKilobytes > 100) { comment = `### :warning: APK Size Warning The APK size has increased by ${apkSizeDifferenceInKilobytes}KB compared to the previous version. Please provide the justification for this increase. ${additionalInfo}`; } else { comment = `### :white_check_mark: APK Size Within Limit The APK size issue has been resolved, and the size is within acceptable limits.`; } const comments = await github.rest.issues.listComments({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, }); const existingComment = comments.data.find(c => c.body.includes('APK Size')); if (existingComment) { github.rest.issues.updateComment({ comment_id: existingComment.id, issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: comment }); } else if (apkSizeDifferenceInKilobytes > 100) { github.rest.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, body: comment }); } - name: Cleanup run: rm -rf *.tmp - name: Fail Job if Size Difference Exceeds 200 KB if: ${{ steps.size-diff-check.outputs.job_status == 'failure' }} run: exit 1