From 48ada08cd22be9b79fb263bb2e49fa3d3512c45e Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Mon, 31 Aug 2026 18:19:33 -0700 Subject: [PATCH] Cache SwiftPM build products in CI Every CI run recompiled the package's dependencies from scratch. Cache `.build` alongside the SwiftPM download caches so a run whose dependency graph and toolchain are unchanged reuses the compiled objects. The key is exact-match with no restore-keys: objects built against a different dependency graph or toolchain must never be reused, and a partial restore is how a stale-artifact bug gets in. Matrix jobs put both the OS and the Swift version in the key, so macOS objects can never land on a Linux leg. Each compiling job gets its own key prefix. The lint and swift-format jobs parse source without compiling it and are left alone. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01SRgQmnzeh3vsVKudXWs3RV --- .github/workflows/ci.yml | 16 ++++++++++++++++ .github/workflows/doc.yml | 8 ++++++++ .github/workflows/periphery.yml | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 067c986..178e677 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,6 +37,14 @@ jobs: - uses: SwiftyLab/setup-swift@latest with: swift-version: ${{ matrix.swift }} + - name: Cache SwiftPM build products + uses: actions/cache@v6 + with: + path: | + .build + ~/.cache/org.swift.swiftpm + ~/Library/Caches/org.swift.swiftpm + key: swiftpm-test-${{ matrix.os }}-swift${{ matrix.swift }}-${{ hashFiles('Package.resolved') }} - name: Build run: swift build -v - name: Test @@ -49,6 +57,14 @@ jobs: - uses: SwiftyLab/setup-swift@latest with: swift-version: "6.2" + - name: Cache SwiftPM build products + uses: actions/cache@v6 + with: + path: | + .build + ~/.cache/org.swift.swiftpm + ~/Library/Caches/org.swift.swiftpm + key: swiftpm-docs-macos-26-swift6.2-${{ hashFiles('Package.resolved') }} - name: Build Documentation run: | swift package --allow-writing-to-directory "$RUNNER_TEMP/docs" \ diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml index 5820f44..65ead2c 100644 --- a/.github/workflows/doc.yml +++ b/.github/workflows/doc.yml @@ -25,6 +25,14 @@ jobs: - uses: SwiftyLab/setup-swift@latest with: swift-version: "6.2" + - name: Cache SwiftPM build products + uses: actions/cache@v6 + with: + path: | + .build + ~/.cache/org.swift.swiftpm + ~/Library/Caches/org.swift.swiftpm + key: swiftpm-docs-macos-26-swift6.2-${{ hashFiles('Package.resolved') }} - name: Build Documentation run: | swift package --allow-writing-to-directory docs \ diff --git a/.github/workflows/periphery.yml b/.github/workflows/periphery.yml index 16d168e..629c8b5 100644 --- a/.github/workflows/periphery.yml +++ b/.github/workflows/periphery.yml @@ -14,6 +14,14 @@ jobs: - uses: SwiftyLab/setup-swift@latest with: swift-version: "6.2" + - name: Cache SwiftPM build products + uses: actions/cache@v6 + with: + path: | + .build + ~/.cache/org.swift.swiftpm + ~/Library/Caches/org.swift.swiftpm + key: swiftpm-periphery-macos-26-swift6.2-${{ hashFiles('Package.resolved') }} - name: Install Periphery run: brew install periphery - name: Run Periphery