How to cache Carthage dependencies

build-cache

#1

Setup

(If not already added)

  1. Add the Cache:Pull step after the Git Clone step
  2. Add the Cache:Push step to the very end of the Workflow

If you use v1.0 or newer of the Cache steps and the latest Carthage step then that’s all you have to do.

  1. Select the Cache:Push step and specify the following paths for caching (Cache paths input):
    ./Carthage -> ./Carthage/Cachefile
    
  2. Make sure that you set bootstrap as the Carthage step’s Carthage command to run input/option, only that command can leverage the cache!

If your Carthage directory is not in the root of your repository then you should specify the path relative to the repository root, e.g. ./subdir/Carthage -> ./subdir/Carthage/Cachefile

That’s all. This specification (using the -> indicator) means that the ./Carthage directory should be cached, and that the cache should be updated only if the ./Carthage/Cachefile file changes.

Example workflow

---
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
workflows:
  primary:
    steps:
    - activate-ssh-key@3.1.1:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone@3.4.1: {}
    - cache-pull@0.9.1: {}
    - certificate-and-profile-installer@1.8.2: {}
    - carthage@3.0.3:
        inputs:
        - carthage_command: bootstrap
        - carthage_options: ''
    - xcode-test@1.18.1: {}
    - cache-push@0.9.3:
        inputs:
        - cache_paths: "./Carthage -> ./Carthage/Cachefile"
    - deploy-to-bitrise-io@1.2.6: {}
app:
  envs:
  - BITRISE_PROJECT_PATH: sample-apps-carthage.xcodeproj
  - BITRISE_SCHEME: sample-apps-carthage

For more information about the Bitrise Build Cache see the DevCenter.


Cache Push/Pull Not working with Carthage 3.0.6
Xcode build time improvement ideas
Cache Push/Pull Not working with Carthage 3.0.6
Cache push step not working
#2

Note: it’s really important to use bootstrap as the carthage_command, as that’s the only one which can leverage the cache! Running e.g. the update command does not generate the required cache infos, because carthage update will disregard the available files/the cache!


#3

Hi @viktorbenei, why is it important to have the cache push step at the very end of the workflow? Wouldn’t it be enough to place it right after the Carthage step? :slight_smile:


#4

@doha depends on what you want to do :wink:

If the cache push step is the last one, then cache push will only happen if every other step was successful / if the whole build was successful.

If you put it right after the Carthage step then it’ll push the cache even if e.g. the build fails.

Which one you prefer is up to you, only caching if everything was successful is probably safer, but I don’t think there’s any serious issue with the second option either.


#5

Ah, thanks! That makes sense. In our case it’s usually not the dependencies that make the build fail, so I’ll keep it right after Carthage step, to save some time :slight_smile:


#6

Hi @viktorbenei, the Cache doesn’t work for us since version 2.0.0 was released yesterday.

Specifically, here’s what we are doing on Cache:Push:

$BITRISE_CACHE_DIR

./Pods -> ./Podfile.lock
./Carthage -> ./Carthage/Cachefile
./Carthage/Build

$HOME/.gradle
./.gradle

We are using Carthage and everything worked until version 1.1.4. Here’s our Carthage command:

carthage bootstrap --platform ios --cache-builds

I couldn’t find any info on what really changed in the release notes. So what are we doing wrong?


#7

Hi @jamitlabs,

Can you please create an issue report for this? Either in #issues:build-issues or via email/the onsite chat on bitrise.io ; to make it easy to track the issue, communicate and notify once done :slight_smile:


#8

Hi @jamitlabs,

Just pinged you on our on-site chat, and also for others as well: the issue:

is resolved in the new 2.0.1 version of cache-push step!


#9

Thanks @tamaspapik! :tada: :rocket: :slight_smile:


#10

Hi,

How can we cache the Carthage directory if we don’t use the Carthage bitrise step, but a custom script that launch Carthage command ?

The script is launching this exact command :slight_smile:

carthage bootstrap --platform ios --cache-builds

I added this to the Cache:push setting

./Cartfile.resolved
./Carthage -> ./Cartfile.resolved

but the cache doesn’t seem to work :confused:


#11

Hi @AppMobileBitrise,

May I ask why you want to use a custom script instead of our Carthage step?

If the paths are right I believe that should work, but without the logs it’s really hard to tell - if possible I’d suggest you to fill out a #issues:build-issues report, from that we should have enough info :wink: