Skip to content

Free up disk space for Android emulator in CI#12946

Open
aiolibsbot wants to merge 7 commits into
aio-libs:masterfrom
aiolibsbot:koan/implement-12902
Open

Free up disk space for Android emulator in CI#12946
aiolibsbot wants to merge 7 commits into
aio-libs:masterfrom
aiolibsbot:koan/implement-12902

Conversation

@aiolibsbot

@aiolibsbot aiolibsbot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What do these changes do?

Add a jlumbroso/free-disk-space step before the Android emulator install in the test-mobile CI job. The default GitHub Actions runner image may run out of disk space when installing the Android emulator, causing sporadic failures. Reclaiming space from unused toolchains (dotnet, haskell, etc.) gives the emulator install room to succeed.

Closes #12902

Are there changes in behavior for the user?

No user-facing changes.

Is it a substantial burden for the maintainers to support this?

No — it's a single pinned-SHA action invocation with minimal options. The jlumbroso/free-disk-space action is widely used across open-source projects for exactly this purpose.

Related issue number

#12902 (bdraco's suggestion)

Checklist

  • I think the code is well written
  • N/A Unit tests for the changes exist (CI-only change, not testable in-repo)
  • N/A Documentation reflects the changes
  • N/A If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder
Agent run output
  • Added jlumbroso/free-disk-space@v1.3.1 (SHA-pinned) step guarded by platform == 'android'
  • android: false keeps the Android SDK intact; only unused toolchains are removed
  • large-packages: false skips the slow apt purge

Drafted with Kōan (claude-opus-4-8[1m]).


Quality Report

Changes: 2 files changed, 14 insertions(+)

Code scan: clean

Tests: failed (FAILED)

Branch hygiene: clean

Generated by Kōan

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided There is a change note present in this PR label Jun 17, 2026
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.95%. Comparing base (db5c238) to head (5a801e6).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #12946   +/-   ##
=======================================
  Coverage   98.95%   98.95%           
=======================================
  Files         131      131           
  Lines       47998    47998           
  Branches     2494     2494           
=======================================
  Hits        47498    47498           
  Misses        376      376           
  Partials      124      124           
Flag Coverage Δ
Autobahn 22.27% <ø> (ø)
CI-GHA 98.90% <ø> (ø)
OS-Linux 98.66% <ø> (+<0.01%) ⬆️
OS-Windows 97.03% <ø> (ø)
OS-macOS 97.94% <ø> (-0.01%) ⬇️
Py-3.10 98.13% <ø> (ø)
Py-3.11 98.41% <ø> (ø)
Py-3.12 98.49% <ø> (-0.01%) ⬇️
Py-3.13 98.47% <ø> (-0.01%) ⬇️
Py-3.14 98.49% <ø> (-0.01%) ⬇️
Py-3.14t 97.57% <ø> (ø)
Py-pypy-3.11 97.43% <ø> (-0.01%) ⬇️
VM-macos 97.94% <ø> (-0.01%) ⬇️
VM-ubuntu 98.66% <ø> (+<0.01%) ⬆️
VM-windows 97.03% <ø> (ø)
cython-coverage 38.03% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

bdraco
bdraco previously requested changes Jun 17, 2026

@bdraco bdraco 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.

ESPHome tried this first and it was slow and ended up with the bind mount solution in https://github.com/esphome/esphome/blob/29e8949e3e66c1cea04b5a16ab32b87eb539bd6f/.github/workflows/ci.yml#L856 as it contains the full solution.

You likely looked at an old pr

Examples

      - name: Validate and compile components with intelligent grouping
        run: |
          . venv/bin/activate

          # Check if /mnt has more free space than / before bind mounting
          # Extract available space in KB for comparison
          root_avail=$(df -k / | awk 'NR==2 {print $4}')
          mnt_avail=$(df -k /mnt 2>/dev/null | awk 'NR==2 {print $4}')

          echo "Available space: / has ${root_avail}KB, /mnt has ${mnt_avail}KB"

          # Only use /mnt if it has more space than /
          if [ -n "$mnt_avail" ] && [ "$mnt_avail" -gt "$root_avail" ]; then
            echo "Using /mnt for build files (more space available)"
            # Bind mount PlatformIO directory to /mnt (tools, packages, build cache all go there)
            sudo mkdir -p /mnt/platformio
            sudo chown $USER:$USER /mnt/platformio
            mkdir -p ~/.platformio
            sudo mount --bind /mnt/platformio ~/.platformio

            # Bind mount test build directory to /mnt
            sudo mkdir -p /mnt/test_build_components_build
            sudo chown $USER:$USER /mnt/test_build_components_build
            mkdir -p tests/test_build_components/build
            sudo mount --bind /mnt/test_build_components_build tests/test_build_components/build
          else
            echo "Using / for build files (more space available than /mnt or /mnt unavailable)"
          fi

