无法使用 Github actions 构建 iOS 项目。

4

我有一个简单的iOS项目(只是使用Xcode创建的新项目),我可以在本地构建和测试。

我想集成Github actions进行CI/CD。

以下是我的工作流脚本:

name: iOS starter workflow

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

jobs:
  build:
    name: Build and Test default scheme using any available iPhone simulator
    runs-on: macos-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v3
      - name: Set Default Scheme
        run: |
          scheme_list=$(xcodebuild -list -json | tr -d "\n")
          default=$(echo $scheme_list | ruby -e "require 'json'; puts JSON.parse(STDIN.gets)['project']['targets'][0]")
          echo $default | cat >default
          echo Using default scheme: $default
      - name: Build
        env:
          scheme: ${{ 'default' }}
          platform: ${{ 'iOS Simulator' }}
        run: |
          # xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
          device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
          if [ $scheme = default ]; then scheme=$(cat default); fi
          if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
          file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
          xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"
      - name: Test
        env:
          scheme: ${{ 'default' }}
          platform: ${{ 'iOS Simulator' }}
        run: |
          # xcrun xctrace returns via stderr, not the expected stdout (see https://developer.apple.com/forums/thread/663959)
          device=`xcrun xctrace list devices 2>&1 | grep -oE 'iPhone.*?[^\(]+' | head -1 | awk '{$1=$1;print}' | sed -e "s/ Simulator$//"`
          if [ $scheme = default ]; then scheme=$(cat default); fi
          if [ "`ls -A | grep -i \\.xcworkspace\$`" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\$`"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\$`"; fi
          file_to_build=`echo $file_to_build | awk '{$1=$1;print}'`
          xcodebuild test-without-building -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,name=$device"


问题在于构建步骤中的操作失败,并抱怨目标位置。
以下是输出内容:
xcodebuild: error: Unable to find a destination matching the provided destination specifier:
        { platform:iOS Simulator, OS:latest, name:'iPhone 11' }
    The requested device could not be found because no available devices matched the request.
    Ineligible destinations for the "HelloActions" scheme:
        { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Any iOS Device }
        { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Any iOS Simulator Device }
Error: Process completed with exit code 70.

我尝试更改目标,但无论我使用什么设备,每次都会出现完全相同的错误。

在我的本地机器上运行完全相同的命令时,可以构建项目而不会出现任何问题。

我甚至尝试使用 xcrun xctrace list devices 获取可用设备列表并使用其中一个,但仍然会显示相同的信息。

1个回答

2
经过多次尝试,我找到了真正的问题及其解决方法。
我使用了fastlane来运行单元测试。在将其推送至代码库后,我发现实际问题与部署目标有关。我的项目的部署目标是iOS 15.4,但Github actions支持的最新版本为15.2。这就是为什么我无法构建项目的原因。
然后,我更改了脚本,并包含了用于目标环境的操作系统版本。更新后的脚本如下:
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,OS=15.2,name=$device"

有没有任何链接可以帮助找到 Github Actions 支持的最新操作系统版本?谢谢。 - Hongbo Miao
1
@HongboMiao,您可以在此处查看可用版本:https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners - Mohammad Rahchamani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接