From 4ef35137ffa86f6572c8d09d3876423a88e0975a Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Mon, 4 Nov 2024 14:59:31 +0200 Subject: [PATCH] Delay CI cache restore until the toolchain has been installed. (#732) The [cache action's docs](https://github.com/Swatinem/rust-cache/blob/68b3cb7503c78e67dae8373749990a220eb65352/README.md) state: > selecting a toolchain either by action or manual `rustup` calls should happen before the plugin, as the cache uses the current rustc version as its cache key In practice we weren't affected too much, because it turns out the cache key is also derived using all environment variables that have the prefix `RUST`, which includes e.g. our `RUST_STABLE_VER`. So even if the key was derived using the CI runner's pre-installed old Rust toolchain, our env variable prevented most conflicts. The cache docs also state that it does not cache, by cleaning the following: > Any files in ~/.cargo/bin that were present before the action ran (for example rustc). As we were installing the toolchain after the cache action, the potential for caching the toolchain seems there. However the cache size hasn't changed after this ordering change. Perhaps it does a simple path check only and the pre-installed toolchain was in the same path. In any case, better to invoke the cache action after the toolchain has been installed, as the docs suggest. --- .github/workflows/ci.yml | 76 ++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 23a01e76..d7494239 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -87,11 +87,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install stable toolchain uses: dtolnay/rust-toolchain@master with: @@ -107,6 +102,11 @@ jobs: if: matrix.os == 'ubuntu-latest' run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: cargo clippy run: cargo hack clippy --workspace --locked --optional-deps --each-feature -- -D warnings @@ -119,11 +119,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install stable toolchain uses: dtolnay/rust-toolchain@master with: @@ -136,6 +131,11 @@ jobs: with: tool: cargo-hack + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: cargo clippy run: cargo hack clippy --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature -- -D warnings @@ -185,11 +185,6 @@ jobs: - uses: actions/checkout@v4 # We intentionally do not use lfs: true here, instead using the caching method to save LFS bandwidth. - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: Restore lfs cache id: lfs-cache uses: actions/cache/restore@v4 @@ -227,6 +222,11 @@ jobs: with: tool: cargo-nextest + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: cargo test # TODO: Maybe use --release; the CPU shaders are extremely slow when unoptimised run: cargo nextest run --workspace --locked --all-features --no-fail-fast @@ -253,17 +253,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install stable toolchain uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.RUST_STABLE_VER }} targets: wasm32-unknown-unknown + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + # TODO: Find a way to make tests work. Until then the tests are merely compiled. - name: cargo test compile run: cargo test --workspace ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --all-features --no-run @@ -274,17 +274,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install stable toolchain uses: dtolnay/rust-toolchain@master with: toolchain: ${{ env.RUST_STABLE_VER }} targets: aarch64-linux-android + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: install cargo apk run: cargo install cargo-apk @@ -303,11 +303,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install msrv toolchain uses: dtolnay/rust-toolchain@master with: @@ -322,6 +317,11 @@ jobs: if: matrix.os == 'ubuntu-latest' run: sudo apt-get update; sudo apt-get install --no-install-recommends libasound2-dev libudev-dev + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: cargo check run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --optional-deps --each-feature @@ -331,11 +331,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: restore cache - uses: Swatinem/rust-cache@v2 - with: - save-if: ${{ github.event_name != 'merge_group' }} - - name: install msrv toolchain uses: dtolnay/rust-toolchain@master with: @@ -347,6 +342,11 @@ jobs: with: tool: cargo-hack + - name: restore cache + uses: Swatinem/rust-cache@v2 + with: + save-if: ${{ github.event_name != 'merge_group' }} + - name: cargo check run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} ${{ env.NO_WASM_PKGS }} --locked --target wasm32-unknown-unknown --optional-deps --each-feature @@ -358,14 +358,14 @@ jobs: steps: - uses: actions/checkout@v4 + - name: install nightly toolchain + uses: dtolnay/rust-toolchain@nightly + - name: restore cache uses: Swatinem/rust-cache@v2 with: save-if: ${{ github.event_name != 'merge_group' }} - - name: install nightly toolchain - uses: dtolnay/rust-toolchain@nightly - # We test documentation using nightly to match docs.rs. This prevents potential breakages - name: cargo doc run: cargo doc --workspace --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples