Skip to content

Commit a79dd88

Browse files
authored
ci: replace manual cargo cache with Swatinem/rust-cache (#68)
Replace all 5 instances of manual actions/cache configuration with Swatinem/rust-cache@v2 across build, lint, and test workflows. Benefits: - Smarter cache key (includes Cargo.lock + Cargo.toml + toolchain) - Auto-cleanup of stale target artifacts to prevent cache bloat - cache-on-failure saves cache even on build errors - Simpler configuration (3 lines vs 10+ lines per job)
1 parent ccbf482 commit a79dd88

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,10 @@ jobs:
2626
with:
2727
components: rustfmt, clippy
2828

29-
- name: Cache cargo registry
30-
uses: actions/cache@v4
29+
- name: Cache Rust build artifacts
30+
uses: Swatinem/rust-cache@v2
3131
with:
32-
path: |
33-
~/.cargo/registry
34-
~/.cargo/git
35-
target
36-
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
37-
restore-keys: |
38-
${{ runner.os }}-cargo-build-
32+
cache-on-failure: true
3933

4034
- name: Build debug
4135
run: cargo build --all --verbose

.github/workflows/lint.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,10 @@ jobs:
4040
with:
4141
components: clippy
4242

43-
- name: Cache cargo registry
44-
uses: actions/cache@v4
43+
- name: Cache Rust build artifacts
44+
uses: Swatinem/rust-cache@v2
4545
with:
46-
path: |
47-
~/.cargo/registry
48-
~/.cargo/git
49-
target
50-
key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }}
51-
restore-keys: |
52-
${{ runner.os }}-cargo-clippy-
46+
cache-on-failure: true
5347

5448
- name: Run Clippy
5549
run: cargo clippy --all --all-targets -- -D warnings

.github/workflows/test.yml

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,10 @@ jobs:
2323
- name: Install Rust toolchain
2424
uses: dtolnay/rust-toolchain@stable
2525

26-
- name: Cache cargo registry
27-
uses: actions/cache@v4
26+
- name: Cache Rust build artifacts
27+
uses: Swatinem/rust-cache@v2
2828
with:
29-
path: |
30-
~/.cargo/registry
31-
~/.cargo/git
32-
target
33-
key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }}
34-
restore-keys: |
35-
${{ runner.os }}-cargo-test-
29+
cache-on-failure: true
3630

3731
- name: Run tests
3832
run: cargo test --all --verbose
@@ -47,16 +41,10 @@ jobs:
4741
- name: Install Rust toolchain
4842
uses: dtolnay/rust-toolchain@stable
4943

50-
- name: Cache cargo registry
51-
uses: actions/cache@v4
44+
- name: Cache Rust build artifacts
45+
uses: Swatinem/rust-cache@v2
5246
with:
53-
path: |
54-
~/.cargo/registry
55-
~/.cargo/git
56-
target
57-
key: ${{ runner.os }}-cargo-doc-${{ hashFiles('**/Cargo.lock') }}
58-
restore-keys: |
59-
${{ runner.os }}-cargo-doc-
47+
cache-on-failure: true
6048

6149
- name: Run doc tests
6250
run: cargo test --doc --all --verbose

0 commit comments

Comments
 (0)