如何在 GitHub 操作中修复 xcodebuild 的错误

How to fix error with xcodebuild in GitHub Actions

我正在尝试使用 GitHub 操作在 Github 中为我的私有 Swift 项目设置一个 CI。我使用了 Github 提供的标准 swift.yml 模板并做了一些修改。这是文件 ci.yml

name: Swift

on: [push]

jobs:
  build:

    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v1
    - name: Run tests
      run: xcodebuild -project 'MyApp.xcodeproj' -scheme 'MyApp' -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.2' clean test
    - name: Build App
      run: xcodebuild -project 'MyApp.xcodeproj' -scheme 'MyApp' -destination 'generic/platform=iOS' -configuration Release build CODE_SIGNING_ALLOWED=NO

当我将新构建推送到存储库时,操作会触发,但测试失败。

xcodebuild -project 'MyApp.xcodeproj' -scheme 'MyApp' -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=latest' clean test

我在本地 运行 并且所有测试都通过了。在 GitHub 操作中我遇到了这个错误

Set up job                  0s
Run actions/checkout@v1     2s
Run tests                   34s
    ##[error]Process completed with exit code 70.
1     Run xcodebuild -project 'MyApp.xcodeproj' -scheme 'MyApp' -destination 'platform=iOS Simulator,name=iPhone 11 Pro Max,OS=13.2' clean test
4        xcodebuild: error: Unable to find a destination matching the provided destination specifier:
5             { platform:iOS Simulator, OS:13.2, name:iPhone 11 Pro Max }
6
9        Ineligible destinations for the "MyApp" scheme:
10           { platform:iOS, id:dvtdevice-DVTiPhonePlaceholder-iphoneos:placeholder, name:Generic iOS Device }
11           { platform:iOS Simulator, id:dvtdevice-DVTiOSDeviceSimulatorPlaceholder-iphonesimulator:placeholder, name:Generic iOS Simulator Device }
12    ##[error]Process completed with exit code 70.
Build App                   0s
Complete job

这个测试应该通过了。我不确定如何解决这个问题,让操作不再失败

我能够通过强制 Xcode 11 修复此错误。我使用以下代码使其工作。现在所有测试都通过了,一切正常。

name: Swift

on: [push]

jobs:
  build:

    runs-on: macOS-latest

    steps:
    - uses: actions/checkout@v1
    - name: Force Xcode 11
      run: sudo xcode-select -switch /Applications/Xcode_11.3.app
    - name: Run tests
      run: xcodebuild clean test -project "MyApp.xcodeproj" -scheme "MyApp" -destination "platform=iOS Simulator,name=iPhone 11 Pro Max,OS=latest"
    - name: Build App
      run: xcodebuild -project "MyApp.xcodeproj" -scheme "MyApp" -destination "generic/platform=iOS" -configuration Release build CODE_SIGNING_ALLOWED=NO