无法使用GitHub动作构建iOS项目

发布于 2025-02-06 16:02:58 字数 3415 浏览 1 评论 0原文

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

我想整合CI/CD的GitHub动作。

这是我的工作流脚本:

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设备并使用其中之一的可用设备列表,但仍然说相同的话。

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

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\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

"; 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\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

" ]; then filetype_parameter="workspace" && file_to_build="`ls -A | grep -i \\.xcworkspace\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

"; else filetype_parameter="project" && file_to_build="`ls -A | grep -i \\.xcodeproj\

I have a simple iOS project (just a new project created with Xcode) that I can build and test locally.

I want to integrate Github actions for CI/CD.

Here is my workflow script:

"; 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"

The problem is that the action fails at the build step and complains about the destination.

here is the output:

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.

I tried to change the destination, but no matter what device I try to use, it gives the exact same error every time.

I can run the exact same command on my local machine and it builds the project without any issue.

I even tried getting a list of available devices with xcrun xctrace list devices and using one of them, but it still says the same thing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为你拒绝所有暧昧 2025-02-13 16:02:58

经过数小时的尝试,我找到了真正的问题和解决方案。

我尝试使用Fastlane运行单元测试。推到仓库后,我发现实际问题是关于部署目标的。我项目的部署目标是iOS 15.4,但GitHub Actions支持的最新版本是15.2。这就是为什么我无法构建项目的原因。

然后,我更改了脚本,并包括了目标和Voila的OS版本。
这是脚本中的更新行:

xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,OS=15.2,name=$device"

After hours of trying everything, I found the real issue and the solution.

I tried running unit tests using fastlane. after pushing to the repo, I found out that the actual problem was about the deployment target. The deployment target for my project was iOS 15.4 but the latest version that the Github actions supports is 15.2. that's why I couldn't build my project.

Then I changed the script and included the OS version for destination and Voila.
Here's the updated line in the script:

xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,OS=15.2,name=$device"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文