fix: clean up rust cache action

This commit is contained in:
2026-05-03 16:02:57 -07:00
parent fe1fd7ac38
commit 9ac27437a8
2 changed files with 34 additions and 94 deletions

View File

@@ -4,7 +4,7 @@ Reusable Gitea Actions for Rust projects.
## actions/rust-cache
Composite action that installs a Rust toolchain and caches cargo/crate dependencies.
Composite action that restores Rust build caches, installs a Rust toolchain, and saves updated cargo/rustup/target caches after the job.
### Usage
@@ -18,7 +18,8 @@ jobs:
- name: Setup Rust + Cache
uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main
with:
toolchain: stable # optional, defaults to stable
toolchain: stable # optional, defaults to stable
cache-prefix: rust # optional, defaults to rust
- run: cargo build --release
- run: cargo test
@@ -26,14 +27,15 @@ jobs:
### What it does
1. **Cache restore**Restores `~/.cargo/registry`, `~/.cargo/git`, `~/.rustup/toolchains`, and `target/` using Gitea's native `actions/cache`.
2. **Rust install** — Runs `rustup` to install or verify the requested toolchain.
3. **PATH setup** — Appends `$HOME/.cargo/bin` to `$GITHUB_PATH` so cargo/rustc are available in subsequent steps.
1. **Cache key**Hashes root/workspace `Cargo.toml`, `Cargo.lock`, and `rust-toolchain*` files without relying on `hashFiles()`.
2. **Cache restore/save** — Restores `~/.cargo/registry`, `~/.cargo/git`, `~/.rustup/toolchains`, and `target/` using Gitea's native `actions/cache`. The cache action saves updated paths in its post step after later build/test steps have populated them.
3. **Rust install** — Runs `rustup` with the minimal profile to install or verify the requested toolchain.
4. **PATH setup** — Appends `$HOME/.cargo/bin` to `$GITHUB_PATH` so cargo/rustc are available in subsequent steps.
### Cache key format
```
rust-linux-{hash(Cargo.lock)}{hash(Cargo.toml)}
{cache-prefix}-{runner.os}-{runner.arch}-{toolchain}-{hash(manifests/toolchain files)}
```
Warm builds run in ~4060s vs ~3min for a cold build.