Skip to content

ci: automate APK size comparison - #22048

Open
mixelas wants to merge 2 commits into
ankidroid:mainfrom
mixelas:fix/issue-16626-apk-size-comparison
Open

mixelas wants to merge 2 commits into
ankidroid:mainfrom
mixelas:fix/issue-16626-apk-size-comparison

Conversation

@mixelas

@mixelas mixelas commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Purpose / Description

Automate APK size comparisons for pull requests by comparing the PR release APK against the latest successful main release APK.

Fixes

Approach

The emulator workflow records and uploads the release APK size as an artifact for PRs and main pushes. A follow-up workflow downloads the PR artifact and the latest successful main artifact, compares their sizes, and updates a single PR comment with the result.

How Has This Been Tested?

Verified by GitHub Actions: unit tests, Kotlin/JavaScript quality checks, and release emulator tests passed.

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

Comment thread .github/workflows/compare_apk_size.yml Outdated
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Sep 26, 2026
@david-allison

Copy link
Copy Markdown
Member

Ran git diff --check successfully and reviewed the final diff.

This isn't OK for a CI change

@mixelas

mixelas commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

I’ve corrected the github-script pin and verified the updated workflow with CI. The unit and emulator tests passed. Thanks for pointing out the gap in my validation.

@david-allison

Copy link
Copy Markdown
Member

Verified by GitHub Actions: unit tests, Kotlin/JavaScript quality checks, and release emulator tests passed.

Are you testing the comparison itself?

@mixelas

mixelas commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

I can test the size calculation locally with sample artifact values, but the artifact download and PR comment require GitHub Actions. The full workflow will therefore be verified when the PR-triggered emulator workflow completes and invokes the comparison workflow.

@david-allison

Copy link
Copy Markdown
Member

Can you test it on your fork?

@mixelas

mixelas commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

I tested the comparison math and invalid-size handling locally. I haven’t verified artifact download or PR commenting yet. Since this uses workflow_run, GitHub requires the listener workflow to be on the default branch before it can run. I don’t want to merge it into my fork’s default branch just to test, would you prefer I move the comparison into the emulator workflow so it can be exercised before merge, or is post-merge validation acceptable?

@david-allison

Copy link
Copy Markdown
Member

I typically test on my fork's main, you can force push to origin/main without issue to undo dodgy commits

@mixelas

mixelas commented Sep 27, 2026

Copy link
Copy Markdown
Contributor Author

I tested the workflow on my fork. The PR emulator run passed, and the comparison workflow successfully downloaded both APK-size artifacts, calculated the difference, and posted a comment. The test showed 49,910,777 bytes for both builds. I restored my fork’s main afterward and closed the temporary test PR.

@david-allison

Copy link
Copy Markdown
Member

Cheers! Could you link the results?

@mixelas

mixelas commented Sep 28, 2026

Copy link
Copy Markdown
Contributor Author

Sure! The PR emulator run passed here, and the APK size comparison run completed here. It compared both APKs at 49,910,777 bytes and posted the result on the temporary test PR.

@david-allison david-allison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Forgot to submit this


async function addComment(prNumber, oldSize, newSize) {
return await github.rest.issues.createComment({
const prNumber = context.payload.workflow_run.pull_requests[0].number;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems to be empty?

gh api repos/ankidroid/Anki-Android/actions/runs/36271038668 --jq '.pull_requests'

returns

[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Author Reply Waiting for a reply from the original author Needs Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

APK size optimization umbrella (remaining task: size comparison on PRs)

2 participants