我有一個簡單的 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 devices并使用其中一個,但它仍然說同樣的話。
uj5u.com熱心網友回復:
經過數小時的嘗試,我找到了真正的問題和解決方案。
我嘗試使用fastlane. 推送到 repo 后,我發現實際問題出在部署目標上。我的專案的部署目標是,iOS 15.4但 Github 操作支持的最新版本是15.2. 這就是為什么我無法構建我的專案。
然后我更改了腳本并包含了目的地和瞧的作業系統版本。這是腳本中的更新行:
xcodebuild build-for-testing -scheme "$scheme" -"$filetype_parameter" "$file_to_build" -destination "platform=$platform,OS=15.2,name=$device"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/492056.html
上一篇:如何禁用xcode除錯選項卡?
