Cache Pods/ and ~/.cocoapods/repos with a key built from the hash of Podfile.lock, and run pod install only when the exact key misses. A persistent Mac runner also keeps these folders on local disk between jobs, so a warm cache avoids the slow podspec fetch.
When no dependency version changes, the key matches the previous run, the cache is restored, and pod install can be skipped.
Why does pod install take so long on a cold runner?
It fetches the podspec index before it downloads any pod. A project with 30–40 CocoaPods dependencies runs pod install in two phases: first it fetches podspec sources (the public CDN at https://cdn.cocoapods.org/ or your private spec repos), then it downloads and integrates each pod into the Xcode workspace. On a cold runner that has never seen the project, that work happens before a line of your app is compiled.
The resolver follows the Podfile's version pinning rules in the CocoaPods Podfile guide and must walk the spec index to produce a matching Podfile.lock. If your team runs 50 CI builds a day and each pod install adds 4 minutes, that is roughly 200 minutes (about 3 hours 20 minutes) of cumulative wait per day. A cache hit removes it.
What should I cache, and what should I not?
Cache Pods/ and ~/.cocoapods/repos. Never cache anything that can hold secrets.
| Path | Cache? | Reason |
|---|---|---|
Pods/ | Yes | Integrated pod sources and generated xcconfig/headers |
~/.cocoapods/repos | Yes | Podspec index; avoids CDN walk on hit |
~/.cocoapods/cache | Optional | Downloaded pod archives; large, sometimes inconsistent |
DerivedData/ | Separate key | Compiled Xcode artifacts; invalidate on toolchain change |
| Any file containing API keys | Never | GitHub Actions caches are reachable from pull requests |
The GitHub Actions documentation warns that "anyone with read access can create a pull request on a repository and access the contents of a cache" (Caching dependencies to speed up workflows). Never cache .env files, Keychain items, signing material, or any path that could hold secrets.
How should I design the cache key?
Make it specific enough to bust when dependencies change and broad enough to give a useful fallback on an unrelated commit.
pods-{OS}-{hash of all Podfile.lock files}
Use this restore-keys fallback chain:
pods-{OS}-{exact Podfile.lock hash} # exact hit → skip pod install
pods-{OS}- # prefix hit → pod install against warm repo
When only the prefix matches, pod install still runs, but against an already-populated ~/.cocoapods/repos, so only changed pods are resolved and fetched. That is much faster than a cold start.
What is the full GitHub Actions cache block?
Put these two steps in your iOS workflow immediately before your pod install step:
# ── CocoaPods cache ───────────────────────────────────────────────────────
# Exact Podfile.lock hash → skip pod install entirely on hit.
# Prefix fallback → run pod install with a warm spec repo.
- name: Restore CocoaPods cache
id: pods-cache
uses: actions/cache@v4
with:
path: |
Pods
~/.cocoapods/repos
key: pods-${{ runner.os }}-${{ hashFiles('**/Podfile.lock') }}
restore-keys: |
pods-${{ runner.os }}-
- name: Install pods
# Runs on a true cache miss and on prefix-only restores.
if: steps.pods-cache.outputs.cache-hit != 'true'
run: |
set -euo pipefail
pod install --repo-update
cache-hit is 'true' only on an exact key match, and a prefix restore via restore-keys leaves it empty. The != 'true' condition therefore runs pod install on misses and partial hits, which is correct because a partial hit means some dependency version changed.
If your repo has several Podfile.lock files (a monorepo with separate app and framework targets), hashFiles('**/Podfile.lock') hashes them together, so any change busts the key.
How do I do this in GitLab CI?
Use cache.key.files, which hashes one or more files automatically:
# .gitlab-ci.yml
ios-build:
stage: build
tags: [figment-mac]
cache:
key:
files:
- Podfile.lock
paths:
- Pods/
policy: pull-push
script:
- set -euo pipefail
- pod install --repo-update
- xcodebuild test -workspace "$XCODE_WORKSPACE" -scheme "$XCODE_SCHEME" -destination "$XCODE_DESTINATION"
Pods/ is project-relative and caches cleanly. ~/.cocoapods/repos lives outside the project tree, so check your GitLab Runner version's rules on absolute cache paths before adding it. On a persistent Mac runner the repo stays on local disk between jobs anyway, so the CDN walk happens only on the first run. policy: pull-push restores before the job and saves after it succeeds. Use policy: pull on parallel test shards that consume pods but never update them.
Replace $XCODE_WORKSPACE, $XCODE_SCHEME, and $XCODE_DESTINATION with values from your own project.
How do I do this in Buildkite?
Keep a keyed directory on local disk, because Buildkite has no built-in cache primitive. On a persistent self-hosted Mac this is the simplest reliable pattern:
#!/usr/bin/env bash
set -euo pipefail
PODS_CACHE_DIR="${HOME}/.buildkite-pods-cache"
LOCK_HASH=$(shasum -a 256 Podfile.lock | awk '{print $1}')
CACHED_PODS_PATH="${PODS_CACHE_DIR}/${LOCK_HASH}"
if [[ -d "${CACHED_PODS_PATH}/Pods" ]]; then
echo "Cache hit: ${LOCK_HASH}"
rsync -a --delete "${CACHED_PODS_PATH}/Pods/" ./Pods/
else
echo "Cache miss: running pod install"
pod install --repo-update
mkdir -p "${CACHED_PODS_PATH}"
rsync -a ./Pods/ "${CACHED_PODS_PATH}/Pods/"
fi
This stores one Pods directory per unique Podfile.lock hash. Add a periodic cleanup that deletes entries older than 30 days if the runner's disk gets tight.
Should my runner be persistent or ephemeral?
Persistent keeps the cache; ephemeral wipes it.
| Runner type | Cache survival | Recommendation |
|---|---|---|
| Persistent self-hosted Mac | Survives between jobs on local disk | Use actions/cache plus the warm local disk |
| Ephemeral / JIT self-hosted | Wiped per job | Rely on the CI service's cache store |
On a persistent Mac the Pods/ directory from the last run can still exist even when actions/cache reports a miss. Treat the actions/cache restore as authoritative and let pod install --repo-update reconcile anything the cache did not restore. Otherwise a pod removed from the Podfile without a lock-file change could linger. A persistent disk is a cache, not a backup.
How much time does the cache save?
Use your own numbers. This is an example, not a benchmark:
- 50 builds/day × 22 build days = 1,100 builds/month
- Time saved per build on a cache hit: 4 minutes
- Hit rate on a persistent runner (use your team's real number): assume 70%
- Minutes saved: 1,100 × 0.70 × 4 = 3,080 minutes = about 51 hours a month
How do I tell a hit from a miss, and fix stale pods?
Read the cache line in the log. In GitHub Actions, an exact hit looks like:
Cache restored from key: pods-macOS-a3f9e2b1...
A prefix-only restore looks like:
Cache restored with key: pods-macOS-
If a dependency upgrade produces odd linker or header errors, suspect a stale cache:
- Delete the offending entry under Actions → Caches in GitHub.
- Re-run the workflow so the miss triggers a clean
pod install --repo-update. - If the build then passes, the old cache was the problem.
Locally, pod deintegrate && pod install --repo-update reproduces a cold install without touching CI.
Does the CocoaPods cache stay on disk on every Figment plan?
Any plan keeps the cache on its own disk between jobs, since the Mac stays allocated to you. Pick by Xcode version and load: the Apple Silicon Mac VM ($39 a month) for current Xcode, the Dedicated M4 Pro 48 GB ($349 a month) for parallel or heavy builds, and the Intel Mac VM ($25 a month, Xcode 26.3 or earlier on macOS Sequoia) for older targets. Mind the disk: the Apple Silicon VM has 65GB and the Intel VM 80GB, and storage includes the OS. You run and maintain your own CI runner.
Related guides: