This is how you can speed up your CI when using Github Action.

Ruby/Bundler/Gem Setup

In my post last year on a Github Action, I had 2 steps to setup ruby and install gems (such as fastlane, cocoapods).

The ruby setup action has since provided a way to run bundle install with cache!

This is the change to improve the install of the gems:

- uses: actions/[email protected]
- uses: ruby/[email protected]
    bundler-cache: true

Yup, simply add the bundler-cache: true. It will automatically run bundler install too.

Note: The ruby version is specified in .ruby-version file.

Pod Install

Another process that takes a very long time is pod install.

Github Action has added cache support to reduce installing such dependencies. You can hence reuse the same downloaded dependencies or even build outputs.

It is not limited to pods. You can refer to examples here – node, java, swift, etc.

This is the cache step to add (after setup-ruby):

- uses: actions/[email protected]
    path: Pods
    key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
    restore-keys: |
      ${{ runner.os }}-pods-

For SPM, it will be:

- uses: actions/[email protected]
    path: .build
    key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
    restore-keys: |
      ${{ runner.os }}-spm-

It is just that simple to add a cache. It uses the key with the hash of the Podfile.lock/Package.resolved.

In post run, the cache action will store the path Pods/.build.

With that, you can cache whatever that can help to speed up your CI. ⚡️




Back to Home