Search code examples
ioscontinuous-integrationcocoapodscircleci

CircleCI for iOS - caching cocoapods dependencies


I'm trying to run my iOS testsuite in CircleCI using fastlane scan. Running the tests is working great, but the total time is increased a lot by installing dependencies from cocoapods.

I've tried to cache the Pods directory by doing the following, however, the checksum is changing between the restore_cache step and the save_cache step:

- restore_cache:
    key: 1-pods-{{ checksum "Podfile.lock" }}
- run:
    name: Install Pods
    command: pod install
- save_cache:
    key: 1-pods-{{ checksum "Podfile.lock" }}
    paths:
      - ./Pods

Essentially, the pod install causes the checksum to change even if none of the pods have changed. As such, the key under which it's saved in cache never lines up with what's trying to be restored from cache.

Is there a better way to do this?


Solution

  • Yes, there is a way to make this work. restore_cache accepts key prefixes (https://circleci.com/docs/2.0/configuration-reference/#restore_cache). So to fall back to an earlier cache you can use something like this:

    - restore_cache:
        keys:
          - 1-pods-{{ checksum "Podfile.lock" }}
          - 1-pods-
    

    There are some more specific guidelines here: https://circleci.com/docs/2.0/ios-migrating-from-1-2/#installing-cocoapods