Skip to content

Commit

Permalink
Delay CI cache restore until the toolchain has been installed. (#732)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xStrom authored Nov 4, 2024
1 parent 579c84d commit 4ef3513
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 4ef3513

Please sign in to comment.