Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
108 lines
4.6 KiB
YAML
108 lines
4.6 KiB
YAML
name: APK Diff CI
|
|
on:
|
|
workflow_call:
|
|
secrets:
|
|
AWS_ACCESS_KEY_GITHUB_CACHE:
|
|
description: Access Key
|
|
required: true
|
|
AWS_SECRET_KEY_GITHUB_CACHE:
|
|
description: Secret Key
|
|
required: true
|
|
jobs:
|
|
generate-apk-diff:
|
|
runs-on: self-hosted
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
- name: Clear Cache
|
|
run: |
|
|
sudo rm -rf ~/Python
|
|
|
|
- name: Download Artifact
|
|
id: download
|
|
uses: actions/download-artifact@v3
|
|
with:
|
|
name: app-qa-debug
|
|
- name: Echo Download Path
|
|
run: echo ${{steps.download.outputs.download-path}}
|
|
- name: List Files
|
|
run: |
|
|
ls -R ${{steps.download.outputs.download-path}}
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v2
|
|
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 }} app/build/outputs/apk/dev/debug/latest_build.apk
|
|
- name: Compare APK Size Diff
|
|
id: apk-diff
|
|
run: |
|
|
previous_apk_path="app/build/outputs/apk/dev/debug/latest_build.apk"
|
|
current_apk_path="${{steps.download.outputs.download-path}}/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 "::set-output name=size_diff::$size_diff"
|
|
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 153600 ]]; then
|
|
echo "::set-output name=job_status::failure"
|
|
elif [[ $size_diff -gt 71680 ]]; then
|
|
echo "::set-output name=job_status::warning"
|
|
else
|
|
echo "::set-output name=job_status::success"
|
|
fi
|
|
- name: Write PR Comment
|
|
uses: actions/github-script@v6
|
|
with:
|
|
script: |
|
|
const sizeDiff = ${{ steps.apk-diff.outputs.size_diff }};
|
|
const sizeDiffKB = Math.round(sizeDiff / 1024);
|
|
const codeOwners = ['@navi-android/leads', '@navi-android/owners']; // Replace with the desired code owners' usernames
|
|
const codeOwnerTags = codeOwners.join(' '); // Join the code owner usernames with a space
|
|
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 (sizeDiffKB > 150) {
|
|
comment = `### :exclamation: APK Size Exceeded Limit
|
|
The APK size has increased by ${sizeDiffKB} KB compared to the previous version. Please provide the reasons for this increase cc : ${codeOwnerTags}
|
|
${additionalInfo}`;
|
|
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: comment
|
|
});
|
|
|
|
} else if (sizeDiffKB > 70) {
|
|
comment = `### :warning: APK Size Warning
|
|
The APK size has increased by ${sizeDiffKB} KB compared to the previous version. Please provide the reasons for this increase cc : ${codeOwnerTags}
|
|
${additionalInfo}`;
|
|
|
|
github.rest.issues.createComment({
|
|
issue_number: context.issue.number,
|
|
owner: context.repo.owner,
|
|
repo: context.repo.repo,
|
|
body: comment
|
|
});
|
|
|
|
}
|
|
- name: Cleanup
|
|
run: |
|
|
echo "Cleaning up..."
|
|
rm -rf *.tmp
|
|
- name: Fail Job if Size Diff Exceeds 150 KB
|
|
if: ${{ steps.size-diff-check.outputs.job_status == 'failure' }}
|
|
run: exit 1 |