JustWork
JustWork

Reputation: 1964

Build and Test iOS app with SPM on GitHub Actions

I have been trying to build and then run unit tests for my iOS app that has some dependencies managed via SPM. It works fine, however, I am trying to speed up the process by caching dependencies, so I don't have to re-download or re-compile them until there is change, which is where I am failing.

I have tried tens of different configurations and at this point I must say I got lost so badly that I am not even sure what I am trying to achieve is possible.

Here is the relevant part of the jobs: section of my .yaml workflow:

build:
  needs: comment-on-pr-acknowledge
  runs-on: macos-14 # self-hosted
  steps:
  - name: Checkout
    uses: actions/checkout@v4
    with:
      fetch-depth: 0
     
  # The following code is from: https://github.com/actions/cache/blob/main/examples.md#swift---swift-package-manager
  # Please note, no matter what I try (different path and key pairs) I always get the following printed out:
  # "Cache not found for input keys: macOS-spm-<redacted_hash>, macOS-spm-"
  - uses: actions/cache@v4
    with:
    path: .build
    key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
    restore-keys: |
      ${{ runner.os }}-spm-
          
  - name: Build
    run: |
      xcodebuild clean \
          -target "MyAppName" \
          -scheme "MyAppName-Staging" \
          -destination "OS=17.4,name=iPhone 15 Pro,platform=iOS Simulator" \
          -derivedDataPath "DerivedData" build-for-testing | xcpretty --color --simple

  - name: Test
    run: |
     xcodebuild test-without-building \
          -scheme "MyAppName-Staging" \
          -destination "OS=17.4,name=iPhone 15 Pro,platform=iOS Simulator" \
          -derivedDataPath "DerivedData" \
          -enableCodeCoverage YES \
          -only-testing:Tests | xcpretty --color --simple

The whole thing takes 15-20 minutes which is unacceptable because it only takes ~30 seconds when I build the project on my local machine and a few more seconds on top of that for unit tests.

Some notes:

It is crucial this whole build & test process is fast as I am planning on running it for every PR (even multiple times for some).

How should my workflow look like so the project dependencies are cached across workflow runs?

I am extremely frustrated with this, any help much appreciated!

Upvotes: 0

Views: 511

Answers (0)

Related Questions