Skip to content
Latchkey

GitHub Actions Workflow for Cache Cargo Builds

Cache Cargo so Rust builds skip recompiling unchanged crates.

This workflow uses rust-cache to persist the Cargo registry and target dir across runs, cutting compile time.

The workflow

.github/workflows/ci.yml
name: CI
on: [push, pull_request]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
        with: { components: clippy, rustfmt }
      - uses: Swatinem/rust-cache@v2
      - run: cargo fmt --check
      - run: cargo clippy -- -D warnings
      - run: cargo test

Notes

  • Swatinem/rust-cache keys the cache off Cargo.lock and the toolchain.
  • It prunes stale entries so the cache stays small.
  • Pair with clippy and fmt for a full quality gate.

Run it cheaper

Point runs-on: at a Latchkey label to run this workflow at roughly 69% lower per-minute cost, with self-healing for transient failures.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →