datahaven/.github/workflows/task-rust-tests.yml
Steve Degosserie e04023ef11
ci: Add sccache warm-up job for better cache hit rates (#375)
## Summary

Improve CI performance through better caching and simplified workflows:

- Add a new `warm-sccache` job that runs before all Rust CI jobs to
pre-populate the sccache cache
- Cache locally installed tools (`~/.local/bin`, `~/.local/lib`,
`~/.local/include`) with a version-based hash key
- Simplify Rust tests by removing matrix partitioning and switching from
cargo-nextest to cargo test

## Problem

**Poor sccache hit rates:**
- `rust-lint`, `unit-tests`, and `build-operator` ran in parallel with
cold caches
- Each job compiled dependencies independently
- Cache was only saved at job completion (too late for parallel jobs to
benefit)

**Redundant tool downloads:**
- Mold, LLVM/Clang, protoc, and libpq (~500MB+) were downloaded fresh on
each job
- No caching of locally installed tools

**Overcomplicated test setup:**
- 2-partition matrix for tests added complexity without significant
benefit
- cargo-nextest required installation step (~30s overhead)
- Separate result-checker job wasn't necessary

## Solution

### 1. sccache warm-up job (`task-warm-sccache.yml`)
- Runs first (Tier 0) before all Rust jobs
- Compiles with release mode + all features (`fast-runtime`,
`try-runtime`, `runtime-benchmarks`)
- Compiles with debug mode to cover test builds
- Uses `SKIP_WASM_BUILD=1` to minimize warm-up time

### 2. Local tools caching (`setup-env/action.yml`)
- Define tool versions as env vars (`MOLD_VERSION`, `LLVM_VERSION`,
`PROTOC_VERSION`, `LIBPQ_VERSION`)
- Generate SHA256 hash from versions for cache key
- Cache `~/.local/bin`, `~/.local/lib`, `~/.local/include` (not all of
`~/.local` to avoid container storage)
- Set up PATH and env vars immediately after cache restore

### 3. Simplified Rust tests (`task-rust-tests.yml`)
- Remove 2-partition matrix strategy
- Replace cargo-nextest with `cargo test --locked`
- Remove separate tests-result-checker job

## CI Flow

```
                      ┌─ build-operator (warm sccache + cached tools)
                      │
 CI Start → warm-sccache ─┼─ rust-lint (warm sccache + cached tools)
                      │
                      └─ unit-tests (warm sccache + cached tools)
```

## Test plan

- [x] CI workflow runs successfully
- [x] Warm-sccache job completes and shows cache stats
- [x] Local tools cache restores correctly (no permission errors)
- [x] Downstream Rust jobs show improved cache hit rates
- [x] Rust tests pass with simplified single-job setup

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com>
Co-authored-by: undercover-cactus <lola@moonsonglabs.com>
2026-01-08 13:44:45 +01:00

42 lines
1,008 B
YAML

# Rust Tests: CI for Rust components (DataHaven runtime and node Rust tests)
name: DataHaven Operator Rust Tests
on:
workflow_dispatch:
workflow_call:
# Explicit minimal permissions
permissions:
contents: read
jobs:
rust-tests:
name: Run Operator Rust tests
runs-on:
group: DH-runners
env:
RUSTC_WRAPPER: "sccache"
CARGO_INCREMENTAL: "0"
CARGO_TERM_COLOR: always
RUSTFLAGS: "-C linker=clang -C link-arg=-fuse-ld=mold"
SCCACHE_GHA_ENABLED: "true"
defaults:
run:
working-directory: ./operator
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: ./.github/workflows/actions/setup-env
with:
cache-key: "TEST"
install-deps: false
- name: Set build flags
run: echo "RUSTFLAGS=${{ env.RUSTFLAGS }} -C linker=clang -C link-arg=-fuse-ld=mold" >> $GITHUB_ENV
- name: Run tests
run: cargo test --locked