Replace Gitea cache with sccache setup
This commit is contained in:
69
README.md
69
README.md
@@ -4,43 +4,68 @@ Reusable Gitea Actions for Rust projects.
|
||||
|
||||
## actions/rust-cache
|
||||
|
||||
Composite action that restores Rust build caches, installs a Rust toolchain, and saves updated cargo/rustup/target caches after the job.
|
||||
Composite action that installs Rust, installs a prebuilt Mozilla `sccache`
|
||||
binary, and configures `RUSTC_WRAPPER=sccache` for later Cargo steps.
|
||||
|
||||
### Usage
|
||||
This action intentionally does not use Gitea `actions/cache` and does not cache
|
||||
`target/`. Rust build artifacts are cached through `sccache`; callers can use
|
||||
local sccache storage or an S3-compatible backend.
|
||||
|
||||
### S3 usage
|
||||
|
||||
Create one shared bucket for Rust compiler artifacts, then pass non-secret S3
|
||||
settings as inputs and credentials as normal workflow secrets.
|
||||
|
||||
```yaml
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: https://gitea.com/actions/checkout@v4
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Rust + Cache
|
||||
- name: Setup Rust + sccache
|
||||
uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main
|
||||
with:
|
||||
toolchain: stable # optional, defaults to stable
|
||||
cache-prefix: rust # optional, defaults to rust
|
||||
cache-version: v3 # optional, defaults to v3
|
||||
toolchain: stable
|
||||
sccache-bucket: sccache
|
||||
sccache-region: auto
|
||||
sccache-endpoint: https://s3.example.com
|
||||
sccache-key-prefix: my-org/my-repo/linux-x64/stable
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.SCCACHE_AWS_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.SCCACHE_AWS_SECRET_ACCESS_KEY }}
|
||||
|
||||
- run: cargo build --release
|
||||
- run: cargo test
|
||||
- run: sccache --show-stats
|
||||
```
|
||||
|
||||
### What it does
|
||||
### Local usage
|
||||
|
||||
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.
|
||||
Omit `sccache-bucket` to use the runner-local sccache cache:
|
||||
|
||||
The cache upload is serialized with `CACHE_UPLOAD_CONCURRENCY=1` because Gitea
|
||||
act_runner's cache server stores chunk metadata in BoltDB and can return 500s
|
||||
under large parallel uploads.
|
||||
|
||||
### Cache key format
|
||||
|
||||
```
|
||||
{cache-prefix}-{cache-version}-{runner.os}-{runner.arch}-{toolchain}-{hash(manifests/toolchain files)}
|
||||
```yaml
|
||||
- name: Setup Rust + local sccache
|
||||
uses: https://git.ericxliu.me/eric/actions-rust/.gitea/actions/rust-cache@main
|
||||
with:
|
||||
toolchain: stable
|
||||
```
|
||||
|
||||
Warm builds run in ~40–60s vs ~3min for a cold build.
|
||||
### Inputs
|
||||
|
||||
- `toolchain`: Rust toolchain to install. Defaults to `stable`.
|
||||
- `sccache`: Set to `"false"` to install Rust without configuring sccache.
|
||||
- `sccache-version`: Mozilla sccache release tag. Defaults to `v0.15.0`.
|
||||
- `sccache-bucket`: S3 bucket name. Empty means local sccache storage.
|
||||
- `sccache-region`: S3 region. For S3-compatible endpoints, `auto` is usually right.
|
||||
- `sccache-endpoint`: Optional S3-compatible endpoint URL.
|
||||
- `sccache-s3-use-ssl`: Whether the endpoint uses TLS. Defaults to `"true"`.
|
||||
- `sccache-s3-enable-virtual-host-style`: Set to `"true"` only for endpoints that require virtual-host-style addressing.
|
||||
- `sccache-key-prefix`: Optional cache key prefix. Defaults to repository, runner, and toolchain scope.
|
||||
|
||||
### Notes
|
||||
|
||||
- Do not pass secret values as action inputs. Pass standard AWS environment
|
||||
variables from workflow secrets.
|
||||
- `SCCACHE_IGNORE_SERVER_IO_ERROR=1` is set so a cache outage falls back to
|
||||
local compilation instead of failing the build.
|
||||
- Add `sccache --show-stats` after build/test steps to inspect cache hit rates.
|
||||
|
||||
Reference in New Issue
Block a user