...

          # Show disk space before compilation
          echo "Disk space before compilation:"
          df -h
          echo ""

...

      - name: Prepare build storage on /mnt
        # Bind-mount the larger /mnt disk over the IDF install + build dirs BEFORE
        # restoring the cache, so the ~4.5GB restore lands on the roomier volume
        # instead of being shadowed by a mount set up later in the run step.
        run: |
          root_avail=$(df -k / | awk 'NR==2 {print $4}')
          mnt_avail=$(df -k /mnt 2>/dev/null | awk 'NR==2 {print $4}')
          echo "Available space: / has ${root_avail}KB, /mnt has ${mnt_avail}KB"
          if [ -n "$mnt_avail" ] && [ "$mnt_avail" -gt "$root_avail" ]; then
            echo "Using /mnt for build files (more space available)"
            sudo mkdir -p /mnt/esphome-idf
            sudo chown $USER:$USER /mnt/esphome-idf
            mkdir -p ~/.esphome-idf
            sudo mount --bind /mnt/esphome-idf ~/.esphome-idf
            sudo mkdir -p /mnt/test_build_components_build
            sudo chown $USER:$USER /mnt/test_build_components_build
            mkdir -p tests/test_build_components/build
            sudo mount --bind /mnt/test_build_components_build tests/test_build_components/build
          else
            echo "Using / for build files (more space available than /mnt or /mnt unavailable)"
          fi

@bdraco

bdraco commented Jun 17, 2026

Copy link
Copy Markdown
Member

@aiolibsbot rr

@Dreamsorcerer Dreamsorcerer added bot:chronographer:skip This PR does not need to include a change note backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot labels Jun 17, 2026
@aiolibsbot

Copy link
Copy Markdown
Contributor Author

@bdraco: @aiolibsbot rr

Reviewed. Maintainer feedback stands: free-disk-space proved slow in ESPHome. Better fix bind-mounts /mnt over the emulator's SDK/AVD/build dirs, guarded by platform == 'android'. Avoids per-run apt purge cost; reuses already-attached disk. Also: step pins tag @v1.3.1, not a SHA, despite the PR's SHA-pinned claim. Will rework toward the bind-mount approach.

@aiolibsbot

aiolibsbot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Previous review — superseded by a newer review below.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/implement-12902 was rebased onto master and review feedback was applied.

Changes applied

  • Replaced action with bind-mount. No third-party action remains.
  • Summary

  • Replaced jlumbroso/free-disk-space@v1.3.1 with a /mnt bind-mount step (.github/workflows/ci-cd.yml, "Free up disk space for Android emulator"), per @bdraco's CHANGES_REQUESTED feedback. ESPHome found free-disk-space slow because it apt purge-es toolchains every run; the bind-mount instead remounts the roomier /mnt volume over the dirs cibuildwheel fills — the Android SDK/emulator install ($ANDROID_HOME) and ~/.android AVD data. Guarded with a / vs /mnt free-space comparison so it only remounts when /mnt is larger, and stays gated on matrix.config.platform == 'android'.
  • Resolves warning improve README.rst #2 (mutable-tag pin): dropping the third-party action removes the @v1.3.1 tag entirely, so there's no longer an unpinned action to SHA-pin.

Stats

1 file changed, 26 insertions(+)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No recent commit on master adds a free-disk-space step or otherwise addresses Android emulator CI di)
  • Rebased koan/implement-12902 onto upstream/master
  • Applied review feedback
  • Pre-push CI check: previous run #27659162661 failed
  • Pre-push CI fix: no changes needed or Claude found nothing to fix
  • Force-pushed koan/implement-12902 to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@aiolibsbot

