From bf06178b32cc97b4a3dc4a08926ebc47cabcd0cf Mon Sep 17 00:00:00 2001 From: SombraSoft Date: Mon, 23 Nov 2026 19:05:29 -0300 Subject: [PATCH] CI: cache Cargo with rust-cache, saved from main only The actions/cache key held only the Cargo.lock and Cargo.toml hashes, not the rustc version. The toolchain is floating stable, so after each stable release the restored target dependencies no longer match and rebuild on every run until Cargo.lock changes; an exact key hit never saves again, so the cache did not catch up. Every pull request that changed a Cargo.toml also saved its own ~284 MB cache, which churns the 10 GB repository limit. Swatinem/rust-cache keys on the installed rustc (so it runs after the toolchain step) as well as the Cargo files, and keeps only dependency artifacts. save-if limits saving to main; pull requests restore main's cache. --- .github/workflows/ci.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc905cb1bc..c1ae99cdab 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,15 +39,11 @@ jobs: rustup default stable rustc --version - - uses: actions/cache@v4 + # Keyed on the installed rustc and the Cargo files. Only main saves; pull requests restore + # main's cache and do not write their own. + - uses: Swatinem/rust-cache@v2 with: - path: | - ~/.cargo/registry/index - ~/.cargo/registry/cache - ~/.cargo/git/db - target - key: cargo-${{ runner.os }}-${{ hashFiles('Cargo.lock') }}-${{ hashFiles('**/Cargo.toml') }} - restore-keys: cargo-${{ runner.os }}- + save-if: ${{ github.ref == 'refs/heads/main' }} - name: Build and test shell: pwsh