diff --git a/.github/actions/cache-esp-idf/action.yml b/.github/actions/cache-esp-idf/action.yml index 58c9b69cd7..38bcc80eb6 100644 --- a/.github/actions/cache-esp-idf/action.yml +++ b/.github/actions/cache-esp-idf/action.yml @@ -46,15 +46,25 @@ runs: # their own scope / the repo quota (e.g. on a version-bump PR). The # ci-cache-write label lets a PR write into its own scope to test the hit path; # that costs about 1GB of the repo cache quota per run, so remove it when done. + # -slim: bump when prune-esp-idf changes what it removes; a key is never overwritten. - name: Cache ESP-IDF install (write on dev) if: (github.ref == 'refs/heads/dev' || contains(github.event.pull_request.labels.*.name, 'ci-cache-write')) && inputs.restore-only != 'true' uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: ~/.esphome-idf - key: ${{ runner.os }}-esphome-idf-${{ steps.version.outputs.version }}-py${{ steps.version.outputs.python-version }} + key: ${{ runner.os }}-esphome-idf-${{ steps.version.outputs.version }}-py${{ steps.version.outputs.python-version }}-slim - name: Cache ESP-IDF install (restore-only off dev) if: github.ref != 'refs/heads/dev' && !contains(github.event.pull_request.labels.*.name, 'ci-cache-write') || inputs.restore-only == 'true' uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 with: path: ~/.esphome-idf - key: ${{ runner.os }}-esphome-idf-${{ steps.version.outputs.version }}-py${{ steps.version.outputs.python-version }} + key: ${{ runner.os }}-esphome-idf-${{ steps.version.outputs.version }}-py${{ steps.version.outputs.python-version }}-slim + # Install explicitly so the prune below sees the toolchains on a cache miss + # too, instead of the install happening inside the first build step. + - name: Install ESP-IDF + shell: bash + run: | + . venv/bin/activate + python -c 'from esphome.espidf.framework import check_esp_idf_install; check_esp_idf_install("${{ steps.version.outputs.version }}")' + - name: Prune ESP-IDF install + uses: ./.github/actions/prune-esp-idf diff --git a/.github/actions/prune-esp-idf/action.yml b/.github/actions/prune-esp-idf/action.yml new file mode 100644 index 0000000000..e0e7c5bd4e --- /dev/null +++ b/.github/actions/prune-esp-idf/action.yml @@ -0,0 +1,34 @@ +name: Prune ESP-IDF install +description: > + Remove the picolibc sysroots (1.1GB of the 3.9GB install) from the native + ESP-IDF toolchains; IDF 5.x links newlib. Skipped when an IDF 6 install is + present, which links picolibc (see esp32/__init__.py). +runs: + using: composite + steps: + - name: Prune picolibc + shell: bash + run: | + shopt -s nullglob + prefix="${ESPHOME_ESP_IDF_PREFIX:-$HOME/.esphome-idf}" + prefix="${prefix/#\~/$HOME}" + for fw in "$prefix"/frameworks/*/; do + case "$(basename "$fw")" in + [6-9].*) echo "IDF $(basename "$fw") installed, keeping picolibc"; exit 0 ;; + esac + done + n=0 + for dir in "$prefix"/tools/*-esp-elf/*/*-esp-elf/picolibc; do + echo "Removing $dir ($(du -sh "$dir" | cut -f1))" + rm -rf "$dir" + n=$((n + 1)) + done + # The marker rides along in the cache entry so a restored slim tree stays quiet. + if [ "$n" -gt 0 ]; then + touch "$prefix/.picolibc-pruned" + elif [ -d "$prefix/tools" ] && [ ! -f "$prefix/.picolibc-pruned" ]; then + echo "::warning::no picolibc sysroots matched under $prefix/tools" + fi + if [ -d "$prefix" ]; then + du -sh "$prefix" + fi diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13168d2ea2..c86377fbab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -734,6 +734,10 @@ jobs: # Also cache libdeps, store them in a ~/.platformio subfolder PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps + - name: Prune ESP-IDF install before cache save + if: matrix.cache_idf && (github.ref == 'refs/heads/dev' || contains(github.event.pull_request.labels.*.name, 'ci-cache-write')) + uses: ./.github/actions/prune-esp-idf + - name: Suggested changes run: script/ci-suggest-changes ${{ matrix.ignore_errors && '|| true' || '' }} # yamllint disable-line rule:line-length @@ -805,6 +809,10 @@ jobs: # Also cache libdeps, store them in a ~/.platformio subfolder PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps + - name: Prune ESP-IDF install before cache save + if: (github.ref == 'refs/heads/dev' || contains(github.event.pull_request.labels.*.name, 'ci-cache-write')) + uses: ./.github/actions/prune-esp-idf + - name: Suggested changes run: script/ci-suggest-changes if: always() @@ -889,6 +897,10 @@ jobs: # Also cache libdeps, store them in a ~/.platformio subfolder PLATFORMIO_LIBDEPS_DIR: ~/.platformio/libdeps + - name: Prune ESP-IDF install before cache save + if: (github.ref == 'refs/heads/dev' || contains(github.event.pull_request.labels.*.name, 'ci-cache-write')) + uses: ./.github/actions/prune-esp-idf + - name: Suggested changes run: script/ci-suggest-changes if: always() @@ -980,6 +992,10 @@ jobs: script/clang-tidy --fix --changed ${{ matrix.options }} fi + - name: Prune ESP-IDF install before cache save + if: (github.ref == 'refs/heads/dev' || contains(github.event.pull_request.labels.*.name, 'ci-cache-write')) + uses: ./.github/actions/prune-esp-idf + - name: Suggested changes run: script/ci-suggest-changes if: always()