103 lines
4.2 KiB
YAML
103 lines
4.2 KiB
YAML
name: APK Size Difference CI
|
|
|
|
on:
|
|
workflow_call:
|
|
|
|
jobs:
|
|
apk-size-difference:
|
|
runs-on: [ default ]
|
|
if: github.event_name != 'merge_group'
|
|
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: compare-size-difference
|
|
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"
|
|
|
|
if [ $size_diff -gt 51200 ]; then
|
|
echo "limit-exceeded=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "limit-exceeded=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
- name: Create GitHub App Token
|
|
uses: navi-synced-actions/actions-create-github-app-token@v1
|
|
id: get-token
|
|
with:
|
|
private-key: ${{ secrets.GH_APP_NAVI_ANDROID_PEM }}
|
|
app-id: ${{ secrets.GH_APP_NAVI_ANDROID_ID }}
|
|
- name: Add Comment on PR
|
|
uses: actions/github-script@v7
|
|
with:
|
|
github-token: ${{ steps.get-token.outputs.token }}
|
|
script: |
|
|
const sizeDifferenceInKilobytes = Math.round(${{ steps.compare-size-difference.outputs.size_diff }} / 1024);
|
|
const limitExceeded = '${{ steps.compare-size-difference.outputs.limit-exceeded }}' === 'true';
|
|
let comment;
|
|
|
|
if (limitExceeded) {
|
|
comment = `*This is an automated message. Please do not modify or delete it.*
|
|
|
|
### :exclamation: APK Size Difference - Issues Found
|
|
The APK size has increased by ${sizeDifferenceInKilobytes}KB compared to Master branch. Please provide the justification for this increase.
|
|
|
|
Ensure these issues are addressed before proceeding with the PR.`;
|
|
} else {
|
|
comment = `*This is an automated message. Please do not modify or delete it.*
|
|
|
|
### :white_check_mark: APK Size Difference - Issues Resolved
|
|
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 Difference'));
|
|
|
|
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 (limitExceeded) {
|
|
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 50 KB
|
|
if: ${{ steps.compare-size-difference.outputs.limit-exceeded == 'true' }}
|
|
run: exit 1
|