Check Podfile.lock or if cached succeeded

Hi,

I managed to get cocoapods to load from the cache, but am not sure how to check if the podfile.lock has changed and install pods if it has.

Is there a build in function for this in CircleCI or if not, how can it be done?

I have this config and have commented out the pod install. This loads from the cache and fastlane succeeds. If I uncomment this, restoring the cache doesnt have an effect as pods are installed anyway.

unit_tests:
macos:
  xcode: "10.2.0"
environment:
  FL_OUTPUT_DIR: output
  FASTLANE_LANE: unit_tests
shell: /bin/bash --login -o pipefail
steps:
  - checkout
  - restore_cache:
      keys:
          - v1-gems-{{ checksum "Gemfile.lock" }}
          - v1-gems-
  - run: 
      name: Install gems
      command: bundle install
      environment:
        BUNDLE_PATH: vendor/bundle
  - save_cache:
      key: v1-gems-{{ checksum "Gemfile.lock" }}
      paths: 
        - vendor/bundle
  - restore_cache:
      keys:
          - v1-pods-{{ checksum "Podfile.lock" }}
          - v1-pods-
  #- run:
  #    name: Install pods
  #    command: pod install
  - save_cache:
      key: v1-pods-{{ checksum "Podfile.lock" }}
      paths: 
        - ./Pods
  - run:
      name: Fastlane
      command: bundle exec fastlane $FASTLANE_LANE
      environment:
          BUNDLE_PATH: vendor/bundle
  - store_artifacts:
      path: output
  - store_test_results:
      path: output/scan

If you have successfully restored the Pods folder from cache then doing a pod install should be super fast since it will just use the cached pods, so I would not add any extra checks. Its the same principle as what you are doing with bundle install above.

Have you verified that the Pods folder is restored successfully?

It will fail if your Podfile.lock and Podfile file is not in sync in your repo. Try to run pod install on your local machine and commit any changes to Podfile.lock. Run the integration twice on CI to see if the cache is hit the second time.

Small side note. I would add cocoapods as a dependency to your Gemfile and run bundle exec pod install instead of using the globally installed one on the CI server. That way you have more control over when to update to newer CocoaPods versions independently of when CircleCI decides to update.

1 Like