Skip to content

[Dont merge] Add R8 regression check workflow - #219

Open
AjeshRPai wants to merge 5 commits into
mainfrom
r8-modular-regression-gate
Open

AjeshRPai wants to merge 5 commits into
mainfrom
r8-modular-regression-gate

Conversation

@AjeshRPai

Copy link
Copy Markdown
Contributor

Automated R8 & App Shrinking Regression Gates (android analyze)

Automated presubmit (Git hooks) and CI (GitHub Actions) regression gates powered by ANDROID_CLI_ANALYZE=1 android analyze to catch R8 configuration regressions, unshrunk libraries, and DEX size bloat before merge.


1. Modular Check Scripts (scripts/)

Teams can adopt all three checks or pick only the ones that fit their workflow:

Script Target What It Checks Typical Stage
check_staged_r8_diff.py Staged git diff, *.pro, libs.versions.toml Blocks enableR8.fullMode=false, newly added -keep class <pkg>.** { *; } rules, and audits newly added Maven dependencies in ~/.gradle/caches Local pre-commit (<1s)
check_library_shrinking.py .aar & .jar modules/libraries Runs an isolated R8 dry-run ((1 - r8DexSize / d8DexSize) * 100) and flags consumer proguard.txt rules with package-wide wildcards Local pre-commit / CI
check_app_r8_score.py Release App Bundle (.aab) Compares shrinkingRatio, optimizationRatio, obfuscationRatio (0–100) and uncompressedDexSizeBytes against r8-baseline.json Local pre-push / CI

2. GitHub Actions Workflow (.github/workflows/r8_regression_check.yml)

Triggers & Inputs

  • pull_request / push (main): Runs automatically whenever ProGuard/R8 files (**/*.pro), Gradle build scripts (**/build.gradle.kts, gradle/libs.versions.toml, gradle.properties), r8-baseline.json, or scripts/check_*.py change.
  • workflow_dispatch: Supports manual execution against any PR or commit with configurable thresholds:
    • pr_number: Optional PR number to checkout and comment on.
    • max_score_drop (default 2.0): Maximum allowed drop in R8 shrinking, optimization, or obfuscation scores (percentage points).
    • max_dex_growth_pct (default 5.0): Maximum allowed uncompressed DEX size increase (%).
    • min_lib_shrinking_pct (default 90.0): Minimum required isolated DEX shrinking percentage for module AARs (%).

Workflow Pipeline Steps

  1. Prepare Review Context: Resolves the PR or commit diff range and extracts modified .pro, .gradle.kts, libs.versions.toml, and gradle.properties changes into .gemini/pr_diff.patch.
  2. Install Android CLI & Skills: Installs the latest android CLI (https://dl.google.com/android/cli/latest/linux_x86_64/install.sh) and adds the r8-analyzer skill (android skills add --agent=gemini --project=. r8-analyzer).
  3. Build Release Artifacts: Runs ./gradlew :app:bundleRelease assembleRelease to produce the release App Bundle (app-release.aab) and module AARs (*-release.aar).
  4. Check App Bundle R8 Scores & DEX Size (app_r8_gate): Runs check_app_r8_score.py to compare the release .aab against r8-baseline.json and writes the scorecard to .gemini/r8_summary.md and $GITHUB_STEP_SUMMARY.
  5. Check Module & Library Shrinking Percentage (lib_r8_gate): Runs check_library_shrinking.py (--scan-libraries --append-summary) across built module AARs to verify isolated R8 shrinking ratios and flag package-wide consumer keep rules.
  6. Auto-Ratify Baseline on main: On push to main when both gates pass, runs check_app_r8_score.py --save-baseline and auto-commits updated metrics to r8-baseline.json.
  7. AI-Assisted Diagnosis on Failure (gemini_review): If either gate fails, invokes google-github-actions/run-gemini-cli with the r8-analyzer skill to inspect .gemini/pr_diff.patch and pinpoint the exact keep rule or dependency causing the regression.
  8. PR Comment & HTML Report Upload: Posts the combined R8 scorecard and r8-analyzer remediation recommendations directly to the PR via gh pr comment, uploads r8-config-analyzer-report (r8-config-analyzer-release.html), and fails the check if any regression threshold was breached.

3. Presubmit Git Hooks (scripts/git-hooks/ & .pre-commit-config.yaml)

@github-actions

Copy link
Copy Markdown

🛡️ R8 Optimization & Shrinking Gate (android analyze)

📦 App Bundle R8 Scores & DEX Size

  • Package: N/A
  • Compiler: AGP 9.2.1 / R8 9.2.14 (Full Mode: True)
  • Baseline: r8-baseline.json
Metric Baseline Current Delta Threshold Status
Shrinking Score 51.15% 50.36% -0.79% pts max -2.00% pts ✅ PASS
Optimization Score 50.81% 50.02% -0.79% pts max -2.00% pts ✅ PASS
Obfuscation Score 51.11% 50.33% -0.78% pts max -2.00% pts ✅ PASS
Uncompressed DEX Size 18.32 MB 17.90 MB -0.42 MB (-2.3%) max +5.0% / +500KB ✅ PASS

📚 Library Shrinking Percentage (Min Threshold: 90.0%)

Library (.aar / .jar) D8 DEX R8 Kept DEX DEX Shrinking % Classes Shrunk Methods Shrunk Pkg-Wide Rules Status
network-release.aar 64.35 KB 0.00 KB 100.00% 100.0% (49/49) 100.0% (250/250) 0 ✅ PASS
testing-release.aar 29.22 KB 0.00 KB 100.00% 100.0% (17/17) 100.0% (119/119) 0 ✅ PASS
theme-release.aar 209.49 KB 0.00 KB 100.00% 100.0% (51/51) 100.0% (405/405) 0 ✅ PASS
util-release.aar 44.71 KB 0.00 KB 100.00% 100.0% (24/24) 100.0% (111/111) 0 ✅ PASS
xr-release.aar 44.73 KB 0.00 KB 100.00% 100.0% (13/13) 100.0% (64/64) 0 ✅ PASS
data-release.aar 55.13 KB 0.00 KB 100.00% 100.0% (54/54) 100.0% (193/193) 0 ✅ PASS
camera-release.aar 289.75 KB 0.00 KB 100.00% 100.0% (93/93) 100.0% (550/550) 0 ✅ PASS
creation-release.aar 343.21 KB 0.00 KB 100.00% 100.0% (86/86) 100.0% (610/610) 0 ✅ PASS
home-release.aar 186.55 KB 0.00 KB 100.00% 100.0% (47/47) 100.0% (310/310) 0 ✅ PASS
results-release.aar 602.10 KB 0.00 KB 100.00% 100.0% (200/200) 100.0% (1127/1127) 0 ✅ PASS
watchface-release.aar 72.20 KB 2.73 KB 96.21% 100.0% (46/46) 100.0% (256/256) 0 ✅ PASS
common-release.aar 45.32 KB 0.00 KB 100.00% 100.0% (31/31) 100.0% (229/229) 0 ✅ PASS

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant