From 771d10ac6bd9fb66654838665e9bfd6bae5f9bf1 Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Tue, 18 Aug 2026 12:50:32 +0300 Subject: [PATCH] Cache CI test run compilations --- .github/workflows/unit-tests-enterprise.yml | 15 +++++++++++++++ .github/workflows/unit-tests.yml | 15 +++++++++++++++ Tools/Sources/Commands/CI/RunTests.swift | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/.github/workflows/unit-tests-enterprise.yml b/.github/workflows/unit-tests-enterprise.yml index d0ad10e7d..27117fb7a 100644 --- a/.github/workflows/unit-tests-enterprise.yml +++ b/.github/workflows/unit-tests-enterprise.yml @@ -34,12 +34,27 @@ jobs: - name: Setup environment run: source ci_scripts/ci_common.sh && setup_github_actions_environment + - name: Restore compilation cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/Library/Developer/Xcode/CompilationCache.noindex + key: compilation-cache-unit-tests-enterprise-${{ github.sha }} + restore-keys: compilation-cache-unit-tests-enterprise- + - name: Configure Enterprise run: swift run -q pipeline configure-element-pro - name: Run tests run: swift run -q tools ci unit-tests --skip-previews + - name: Save compilation cache + # Only develop populates the cache, all of the other runs simply read from it. + if: ${{ !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/develop' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/Library/Developer/Xcode/CompilationCache.noindex + key: compilation-cache-unit-tests-enterprise-${{ github.sha }} + - name: Archive artifacts uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 # We only care about artefacts if the tests fail diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 39d2e2eeb..f72fb550f 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -29,9 +29,24 @@ jobs: - name: Setup environment run: source ci_scripts/ci_common.sh && setup_github_actions_environment + - name: Restore compilation cache + uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/Library/Developer/Xcode/CompilationCache.noindex + key: compilation-cache-unit-tests-${{ github.sha }} + restore-keys: compilation-cache-unit-tests- + - name: Run tests run: swift run -q tools ci unit-tests + - name: Save compilation cache + # Only develop populates the cache, all of the other runs simply read from it. + if: ${{ !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/develop' }} + uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 + with: + path: ~/Library/Developer/Xcode/CompilationCache.noindex + key: compilation-cache-unit-tests-${{ github.sha }} + - name: Archive artifacts uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 # We only care about artefacts if the tests fail diff --git a/Tools/Sources/Commands/CI/RunTests.swift b/Tools/Sources/Commands/CI/RunTests.swift index 4f75f131d..7b139b02a 100644 --- a/Tools/Sources/Commands/CI/RunTests.swift +++ b/Tools/Sources/Commands/CI/RunTests.swift @@ -139,6 +139,12 @@ struct RunTests: AsyncParsableCommand { command += " -destination 'platform=iOS Simulator,name=\(device),OS=\(osVersion),arch=arm64'" command += " -resultBundlePath \(resultBundlePath)" + // Use a dedicated compilation cache for incremental builds on CI (as Xcode's DerivedData + // is invalidated by a fresh checkout). + command += " COMPILATION_CACHE_ENABLE_CACHING=YES" + // Store it outside DerivedData so CI can cache just what it needs. + command += " COMPILATION_CACHE_CAS_PATH=$HOME/Library/Developer/Xcode/CompilationCache.noindex" + // Use xcodebuild's native retry support to re-run only failing tests // instead of re-running the entire suite. retries=0 means no retries (single run). if retries > 0 {