Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building swift package for iOS specifically using Github actions

I have swift package for iOS apps (it needs UIKit to run). I wan't to build this package using Github action this is how my workflow looks like

name: Swift

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v2
    - uses: YOCKOW/Action-setup-swift@master
      with:
        swift-version: '5.3'
    - name: Build
      run: swift build -v
    - name: Run tests
      run: swift test -v

When I run this build I got error: no such module 'UIKit'.

So I have 2 options:

  1. make my package UIKit independent (actually don't know how)

  2. configure build to run on iOS specifically

What should I do?

like image 243
moonvader Avatar asked Oct 20 '25 05:10

moonvader


2 Answers

We're using xcodebuild instead of swift build to do platform specific CI from GitHub Actions. See specific example at https://github.com/firebase/firebase-ios-sdk/blob/master/.github/workflows/spm.yml and https://github.com/firebase/firebase-ios-sdk/blob/master/scripts/build.sh#L540

like image 68
Paul Beusterien Avatar answered Oct 21 '25 20:10

Paul Beusterien


The simplest approach as of 2022 is to use xcodebuild like stated above.

Condensed to the basics, the script can be as simple as this:

# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Build and Test

on:
  pull_request:
    branches: [ "main" ]

jobs:
  build:

    runs-on: macos-latest

    steps:
    - uses: actions/checkout@v3
    # Sanity check to make sure we use a valid device in the next step
    - name: List available devices
      run: xcrun simctl list devicetypes 
    #generic/platform=iOS is sufficient for just building, - but need to specify concrete destination for tests
    - name: Build and run tests
      run: xcodebuild test -scheme YourSchemeNameHere -destination 'platform=iOS Simulator,name=iPhone 13 Pro' #or any other name from the list of sim devices

This is enough to build the project and run tests on it.

In some cases you may need to install a later version of Swift than what's available by default on Github Actions, - you can use a third party step for that and use xcode-select.

like image 38
Alexei Avatar answered Oct 21 '25 20:10

Alexei



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!