<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Mick F</title><description>Notes for myself and fellow programmers, with a focus on iOS, Swift and web frontend development. Since 2009.</description><link>https://www.mickf.net/tech/</link><item><title>xcrun simctl list devices: Picking a Simulator for CI</title><link>https://www.mickf.net/tech/finding-ios-simulators-identifiers/</link><guid isPermaLink="true">https://www.mickf.net/tech/finding-ios-simulators-identifiers/</guid><description>&quot;Tests must be run on a concrete device&quot;: xcodebuild test on CI needs a simulator ID. Three ways to get one: Fastlane, Point-Free, and a Swift script.</description><pubDate>Fri, 29 Mar 2024 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;GitHub Actions are powerful tools and a great complement to Xcode Cloud for
Swift projects’ continuous integration.&lt;/p&gt;
&lt;p&gt;However, I encountered an issue: when using &lt;code&gt;xcodebuild test&lt;/code&gt; for iOS, a
&lt;em&gt;concrete device&lt;/em&gt; is required:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sh&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;Cannot&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; test&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; “FooTests”&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; “Any&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; iOS&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; Device”:&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; Tests&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; must&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; be&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; run&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; concrete&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; device&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The challenge then arose: how to identify the simulator identifiers suitable for
the intended device?&lt;/p&gt;
&lt;p&gt;Of course, Apple provides a command for this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sh&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;xcrun&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; simctl&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; list&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; devices&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; available&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;But then CI requires parsing and filtering on this command’s output. Here are 3
solutions to do so.&lt;/p&gt;
&lt;h2 id=&quot;fastlane-era&quot;&gt;Fastlane era&lt;/h2&gt;
&lt;p&gt;Fastlane provides a &lt;code&gt;FastlaneCore::DeviceManager&lt;/code&gt; that greatly assists in
inspecting available devices.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ruby&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;require&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &apos;fastlane_core/device_manager&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Usage: latest_simulator_with_name(&apos;iPhone Xʀ&apos;).udid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; latest_simulator_with_name&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(device_name)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FFAB70&quot;&gt;  result&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;    FastlaneCore&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;DeviceManager&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;simulators&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;                               .&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;select&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; { |s| s.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt; ==&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; device_name }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;                               .&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;max_by&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; { |s| &lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;Gem&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;Version&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;create&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;(s.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;os_version&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;) }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;  return&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; result &lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;unless&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; result.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;nil?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;  FastlaneCore&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;UI&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;error&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;#{device_name}&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; missing. Please select one of the following:&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;  FastlaneCore&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;DeviceManager&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;simulators&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;                             .&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;each&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; { |s| &lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;FastlaneCore&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;UI&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;message&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;#{s.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;name&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;#{s.&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;os_version&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;)&quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;  raise&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;Device with name &lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;#{device_name}&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; cannot be found. Please install it.&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Despite my extensive use of Fastlane, I’m starting to perceive a decline in its
relevance with the emergence of Xcode Cloud.&lt;/p&gt;
&lt;h2 id=&quot;exploring-the-point-free-approach&quot;&gt;Exploring the Point-Free Approach&lt;/h2&gt;
&lt;p&gt;As an admirer of the Point-Free team’s work, I investigated their methods and
discovered &lt;a href=&quot;https://github.com/pointfreeco/swift-composable-architecture/blob/2722a3466b78860ebf493103fc82ac85b076e1bd/Makefile&quot;&gt;a useful yet succinct shell command&lt;/a&gt;.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;makefile&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;PLATFORM_IOS = iOS Simulator,id=&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;call&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; udid_for,iOS 17.2,iPhone \d\+ Pro [^M])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; udid_for&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;shell&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; xcrun simctl list devices available &apos;$(&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;)&apos; | grep &apos;$(&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;)&apos; | sort -r | head -1 | awk -F &apos;[()]&apos; &apos;{ print &lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;$$&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;(NF-3) }&apos;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;endef&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;While efficient, it lacks readability.&lt;/p&gt;
&lt;h2 id=&quot;implementing-a-swift-solution&quot;&gt;Implementing a Swift Solution&lt;/h2&gt;
&lt;p&gt;To address this challenge, I developed a Swift script to obtain the necessary
information. You can find &lt;a href=&quot;https://github.com/dirtyhenry/swift-blocks/blob/main/Scripts/ListDevices.swift&quot;&gt;the script on the Scripts section of my Blocks
project&lt;/a&gt; or as &lt;a href=&quot;https://github.com/dirtyhenry/swift-blocks/blob/main/Examples/BlocksCLI/Sources/BlocksCLI/DevTools/ListDevicesCommand.swift&quot;&gt;a command of the CLI&lt;/a&gt; that I provide with this tool.&lt;/p&gt;
&lt;p&gt;To use it in continuous integration (CI), follow these steps:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; style=&quot;background-color:#24292e;color:#e1e4e8; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Download the script and make it executable&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;curl&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -sSL&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; https://raw.githubusercontent.com/dirtyhenry/swift-blocks/main/Scripts/ListDevices.swift&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;  -o&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; findDevice&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;chmod&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; +x&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; findDevice&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Find the device identifier&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;DEVICE_ID&lt;/span&gt;&lt;span style=&quot;color:#F97583&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$(&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;./findDevice&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$TEST_IOS_VERSION&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$TEST_IOS_SIMULATOR_MODEL&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6A737D&quot;&gt;# Run the test&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;set&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -o&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; pipefail&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt; &amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt;xcodebuild&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; test&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;    -skipMacroValidation&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; -skipPackagePluginValidation&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;    -workspace&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; foo.xcworkspace&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;    -scheme&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; &quot;bar&quot;&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt;    -destination&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt; platform=&quot;iOS Simulator,id=&lt;/span&gt;&lt;span style=&quot;color:#E1E4E8&quot;&gt;$DEVICE_ID&lt;/span&gt;&lt;span style=&quot;color:#9ECBFF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#79B8FF&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F97583&quot;&gt;    |&lt;/span&gt;&lt;span style=&quot;color:#B392F0&quot;&gt; xcpretty&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;💡 I recommend setting &lt;code&gt;TEST_IOS_VERSION&lt;/code&gt; and &lt;code&gt;TEST_IOS_SIMULATOR_MODEL&lt;/code&gt; as
environment variables so that failures after Xcode updates can be resolved
without changing the code.&lt;/p&gt;
</content:encoded><category>iOS</category><category>GitHub Actions</category><category>Continuous integration</category><category>Open Source</category></item></channel></rss>