-
-
Notifications
You must be signed in to change notification settings - Fork 230
ci: fix iOS Device Tests #4447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
ci: fix iOS Device Tests #4447
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3caf453
ci: bump XHarness
Flash0ver f39767f
ci: iOS Device Tests download Xcode platform tools
Flash0ver a247909
ci: remove unsupported option
Flash0ver e43c7b2
ci: iOS Device Tests install Xcode platform tools
Flash0ver 19c0cc7
ci: sudo
Flash0ver 787e45a
Force the tests to run on a specific device (matching desired iOS ver…
jamescrosswell 29ec25b
Refactor into a separate module/function
jamescrosswell 0d8d9ba
Update device-tests-ios.yml
jamescrosswell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| function Get-IosSimulatorUdid { | ||
| [CmdletBinding()] | ||
| param( | ||
| [string]$IosVersion = '18.5', | ||
| [string[]]$PreferredDeviceTypes = @( | ||
| 'com.apple.CoreSimulator.SimDeviceType.iPhone-XS', | ||
| 'com.apple.CoreSimulator.SimDeviceType.iPhone-16', | ||
| 'com.apple.CoreSimulator.SimDeviceType.iPhone-15' | ||
| ) | ||
| ) | ||
|
|
||
| try { | ||
| $simDevices = & xcrun simctl list devices --json | ConvertFrom-Json | ||
| } catch { | ||
| Write-Verbose "Failed to query simctl: $($_.Exception.Message)" | ||
| return $null | ||
| } | ||
| if (-not $simDevices -or -not $simDevices.devices) { | ||
| Write-Verbose "No devices structure returned." | ||
| return $null | ||
| } | ||
|
|
||
| $devicesByRuntime = $simDevices.devices | ||
| $preferredIndex = @{} | ||
| for ($i = 0; $i -lt $PreferredDeviceTypes.Count; $i++) { | ||
| $preferredIndex[$PreferredDeviceTypes[$i]] = $i | ||
| } | ||
|
|
||
| $dashVer = $IosVersion -replace '\.','-' | ||
| $exactKey = "com.apple.CoreSimulator.SimRuntime.iOS-$dashVer" | ||
| $runtimeKey = $null | ||
|
|
||
| $allRuntimeNames = $devicesByRuntime.PSObject.Properties.Name | ||
| if ($allRuntimeNames -contains $exactKey) { | ||
| $runtimeKey = $exactKey | ||
| Write-Verbose "Found exact runtime: $runtimeKey" | ||
| } else { | ||
| $major = ($IosVersion.Split('.')[0]) | ||
| $candidates = $allRuntimeNames | Where-Object { $_ -match "com\.apple\.CoreSimulator\.SimRuntime\.iOS-$major-" } | ||
| if ($candidates) { | ||
| $runtimeKey = $candidates | | ||
| Sort-Object { | ||
| $v = ($_ -replace '.*iOS-','') -replace '-','.' | ||
| try { [Version]$v } catch { [Version]'0.0' } | ||
| } -Descending | | ||
| Select-Object -First 1 | ||
| Write-Verbose "Exact runtime $exactKey not found. Using fallback runtime $runtimeKey" | ||
| } else { | ||
| Write-Verbose "No simulator runtime found for iOS major $major" | ||
| return $null | ||
| } | ||
| } | ||
|
|
||
| $runtimeDevices = $devicesByRuntime.PSObject.Properties | | ||
| Where-Object { $_.Name -eq $runtimeKey } | | ||
| Select-Object -ExpandProperty Value | ||
|
|
||
| if (-not $runtimeDevices) { | ||
| Write-Verbose "Runtime key $runtimeKey present but no devices listed." | ||
| return $null | ||
| } | ||
|
|
||
| $usable = $runtimeDevices | Where-Object { $_.isAvailable -and $_.state -in @('Shutdown','Booted') } | ||
| if (-not $usable) { | ||
| Write-Verbose "No available devices in runtime $runtimeKey" | ||
| return $null | ||
| } | ||
|
|
||
| $ranked = $usable | ForEach-Object { | ||
| $dt = $_.deviceTypeIdentifier | ||
| $weightPref = if ($preferredIndex.ContainsKey($dt)) { $preferredIndex[$dt] } else { 9999 } | ||
| $weightFamily = if ($dt -match 'iPhone') { 0 } else { 1 } # prefer iPhone if not explicitly listed | ||
| [PSCustomObject]@{ | ||
| Device = $_ | ||
| WeightPref = $weightPref | ||
| WeightFamily = $weightFamily | ||
| WeightBoot = if ($_.state -eq 'Booted') { 0 } else { 1 } | ||
| SortName = $_.name | ||
| } | ||
| } | ||
|
|
||
| $sorted = $ranked | Sort-Object WeightPref, WeightFamily, WeightBoot, SortName | ||
| $sorted | Select-Object -First 5 | ForEach-Object { | ||
| Write-Verbose ("Candidate: {0} | {1} | pref={2} fam={3} bootW={4}" -f $_.Device.name, $_.Device.deviceTypeIdentifier, $_.WeightPref, $_.WeightFamily, $_.WeightBoot) | ||
| } | ||
|
|
||
| $selected = $sorted | Select-Object -First 1 | ||
| if (-not $selected) { | ||
| Write-Verbose "Failed to select a simulator." | ||
| return $null | ||
| } | ||
|
|
||
| Write-Verbose ("Selected simulator: {0} ({1}) [{2}]" -f $selected.Device.name, $selected.Device.deviceTypeIdentifier, $selected.Device.udid) | ||
| return $selected.Device.udid | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: diff
https://github.com/dotnet/xharness/commits/main/?since=2025-06-30&until=2025-08-12