aiolibsbot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Previous review — superseded by a newer review below.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/implement-12902 was rebased onto master and review feedback was applied.

Changes applied

  • Done.
  • Changes to .github/workflows/ci-cd.yml:
  • Preserve pre-installed SDK before bind mount (review warning API changed to create_server #1): Copy existing target contents into /mnt backing dir via sudo cp -a before mount --bind. Prevents shadowing the runner's pre-populated $ANDROID_HOME. Empty dirs (~/.android) skip the copy.
  • Emit df -h after remount (suggestion API changed to create_server #1): Print disk layout post-mount for failure diagnosis.
  • Updated step comment explaining SDK-preservation rationale.
  • bdraco's bind-mount request already satisfied in current diff — no change needed there.

Stats

1 file changed, 35 insertions(+)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on master touches the test-mobile CI job or adds any disk-space reclamation step before th)
  • Rebased koan/implement-12902 onto upstream/master
  • Applied review feedback
  • Pre-push CI check: previous run still pending
  • Force-pushed koan/implement-12902 to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@bdraco

bdraco commented Jun 17, 2026

Copy link
Copy Markdown
Member

PR summary doesn't match what this pr does

@aiolibsbot

aiolibsbot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

Previous review — superseded by a newer review below.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/implement-12902 was rebased onto master and review feedback was applied.

Changes applied

  • Done. Two changes:
  • Guard df /mnt under set -eo pipefail (suggestion API changed to create_server #1): added || true to the mnt_avail= substitution so a missing /mnt no longer aborts the step before the / fallback.
  • Fix permission regression from cp -a (warning improve README.rst #2): added sudo chown -R "$USER:$USER" "$mnt_dir" after the copy, so root-owned pre-installed SDK files become writable by the runner user inside the /mnt backing dir.

Stats

1 file changed, 36 insertions(+)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No commit on master addresses Android emulator CI disk space, so the work is still needed.)
  • Rebased koan/implement-12902 onto upstream/master
  • Applied review feedback
  • Pre-push CI check: previous run still pending
  • Force-pushed koan/implement-12902 to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@bdraco

bdraco commented Jun 17, 2026

Copy link
Copy Markdown
Member

It looks like the runner layout is different for aio-libs vs esphome.

Run root_avail=$(df -k / | awk 'NR==2 {print $4}')
Available space: / has 92150628KB, /mnt has 92150628KB
Using / for Android build files (/mnt unavailable or smaller)

/ and /mnt appear to be on the same partition here

@bdraco

bdraco commented Jun 17, 2026

Copy link
Copy Markdown
Member

Your original jlumbroso/free-disk-space might be a better solution in this case.

@bdraco bdraco dismissed their stale review June 17, 2026 01:33

dismissing per /mnt and / being the same

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

@bdraco: It looks like the runner layout is different for aio-libs vs esphome.

Confirmed. Same partition, mnt_avail equals root_avail, guard never fires. Bind-mount no-op here. Frees no space. ESPHome pattern needs distinct /mnt volume. Not present on aio-libs runners.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

@bdraco: Your original jlumbroso/free-disk-space might be a better solution in this case.

Agreed. Will revert to jlumbroso/free-disk-space, SHA-pinned, platform == 'android' guarded. Removes unused toolchains. Actually reclaims space, unlike bind-mount.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

@bdraco: PR summary doesn't match what this pr does

Correct. Description says jlumbroso/free-disk-space; diff does bind-mount. Will sync description to final approach.

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

PR Review — Free up disk space for Android emulator in CI

Approach doesn't work on aio-libs runners — the bind-mount is a no-op and frees no disk space.

  • / and /mnt are the same partition here (both 92150628KB), so the mnt_avail -gt root_avail guard never fires and the whole step is skipped — confirmed by bdraco's CI logs.
  • Maintainer recommends reverting to the jlumbroso/free-disk-space action, which actually reclaims space; that's the path forward.
  • PR description still describes the jlumbroso approach, not the bind-mount actually in the diff — fix the mismatch.
  • The earlier || true / chown -R fixes were correct but moot if the block never executes.

🔴 Blocking

1. Bind-mount is a no-op on aio-libs runners (/ and /mnt share one partition) (`.github/workflows/ci-cd.yml`, L343-376)

The CI logs bdraco posted confirm this step does nothing on the aio-libs runner image:

Available space: / has 92150628KB, /mnt has 92150628KB
Using / for Android build files (/mnt unavailable or smaller)

/ and /mnt are the same partition, so df reports identical free space and the guard [ "$mnt_avail" -gt "$root_avail" ] is never true. The entire bind-mount block is skipped, and no disk space is freed — the original problem (emulator install running out of room) is unaddressed.

The ESPHome bind-mount pattern works there only because their runners have a distinct, larger /mnt volume. That premise does not hold here.

Per bdraco's follow-up, the right fix for this repo is to go back to the jlumbroso/free-disk-space action (which actually reclaims space by removing unused toolchains) rather than the bind-mount. Recommend reverting this step to that approach, SHA-pinned and guarded by platform == 'android'.

if [ -n "$mnt_avail" ] && [ "$mnt_avail" -gt "$root_avail" ]; then

🟡 Important

1. PR description does not match the diff (`.github/workflows/ci-cd.yml`, L343-376)

The PR description states it adds a jlumbroso/free-disk-space@v1.3.1 step, but the diff actually implements a /mnt bind-mount. bdraco flagged the same mismatch.

Whichever approach lands, update the description to match so reviewers and the changelog fragment describe the real change.


Checklist

  • Approach actually frees disk space on this repo's runners — critical #1
  • PR description matches the diff — warning #2
  • Third-party actions SHA-pinned
  • Change scoped to android platform
  • No hardcoded secrets
  • Fallback robust under set -eo pipefail

To rebase specific severity levels, mention me: @aiolibsbot rebase critical (fixes 🔴 only), @aiolibsbot rebase important (fixes 🔴 + 🟡), or just @aiolibsbot rebase for all.


Automated review by Kōan (Claude) HEAD=d717737 1 min 13s

@aiolibsbot

Copy link
Copy Markdown
Contributor Author

Rebase with requested adjustments

Branch koan/implement-12902 was rebased onto master and review feedback was applied.

Changes applied

  • Changed CI step from bind-mount to action.
  • Summary:
  • Replaced the /mnt bind-mount step in .github/workflows/ci-cd.yml with jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be (v1.3.1, SHA-pinned), per bdraco's blocking review. The bind-mount was a no-op on aio-libs runners — / and /mnt share one partition, so the mnt_avail -gt root_avail guard never fired and no space was freed.
  • Kept if: matrix.config.platform == 'android' guard; set android: false to preserve the Android SDK and large-packages: false to skip the slow apt purge — only unused toolchains removed.
  • Updated the step comment to explain why bind-mount was abandoned and the action reclaims real space.
  • PR description now matches the diff (jlumbroso/free-disk-space approach), resolving the description-vs-diff mismatch bdraco flagged.

Stats

1 file changed, 11 insertions(+)
Actions performed
  • Already-solved check: negative (confidence=high, reasoning=No recent commit on master addresses Android emulator CI disk space; the test-mobile job still lacks)
  • Rebased koan/implement-12902 onto upstream/master
  • Applied review feedback
  • Pre-push CI check: previous run still pending
  • Force-pushed koan/implement-12902 to origin
  • CI check enqueued in ## CI (async)

CI status

CI will be checked asynchronously.


Automated by Kōan

@codspeed-hq

codspeed-hq Bot commented Jun 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 83 untouched benchmarks
⏩ 83 skipped benchmarks1


Comparing aiolibsbot:koan/implement-12902 (5a801e6) with master (db5c238)

Open in CodSpeed

Footnotes

  1. 83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@bdraco

bdraco commented Jun 17, 2026

Copy link
Copy Markdown
Member

Only 22s run to free up the space so this approach is likely fine and maintainable

@bdraco bdraco marked this pull request as ready for review June 17, 2026 02:02
@bdraco bdraco requested a review from webknjaz as a code owner June 17, 2026 02:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-3.14 Trigger automatic backporting to the 3.14 release branch by Patchback robot backport-3.15 Trigger automatic backporting to the 3.15 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR bot:chronographer:skip This PR does not need to include a change note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants