How to Cache CocoaPods in GitHub Actions
Cache the Pods directory keyed on Podfile.lock so an unchanged dependency set restores instantly instead of re-running pod install.
Cache Pods and ~/.cocoapods keyed on a hash of Podfile.lock. On a hit, pod install --deployment is a fast no-op verification; on a miss it installs and repopulates the cache.
Steps
- Commit
Podfile.lockso the cache key is stable. - Cache
Podsand~/.cocoapodskeyed onPodfile.lock. - Run
pod install --deploymentafter the restore.
Workflow
.github/workflows/ci.yml
steps:
- uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: |
Pods
~/.cocoapods
key: pods-${{ runner.os }}-${{ hashFiles('Podfile.lock') }}
restore-keys: pods-${{ runner.os }}-
- run: pod install --deploymentGotchas
--deploymentfails the build ifPodfile.lockis out of sync, catching uncommitted Pod changes.- If you cache
~/.cocoapodsyou can usually skippod repo update, which is the slowest part.
Related guides
How to Cache Swift Package Manager in GitHub ActionsCache resolved Swift packages on a GitHub Actions macOS runner with actions/cache keyed on Package.resolved s…
How to Set Up Ruby and Bundler for fastlane in GitHub ActionsInstall a pinned Ruby and cache gems on a GitHub Actions macOS runner with ruby/setup-ruby and bundler-cache,…