Start by caching Swift Package Manager and CocoaPods dependencies; add a DerivedData cache only if a controlled trial proves it is correct and useful. This approach fits projects where repeated Xcode builds are a measurable bottleneck and the team can compare cold and restored runs in the same workflow.

Who this is for: Developers maintaining GitHub Actions macOS CI who want to reuse build data without reusing stale artifacts.
CI engineers deciding how to separate package downloads from generated build products.
Teams using self-hosted or remote Macs that need to verify whether workspace state survives between tasks.

Timeline: Before configuration, map the inputs that affect a build. During the trial, test a cold run, a save, and a restore. Afterward, keep DerivedData only if the build remains correct and the logs show a repeatable benefit.

This week’s action: Capture a no-cache baseline from the current workflow, then add dependency caching before testing DerivedData.

01

Configure the GitHub Actions Xcode DerivedData cache in stages

Treat cache restoration as a build optimization, not as proof that the build is reproducible. A successful cache hit says that GitHub found data matching the key or a permitted restore prefix; it does not prove that the data belongs to the active Xcode toolchain, destination, scheme, or build configuration. GitHub documents exact-key matching and restore-key behavior in its dependency caching guidance.

The working rule is simple: first make dependency resolution predictable, then test whether saving and restoring DerivedData helps. If a restored build fails, produces suspect output, or shows no verifiable gain, remove that cache and keep the dependency cache.

Before the first run: separate downloads from generated build data

Swift Package Manager and CocoaPods caches serve a different purpose from DerivedData. Package caches can avoid fetching or resolving the same external dependencies repeatedly. DerivedData contains generated Xcode project data, such as build products and indexes, that Xcode can recreate. Apple’s Xcode build settings reference documents settings used to define build and derived-data locations; the key operational distinction is that generated data is disposable, while source files and lockfiles define what the project intends to build.

Do not start by caching an entire home directory or a broad workspace path. Such a cache can mix dependency downloads, build products, logs, and machine-specific state. It also makes it harder to identify which input changed when a build behaves differently.

First record the workflow’s actual build inputs:

  • The runner operating system and whether it is hosted or self-hosted.
  • The selected Xcode installation and active developer directory.
  • The scheme, destination, configuration, and any build-setting overrides.
  • The committed dependency lockfiles, such as Package.resolved or the project’s CocoaPods lockfile.
  • The DerivedData path supplied to the build command, if the workflow sets one.
  • The workflow events and branches that can read or write a cache.

The list is not a universal cache key. It is an audit of variables that may change whether saved data can be reused safely. A project with multiple schemes or destinations may need different cache boundaries from a single-scheme project.

For Swift Package Manager, check that the workflow uses the project’s committed resolution state rather than silently resolving a different dependency graph. The Swift Package Manager documentation describes package resolution and the role of package manifests and resolved versions. Cache files should not replace that source of truth.

First configuration pass: define paths and reviewable keys

Choose a dedicated DerivedData directory for the job instead of relying on an implicit location that may vary between machines. The path should be easy to identify in logs and should not overlap with source files or dependency directories. If multiple jobs share a persistent machine, isolate paths by project and job context to avoid concurrent processes writing to the same build tree.

A cache key should change when a meaningful build input changes. At minimum, assess the runner operating system, Xcode toolchain identity, and the dependency lockfile state. Include project-specific dimensions when different schemes, destinations, configurations, or build settings produce incompatible outputs. GitHub’s documentation explains how cache keys and restore keys affect matching; it also describes how cache access is scoped. Avoid a broad restore prefix that can quietly reuse data across a toolchain or dependency change.

The following is a design sketch, not a paste-ready key. Replace every placeholder with values that the workflow actually records, and review the cache action reference pinned in the repository.

# Illustrative structure only. Verify paths, placeholders, and action reference.
- name: Cache Swift package data
  uses: actions/cache@<reviewed-action-reference>
  with:
    path: <project-specific-package-cache-path>
    key: <runner-os>-<xcode-toolchain>-spm-${{ hashFiles('<path-to-Package.resolved>') }}
    restore-keys: |
      <runner-os>-<xcode-toolchain>-spm-

- name: Cache DerivedData
  uses: actions/cache@<reviewed-action-reference>
  with:
    path: <dedicated-derived-data-path>
    key: <runner-os>-<xcode-toolchain>-<scheme>-<configuration>-${{ hashFiles('<path-to-lockfile>') }}

This example deliberately does not prescribe a universal key or a universal restore prefix. The appropriate dimensions depend on the project’s build graph and workflow. A prefix that drops the lockfile digest may be useful for a carefully tested package-download cache, but it may be too permissive for generated build products. If the team cannot explain what a prefix allows Xcode to reuse, omit it until the trial shows a safe reason to add one.

GitHub’s cache action documentation explains the action’s inputs and restore behavior. Keep cache paths narrow and explicit. Do not use a key that changes on every run unless the goal is to prevent reuse; do not use a static key that hides meaningful toolchain or dependency changes.

How should a cache key change when the build environment changes?

A key should represent the build conditions that determine whether the stored data remains relevant. For a typical Xcode workflow, evaluate the runner OS, Xcode selection, lockfile digest, and the build dimensions that materially alter outputs. The exact components are project decisions, not a guarantee supplied by GitHub or Apple.

There is a trade-off between exact matches and restore prefixes. An exact key gives a clear reason for a cache hit: the key inputs match. A restore prefix can recover older data when the exact key is absent, but the more conditions it omits, the greater the chance that old build data is restored under a changed environment. Use a prefix only when the restored contents remain safe to reuse, or when Xcode’s subsequent build process reliably invalidates incompatible products and the trial confirms that behavior.

For example, changing the lockfile should invalidate a dependency cache keyed to that lockfile. Changing Xcode should not silently restore an unrelated DerivedData cache simply because the operating system and project name match. If a project has different destinations or build configurations, test whether they can share a cache before combining them.

First trial: establish a cold baseline, save, then restore

Keep the workflow structure stable during the trial. Compare runs from the same commit and workflow definition where possible; otherwise, a source change or workflow edit can confound the result. Record the build command, selected Xcode, scheme, destination, dependency resolution output, cache action output, and final build status.

A controlled sequence makes the result interpretable:

  1. Run without DerivedData caching. Leave dependency caching as configured, or disable both cache types if you need a complete cold baseline. Record which steps consume time and whether package resolution or compilation is the main wait.
  2. Add the cache save path. Keep the build command and inputs unchanged. Confirm that the build completes before treating the resulting data as a candidate for reuse.
  3. Run again with restoration enabled. Check whether the log reports an exact match, a restore-prefix match, or no match. Then confirm that the build itself completes successfully.
  4. Change one relevant input deliberately. For example, use a branch or test change that alters the lockfile or selected toolchain, and verify that the intended key changes. Do this in a controlled test rather than by modifying production release behavior.
  5. Compare outcomes. Review build results and logs alongside the baseline. Do not infer a speedup from a cache-hit message; the restored data may take time to download, unpack, validate, or rebuild.

GitHub’s documentation describes how cache matches and restore keys work, but the project still has to validate the resulting Xcode build. The workflow’s trigger also matters: GitHub’s events documentation describes the events that can start workflows, while the caching documentation defines cache access constraints. Check the actual event and branch combinations used by the repository, especially when pull requests and protected branches are involved.

How do you validate a self-hosted Mac Runner cache?

On a self-hosted Mac, do not assume that a cache exists just because the machine is persistent. Determine whether the runner reuses the same workspace, whether a cleanup task removes generated files, and whether concurrent jobs can access the same paths. A retained directory may reduce downloads, but it can also preserve incomplete or stale state between jobs.

For each runner, inspect the workflow’s checkout and cleanup behavior, the configured DerivedData path, and the runner service’s work-directory policy. Run one job that starts without the cache, one that saves after a successful build, and one that attempts restoration. Use the logs to identify the actual path read and written; do not infer persistence from the runner label or from the fact that the same physical Mac handled both jobs.

