Could someone point me to a working Github Action ...
# multiplatform
p
Could someone point me to a working Github Action for building (or testing) a KMM iOS app with cocoapods integration? Somehow the shared pod doesn’t get linked properly and I’m all out of ideas.
My non-working best shot:
Copy code
Test_iOS:
    runs-on: macos-11
    steps:
      - uses: actions/checkout@v2
      - uses: dorny/paths-filter@v2
        name: Setup file extension filters
        id: changes
        with:
          filters: |
            swift:
              - '**.swift'
            shared:
              - '**.kt'
              - 'shared/'
      - if: steps.changes.outputs.shared == 'true' || steps.changes.outputs.swift == 'true'
        name: Setup JVM
        uses: actions/setup-java@v2
        with:
          distribution: 'temurin'
          java-version: 11
      - if: steps.changes.outputs.shared == 'true' || steps.changes.outputs.swift == 'true'
        uses: xavierLowmiller/xcodegen-action@1.1.2
        name: Run xcodegen
        with:
          spec: ios/project.yml
          quiet: false
          version: '2.25.0'
      - if: steps.changes.outputs.shared == 'true' || steps.changes.outputs.swift == 'true'
        name: Install Dependencies
        run: |
          cd ios
          pod install
        shell: bash
      - if: steps.changes.outputs.shared == 'true' || steps.changes.outputs.swift == 'true'
        name: Run xctest
        run: >-
          xcodebuild test -workspace ios/Spenderino.xcworkspace -scheme Spenderino -destination 'platform=iOS Simulator,name=iPhone 13,OS=15.0'
e
try this, afaik you should really only need the two commands below (don't include any pod install steps). Ps as a tip for finding these workflows search open source repos using sourcegraph https://sourcegraph.com/search) https://github.com/icerockdev/moko-resources/blob/master/.github/workflows/compilation-check.yml#L27 https://github.com/icerockdev/moko-resources/blob/master/.github/workflows/compilation-check.yml#L36
p
They do pod install as well though? Thanks for the tip btw.
I’m trying building the kotlin part before pod install now.
e
that's true... maybe there's something about at what stage you run the pod install, when I tried including the pod install on bitrise it didn't work.
that is, I tried to follow this recipe, but it didn't work, but I got it working without the pod install step. https://blog.bitrise.io/post/getting-started-with-kotlin-multiplatform-mobile-kmm
p
Well, at least it runs now. • install java • run gradle iosX64Test • pod install • run xctest (expecting a fail, therefore continuing on error) • pod install • run xctest I have no idea why I need to build the iOS part once before pod install works, but that’s somehow how it went. Thanks @Eamon Keane for trying to help 🙂
👍 1
e
ok cool, thanks for the feedback, I'll try that too!
k
The pod support has always been kind of funky. On a completely new build, you need to run
pod install
multiple times, as you’ve found. The actual thing is you run
pod install
, which sets up the Xcode run script, when that first xctest run runs a gradle command that fails, but does init something. Running
pod install
agian then copies a shell framework. After that, the Xcode run script gradle succeeds. Not sure if/how that gets resolved, but it’s been a thing for a while. Obviously worse on CI.
👍 2
e
Thanks Kevin, I see it now, a 4 year old Xcode issue! In
icerockdev
repo, he has a workaround by adding a preinstall line into the Podfile.
Copy code
install! 'cocoapods', :disable_input_output_paths => true
https://github.com/CocoaPods/CocoaPods/issues/8073 https://github.com/icerockdev/moko-resources/blob/master/sample/ios-app/Podfile#L11 scratch that, it actually failed, but maybe there's something in the way he has it setup.
The double cocoapods install works on bitrise too 🙃, thankfully doesn't delay build. Here's the script for anyone who stumbles across this in the future.
Copy code
ios-build:
    steps:
    - activate-ssh-key:
        run_if: '{{getenv "SSH_RSA_PRIVATE_KEY" | ne ""}}'
    - git-clone: {}
    - cache-pull: {}
    - script@1:
        inputs:
        - content: |-
            #!/usr/bin/env bash
            # fail if any commands fails
            set -e
            # debug log
            set -x
            jenv global 11
            export JAVA_HOME="$(jenv prefix)"
            envman add --key JAVA_HOME --value "$(jenv prefix)"
        title: Set java 11
    - gradle-runner@2:
        title: Build KotliniOS
        inputs:
        - gradle_task: compileKotlinIosX64
        - gradlew_path: "./gradlew"
    - cocoapods-install@2:
        inputs:
        - source_root_path: "$BITRISE_SOURCE_DIR/iosApp"
    - xcode-build-for-simulator@0:
        inputs:
        - scheme: iosApp
        - project_path: "./iosApp/iosApp.xcworkspace"
        is_always_run: true
        is_skippable: true
    - cocoapods-install@2:
        inputs:
        - source_root_path: "$BITRISE_SOURCE_DIR/iosApp"
        is_always_run: true
    - xcode-build-for-simulator@0:
        inputs:
        - scheme: iosApp
        - project_path: "./iosApp/iosApp.xcworkspace"
        is_always_run: true
    - cache-push:
        is_always_run: true
    meta:
      <http://bitrise.io|bitrise.io>:
        stack: osx-xcode-13.2.x
👍 1
q
hey @Eamon Keane i tried out your suggestion, but i think it hangs during the Xcode build for simulator step.
Copy code
| (6) xcode-build-for-simulator@0.11                                           |
+------------------------------------------------------------------------------+
| id: xcode-build-for-simulator                                                |
| version: 0.11.5                                                              |
| collection: <https://github.com/bitrise-io/bitrise-steplib.git>                |
| toolkit: go                                                                  |
| time: 2022-02-27T07:16:58Z                                                   |
+------------------------------------------------------------------------------+
|                                                                              |
INFO[07:16:58]  * [OK] Step dependency (xcode) installed, available. 
INFO[07:16:58]  * [OK] Step dependency (go) installed, available. 
Config:
- ProjectPath: ./ios-app/iosApp.xcworkspace
- Scheme: iosApp
- Configuration: 
- ArtifactName: 
- XcodebuildOptions: 
- Workdir: /Users/vagrant/git
- OutputDir: /Users/vagrant/deploy
- IsCleanBuild: false
- OutputTool: xcpretty
- SimulatorDevice: iPhone 8 Plus
- SimulatorOsVersion: latest
- SimulatorPlatform: iOS
- DisableIndexWhileBuilding: true
- VerboseLog: false
- CacheLevel: swift_packages
Step determined configs:
- xcodebuildVersion: Xcode 13.2.1 (Build version 13C100)
Checking if output tool (xcpretty) is installed
- xcprettyVersion: 0.3.0
Simulator info
Latest simulator for iPhone 8 Plus = 50FED432-F33B-4264-921C-EA587D44271C
Running build
[07:17:07] $ set -o pipefail && xcodebuild "-workspace" "/Users/vagrant/git/ios-app/iosApp.xcworkspace" "-scheme" "iosApp" "-configuration" "Release" "CODE_SIGNING_ALLOWED=NO" "-destination" "id=50FED432-F33B-4264-921C-EA587D44271C" "COMPILER_INDEX_STORE_ENABLE=NO" "build" | xcpretty
▸ Running script '[CP-User] Build shared'
160 Views