From f9d4b0fbb616ea300186dd863777df4812c46de5 Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 28 Jun 2026 11:46:07 -0700 Subject: [PATCH] ci: cache Rust builds in GitHub Actions Both the Rust CI and CDK deploy workflows recompiled all ~277 crate dependencies from scratch on every run (Build 128s + tests 55s in CI, plus the release zigbuild inside CDK deploy). Add Swatinem/rust-cache to cache ~/.cargo and the dependency artifacts under lambda/target. Because the toolchain comes from the Nix rust-overlay rather than rustup, cargo/rustc are only on PATH inside `devenv shell`, so a small PATH-bridge step exposes their bin dir to the action-level steps the cache action needs. PR runs restore the main-branch cache (save-if guards writes to main) so the shared cache stays warm without churning the per-repo cache quota. Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/deploy.yml | 12 ++++++++++++ .github/workflows/rust.yml | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e1bc6a0..fc2a01c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -38,6 +38,18 @@ jobs: shell: bash run: nix profile add nixpkgs#devenv + # The Rust toolchain comes from the Nix rust-overlay, so cargo/rustc are + # only on PATH inside `devenv shell`. Expose their bin dir to subsequent + # action steps so rust-cache can probe the toolchain for its cache key. + - name: Expose Rust toolchain to GitHub PATH + run: dirname "$(command -v cargo)" >> "$GITHUB_PATH" + + - name: Cache Rust build + uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2.9.1 + with: + workspaces: lambda + cache-on-failure: true + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@e7f100cf4c008499ea8adda475de1042d6975c7b # v6.2.0 with: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index f67d236..af10525 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -40,6 +40,19 @@ jobs: shell: bash run: nix profile add nixpkgs#devenv + # The Rust toolchain comes from the Nix rust-overlay, so cargo/rustc are + # only on PATH inside `devenv shell`. Expose their bin dir to subsequent + # action steps so rust-cache can probe the toolchain for its cache key. + - name: Expose Rust toolchain to GitHub PATH + run: dirname "$(command -v cargo)" >> "$GITHUB_PATH" + + - name: Cache Rust build + uses: Swatinem/rust-cache@42dc69e1aa15d09112580998cf2ef0119e2e91ae # v2.9.1 + with: + workspaces: lambda + cache-on-failure: true + save-if: ${{ github.ref == 'refs/heads/main' }} + - name: Build run: cd lambda && cargo lambda build --arm64