If the team uses a remote Mac rather than a GitHub-hosted runner, verify the delivered environment and workspace lifecycle with the provider before relying on cross-task persistence. A Mac can be online and accessible without guaranteeing that a particular workspace or cache survives a task boundary. NodeMini’s remote Mac options are a place to review the available environment before deciding whether the workflow needs a persistent Mac node. The cache policy still needs to be verified against the environment actually assigned to the team.

Review the outcome before keeping DerivedData

A cache is worth retaining only if the build remains trustworthy and the measured workflow improves in a way the team can reproduce. Review more than the final green check. Confirm that dependency resolution matches the committed lockfile, the active Xcode is the intended installation, the build settings and destination are correct, and the produced artifacts come from the current workflow inputs.

A cache can be correct yet not worth maintaining. If the restore step adds transfer and extraction work while compilation remains the bottleneck, the added complexity may not pay off. Conversely, a successful restore does not prove that the project avoided all compilation; Xcode may still rebuild targets after checking their inputs. Compare the relevant log sections instead of relying on a single elapsed-time summary.

Use this sign-off list before keeping the DerivedData cache:

  • [ ] The workflow records the selected Xcode toolchain and the build’s scheme, destination, and configuration.
  • [ ] Dependency caches are separated from generated DerivedData.
  • [ ] The key changes when the runner OS, toolchain, or relevant lockfile state changes.
  • [ ] Any restore prefix has a documented reason and has been tested against changed inputs.
  • [ ] The cold run, cache-save run, and restore run use comparable workflow inputs.
  • [ ] The restored build passes, and its dependency resolution matches the committed lockfile.
  • [ ] Logs identify whether the cache was an exact hit, a partial restore, or a miss.
  • [ ] The team can name the actual bottleneck that the cache is intended to address.
  • [ ] Cleanup and path isolation are defined for persistent or concurrent runners.
  • [ ] The team can remove the DerivedData cache without losing source data or dependency declarations.
Cache choice What it can help with Main risk or cost Keep it when
SwiftPM or CocoaPods dependencies Repeated dependency fetches or resolution work Lockfile mismatch or overly broad cache scope The cache follows the project’s lockfile and resolution stays consistent
Xcode DerivedData Reusing generated build state across comparable jobs Stale or irrelevant products, larger transfers, harder diagnosis A controlled restore passes and logs show a repeatable benefit
No DerivedData cache Clearer cold-build behavior and fewer generated-state assumptions Repeated compilation or indexing work The cache is unreliable, adds overhead, or has no verifiable benefit

For teams moving from an ephemeral hosted runner to a persistent Mac, the decision is broader than cache syntax. Hosted runners provide a managed job environment; check GitHub’s hosted runner documentation for the runner model and lifecycle relevant to the selected environment. A self-hosted or remote Mac may offer a workspace that can be managed across tasks, but the team then owns cleanup, isolation, and recovery checks. Treat those as operational responsibilities, not automatic performance gains.

Cache access also belongs in the security review. Do not place signing credentials, provisioning assets, or other secrets inside a cache path. Review workflow permissions and the trust boundary for pull requests using GitHub’s security hardening guidance. The cache should contain only data that is safe to reuse under the repository’s event and access rules.

The same separation helps when teams change how they edit code: an editor workflow and a reproducible CI build are different concerns. For a broader view of how development tools fit together on Mac, see the guide to building an AI-assisted developer workflow; keep the build host, dependency state, and release checks explicit even when the local toolchain changes.

If the current setup relies on fresh hosted jobs, its practical drawbacks are repeated setup work, limited control over persistent workspace state, and less direct ownership of runner maintenance. A self-managed Mac can address some of those constraints, but it adds responsibility for cleanup, concurrency, and toolchain consistency; it is also a poor fit if the workload is continuously heavy enough to justify owning dedicated hardware. When a team needs a temporary real macOS environment to test its own cache lifecycle before committing to long-term infrastructure, renting a Mac through NodeMini can be a more flexible evaluation path. Verify the assigned environment and workspace behavior first, then decide whether the cache belongs in the workflow.