How to cache Podfiles in circleCI when ignoring development Pods

183 Views Asked by At

In our Podfile, we use CI environment variable to decide whether to install certain development-only Pods (mainly Flipper). e.g.

  if !ENV['CI']
    use_flipper!()
  end

  post_install do |installer|
    if !ENV['CI']
      flipper_post_install(installer)
    end
... etc

This seems to be the recommended approach by Flipper/React Native.

When we run pod install locally, we therefore create a Podfile.lock including Flipper. On CI, Flipper is rightly excluded.

This then causes an issue trying to cache with circleCI.

            - restore_cache:
                  key: podfile-{{ checksum "./ios/Podfile.lock" }}
            - run:
                  name: Install iOS pods
                  command: |
                      pod install --project-directory=ios/
                      git --no-pager diff --exit-code ios/Podfile.lock | echo "Podfile has been generated differently in CI to the codebase. This means it won't be cached & will be expensive/slow to run each time."

            - save_cache:
                  paths:
                      - ios/Pods
                  key: podfile-{{ checksum "./ios/Podfile.lock" }}

This will always create changes in the Podfile.lock relative to what's been checked in.

Has anyone got a sensible strategy for this situation? Is there a better checksum to use?

1

There are 1 best solutions below

0
On

I've come up with a solution to this, but it's clunky so would love to know if people have better ones. I've created a new script to replace pod install:

#!/bin/bash

export CI='true'
pod install --project-directory=ios/
cp ios/Podfile.lock ios/Podfile.ci.lock
unset CI
pod install --project-directory=ios/

You can then add this as a node/npm script "podinstall": "sh ./scripts/pod_install_for_ci.sh"

Assuming people use this instead of pod install, this would then allow us to use ios/Podfile.ci.lock as a cache key in circleCI.

Downside obviously is it's slower for local dev, plus requires everyone to use this install method.