无法使用GitHub动作构建iOS项目
我有一个简单的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
经过数小时的尝试,我找到了真正的问题和解决方案。
我尝试使用
Fastlane
运行单元测试。推到仓库后,我发现实际问题是关于部署目标的。我项目的部署目标是iOS 15.4
,但GitHub Actions支持的最新版本是15.2
。这就是为什么我无法构建项目的原因。然后,我更改了脚本,并包括了目标和Voila的OS版本。
这是脚本中的更新行:
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 wasiOS 15.4
but the latest version that the Github actions supports is15.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: