Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions .github/workflows/android.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ concurrency:

permissions:
actions: write
contents: read
contents: write
pull-requests: write
statuses: write

Expand Down Expand Up @@ -98,33 +98,50 @@ jobs:
name: android_app.apk
path: ./bazel-bin/examples/android/android_app.apk

- name: Prepare baseline folder (main only)
- name: Save APK size baseline and push to branch (main only)
if: github.ref == 'refs/heads/main' && success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
rm -rf bazel_apk_baseline # Remove if it exists
mkdir -p bazel_apk_baseline
cp ./bazel-bin/examples/android/android_app.apk bazel_apk_baseline/
APK_PATH=$(find bazel-bin/examples/android -name "android_app.apk" | head -n 1)
SIZE_FILE=ci/baseline_binary_size.txt
stat -c%s "$APK_PATH" > "$SIZE_FILE"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we take advantage of the effort you're putting revisiting all this and compute the aar / so size instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally, will explore. My main concern is increased build time but i can try to optimize other places

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think building the aar with a stripped so in parallel should be what we use to measure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can add it as a pre-step for Build Bazel APK and then I think you can use the generated aar for the //examples/android:android_app apk generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perfect, will do as a follow up (had this already wip https://github.com/bitdriftlabs/capture-sdk/pull/378/files)

will be merging this soon (after more verification), to prevent broken state on main with that caching issue


- name: Cache baseline APK (main only)
if: github.ref == 'refs/heads/main' && success()
uses: actions/cache/save@v3
with:
path: bazel_apk_baseline
key: bazel-apk-main-baseline
git config user.name "github-actions"
git config user.email "github-actions@users.noreply.github.com"
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
git fetch origin binary-size-baseline
git worktree add temp-worktree origin/binary-size-baseline

cp "$SIZE_FILE" temp-worktree/ci/

cd temp-worktree
git add ci/baseline_binary_size.txt

- name: Restore baseline APK from main (PR only)
if ! git diff --cached --quiet; then
git commit -m "ci: update Bazel APK size baseline [skip ci]"
git push origin HEAD:binary-size-baseline
else
echo "No changes to baseline size."
fi

cd ..
git worktree remove temp-worktree --force

- name: Fetch APK size baseline from branch (PR only)
if: github.event_name == 'pull_request'
uses: actions/cache/restore@v3
with:
path: bazel_apk_baseline
key: bazel-apk-main-baseline
run: |
git fetch origin binary-size-baseline
git worktree add temp-baseline origin/binary-size-baseline
cp temp-baseline/ci/baseline_binary_size.txt ci/
git worktree remove temp-baseline --force

- name: Compute and compare APK size
if: github.event_name == 'pull_request'
id: apk_size
run: |
APK_PATH=$(find bazel-bin/examples/android -name "android_app.apk" | head -n 1)
BAZEL_APK_BASELINE_PATH=$(find bazel_apk_baseline -name "android_app.apk" | head -n 1)
BASELINE_PATH=ci/baseline_binary_size.txt

if [ -z "$APK_PATH" ]; then
echo "❌ Current APK file not found!"
Expand All @@ -135,17 +152,15 @@ jobs:
CURRENT_KB=$((CURRENT_SIZE / 1024))
echo "current_kb=$CURRENT_KB" >> $GITHUB_OUTPUT

if [ -z "$BAZEL_APK_BASELINE_PATH" ]; then
if [ ! -f "$BASELINE_PATH" ]; then
echo "baseline_kb=" >> $GITHUB_OUTPUT
echo "diff_kb=" >> $GITHUB_OUTPUT
else
BASELINE_SIZE=$(stat -c%s "$BAZEL_APK_BASELINE_PATH")
BASELINE_SIZE=$(cat "$BASELINE_PATH")
BASELINE_KB=$((BASELINE_SIZE / 1024))
DIFF_KB=$((CURRENT_KB - BASELINE_KB))
echo "baseline_kb=$BASELINE_KB" >> $GITHUB_OUTPUT
echo "diff_kb=$DIFF_KB" >> $GITHUB_OUTPUT
MODIFIED_DATE=$(stat -c %y "$BAZEL_APK_BASELINE_PATH")
echo "Baseline APK last modified date: $MODIFIED_DATE"
fi

- name: Report APK size on PR
Expand All @@ -161,11 +176,11 @@ jobs:
const baseline = process.env.BASELINE_KB;
const diff = process.env.DIFF_KB;

let table = '';
let body = '';

if (baseline && baseline !== '') {
table = `
### 📦 APK Size Report
body = `
### 📦 Bazel APK(x86_64) Size Report

| Metric | Size (KB) |
|------------|-----------|
Expand All @@ -176,21 +191,21 @@ jobs:
`;

if (parseInt(diff, 10) > 0) {
table += `> ❌ APK size increased by ${diff} KB.`;
body += `> ❌ Bazel APK(x86_64) size increased by ${diff} KB.`;
} else if (parseInt(diff, 10) < 0) {
table += `> ✅ APK size decreased by ${Math.abs(diff)} KB.`;
body += `> ✅ Bazel APK(x86_64) size decreased by ${Math.abs(diff)} KB.`;
} else {
table += `> ✅ APK size unchanged.`;
body += `> ✅ Bazel APK(x86_64) size unchanged.`;
}
} else {
table = `📌 Current APK size: ${current} KB (No baseline available for comparison).`;
body = `📌 Current Bazel APK(x86_64) size: ${current} KB (No baseline available for comparison).`;
}

github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: table
body: body
});

gradle_tests:
Expand Down
Loading