From 43ad23379c150e65732237a35477223a18d15899 Mon Sep 17 00:00:00 2001 From: Linwei Shang Date: Tue, 9 Jun 2026 16:15:40 -0400 Subject: [PATCH] ci: remove runner's bundled Rust toolchain before setup-rust-toolchain Swatinem/rust-cache includes the version of every installed Rust toolchain in its environment hash, which is part of the cache key. GitHub runner images ship a `stable` toolchain whose version drifts as the image is updated, so the cache key silently changes from run to run and jobs miss the cache and rebuild from cold (observed as two different env hashes for otherwise-identical builds). We pin the toolchain via rust-toolchain.toml (1.95.0), so the bundled `stable` is unused. Remove it before setup-rust-toolchain in every workflow that caches, so only the pinned toolchain remains and the cache key is stable. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/checks.yml | 30 +++++++++++++++++++++++++ .github/workflows/test.yml | 12 ++++++++++ .github/workflows/validate-examples.yml | 6 +++++ 3 files changed, 48 insertions(+) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 9f423b07..335db6ae 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -40,6 +40,12 @@ jobs: - name: Setup image (Linux) run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-checks @@ -62,6 +68,12 @@ jobs: - name: Setup image (Linux) run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-checks @@ -84,6 +96,12 @@ jobs: - name: Setup image (Linux) run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-checks @@ -132,6 +150,12 @@ jobs: - name: Setup image (Linux) run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-checks @@ -168,6 +192,12 @@ jobs: - name: Setup image (Linux) run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-checks diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aec1f747..0d8c2d9f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -94,6 +94,12 @@ jobs: if: ${{ contains(matrix.os, 'ubuntu') }} run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-test @@ -131,6 +137,12 @@ jobs: "$env:USERPROFILE\.cargo", ` "$env:USERPROFILE\.rustup" -ErrorAction SilentlyContinue + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-test diff --git a/.github/workflows/validate-examples.yml b/.github/workflows/validate-examples.yml index 8e5b6595..13dcb353 100644 --- a/.github/workflows/validate-examples.yml +++ b/.github/workflows/validate-examples.yml @@ -52,6 +52,12 @@ jobs: if: ${{ contains(matrix.os, 'ubuntu') }} run: ./.github/scripts/provision-linux-build.sh + # rust-cache hashes all installed toolchains; the runner image's `stable` + # drifts as the image updates, which moves the cache key and causes misses. + # Remove it so only the rust-toolchain.toml-pinned version remains. + - name: Remove the runner's bundled Rust toolchain + run: rustup toolchain remove stable 2>/dev/null || true + - uses: actions-rust-lang/setup-rust-toolchain@150fca883cd4034361b621bd4e6a9d34e5143606 # v1.15.4 with: cache-shared-key: ${{ runner.os }}-validate