Skip to content

Commit 83c10a0

Browse files
authored
CI: fix create_simulators dedup logic (#483)
1 parent aa15494 commit 83c10a0

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

fastlane/Fastfile

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ skip_docs
22

33
devices = {
44
"ios" => {
5-
15 => ["iPhone SE (3rd generation) (15.5)", "iPad Air (5th generation) (15.5)",],
5+
15 => ["iPhone 13 Pro (15.5)", "iPad Pro (11-inch) (3rd generation) (15.5)",],
66
16 => ["iPhone 14 Pro (16.4)", "iPad Pro (11-inch) (4th generation) (16.4)"],
77
17 => ["iPhone 15 Pro (17.5)", "iPad Pro 11-inch (M4) (17.5)"],
88
18 => ["iPhone 16 Pro (18.6)", "iPad Pro 11-inch (M4) (18.6)"],
@@ -48,20 +48,27 @@ lane :create_simulators do |options|
4848

4949
# Build lookup tables from CoreSimulator for robust name→identifier mapping
5050
begin
51+
# Build a set of existing simulator name+runtime pairs to prevent duplicates across OS versions
52+
devices_json = sh("xcrun simctl list -j devices", log: false)
53+
devices_list = JSON.parse(devices_json)
54+
existing_pairs = Set.new
55+
(devices_list["devices"] || {}).each do |runtime_key, arr|
56+
Array(arr).each do |d|
57+
name = d["name"]
58+
next unless name && runtime_key
59+
existing_pairs.add("#{name}||#{runtime_key}")
60+
end
61+
end
62+
5163
list_json = sh("xcrun simctl list -j", log: false)
5264
list = JSON.parse(list_json)
5365
devtypes = list["devicetypes"] || []
5466
runtimes = list["runtimes"] || []
55-
56-
# Build a set of existing simulator names to prevent duplicates
57-
devices_json = sh("xcrun simctl list -j devices", log: false)
58-
devices_list = JSON.parse(devices_json)
59-
existing_names = (devices_list["devices"] || {}).values.flatten.map { |d| d["name"] }.compact.to_set
6067
rescue => e
6168
UI.message("Failed to read simctl lists: #{e}")
6269
devtypes = []
6370
runtimes = []
64-
existing_names = Set.new
71+
existing_pairs = Set.new
6572
end
6673

6774
device_name_to_id = devtypes.each_with_object({}) do |dt, h|
@@ -126,13 +133,14 @@ lane :create_simulators do |options|
126133
# Use the device name without the version suffix as the simulator name
127134
sim_name = device_name
128135

129-
if existing_names.include?(sim_name)
136+
pair_key = "#{sim_name}||#{runtime_id}"
137+
if existing_pairs.include?(pair_key)
130138
UI.message("Already exists: #{sim_name} (#{runtime_version}), skipping")
131139
next
132140
end
133141

134142
sh(%(xcrun simctl create "#{sim_name}" "#{device_type_id}" "#{runtime_id}" || true))
135-
existing_names.add(sim_name)
143+
existing_pairs.add(pair_key)
136144
rescue => e
137145
UI.message("Skipping #{descriptor}: #{e}")
138146
end

0 commit comments

Comments
 (0)