Skip to content

Commit 99222a8

Browse files
committed
Refactored to also output platform
1 parent 3de79c2 commit 99222a8

4 files changed

Lines changed: 58 additions & 41 deletions

File tree

action.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ inputs:
2424
required: false
2525

2626
outputs:
27-
id:
27+
destination-platform:
28+
description: "Platform"
29+
value: ${{ steps.parse-inputs.outputs.parsed-platform }}
30+
destination-id:
2831
description: "Simulator ID"
2932
value: ${{ steps.id-finder.outputs.id }}
3033

@@ -52,6 +55,7 @@ runs:
5255
# parsed-workspace-path
5356
# parsed-scheme
5457
# parsed-platform
58+
# parsed-platform-short
5559
# parsed-platform-regex
5660
# parsed-device-regex
5761
# parsed-os-version-regex
@@ -62,7 +66,7 @@ runs:
6266
if: inputs.download == 'true'
6367
env:
6468
GITHUB_ACTION_PATH: ${{ github.action_path }}
65-
SIMPLATFORM: ${{ steps.parse-inputs.outputs.parsed-platform }}
69+
SIMPLATFORM_SHORT: ${{ steps.parse-inputs.outputs.parsed-platform-short }}
6670

6771
- name: Find Simulator ID
6872
id: id-finder
@@ -73,9 +77,13 @@ runs:
7377
WORKSPACEPATH: ${{ steps.parse-inputs.outputs.parsed-workspace-path }}
7478
SCHEME: ${{ steps.parse-inputs.outputs.parsed-scheme }}
7579
SIMPLATFORM: ${{ steps.parse-inputs.outputs.parsed-platform }}
80+
SIMPLATFORM_SHORT: ${{ steps.parse-inputs.outputs.parsed-platform-short }}
7681
SIMPLATFORM_REGEX: ${{ steps.parse-inputs.outputs.parsed-platform-regex }}
7782
SIMDEVICE_REGEX: ${{ steps.parse-inputs.outputs.parsed-device-regex }}
7883
OSVERSION_REGEX: ${{ steps.parse-inputs.outputs.parsed-os-version-regex }}
84+
# outputs:
85+
# destination-platform
86+
# destination-id
7987

8088
branding:
8189
icon: 'code'

scripts/download.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
# see https://github.com/actions/runner-images/issues/12758#issuecomment-3206748945
55

66
# Inputs:
7-
# - SIMPLATFORM required
7+
# - SIMPLATFORM_SHORT required
88

99
# Step outputs produced:
1010
# (none)
1111

1212
echo "Downloading simulator if needed..."
1313

1414
# Capture output so it doesn't spam the console. In future this can optionally be printed to the console.
15-
LOG=$(xcodebuild -downloadPlatform "$SIMPLATFORM")
15+
LOG=$(xcodebuild -downloadPlatform "$SIMPLATFORM_SHORT")
1616

1717
echo "Done downloading simulator."

scripts/id.sh

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@
1010
# - https://docs.github.com/en/actions/how-tos/create-and-publish-actions/set-exit-codes
1111

1212
# Inputs:
13-
# - WORKSPACEPATH optional
14-
# - SCHEME required
15-
# - SIMPLATFORM required
16-
# - SIMPLATFORM_REGEX required
17-
# - SIMDEVICE_REGEX required
18-
# - OSVERSION_REGEX optional
13+
# - WORKSPACEPATH optional
14+
# - SCHEME required
15+
# - SIMPLATFORM required
16+
# - SIMPLATFORM_SHORT required
17+
# - SIMPLATFORM_REGEX required
18+
# - SIMDEVICE_REGEX required
19+
# - OSVERSION_REGEX optional
1920

2021
# Step outputs produced:
21-
# - id
22+
# - destination-platform Platform string (ie: "iOS Simulator") which can be used verbatim in `xcodebuild destination="platform=X"` in place of X
23+
# - destination-id ID string (ie: "17FC425F-F336-48DC-8D5A-05DA7BCF7B7D") which can be used verbatim in `xcodebuild destination="id=X"` in place of X
2224

2325
# Note that validation of variables is skipped in this script, as validation already occurred
2426
# in the action step that runs parse-inputs.sh.
@@ -58,4 +60,5 @@ if [[ -z $DESTID ]]; then echo "⛔️ Error: No matching simulators available."
5860
echo "🟢 Found device simulator: $DESTDESC"
5961

6062
# Set output variable.
61-
echo "id=$(echo $DESTID)" >> $GITHUB_OUTPUT
63+
echo "destination-platform=$(echo $SIMPLATFORM)" >> $GITHUB_OUTPUT
64+
echo "destination-id=$(echo $DESTID)" >> $GITHUB_OUTPUT

scripts/parse-inputs.sh

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
# - INPUT_OSVERSION optional
88

99
# Step outputs produced:
10-
# - parsed-workspace-path
11-
# - parsed-scheme
12-
# - parsed-platform
13-
# - parsed-platform-regex
10+
# - parsed-workspace-path Relative path to .xcworkspace file from repo root
11+
# - parsed-scheme Xcode scheme name
12+
# - parsed-platform Platform string (ie: "iOS Simulator") which can be used verbatim in `xcodebuild destination="platform=X"` in place of X
13+
# - parsed-platform-short Platform short name (ie: "iOS")
14+
# - parsed-platform-regex Platform name regex used when parsing simulator list output from `xcodebuild -showdestinations``
1415
# - parsed-device-regex
1516
# - parsed-os-version-regex
1617

@@ -42,121 +43,121 @@ if [[ -n $OSVERSION_REGEX ]]; then echo "Using OS version regex: $OSVERSION_REGE
4243
INPUT_TARGET_LOWERCASE=$( tr '[:upper:]' '[:lower:]' <<<"$INPUT_TARGET" )
4344
case $INPUT_TARGET_LOWERCASE in
4445
ios)
45-
SIMPLATFORM="iOS"
46+
SIMPLATFORM_SHORT="iOS"
4647
SIMPLATFORM_REGEX="iOS"
4748
SIMDEVICE_REGEX="iPhone\s\d{2}\s"
4849
;;
4950

5051
tvos)
51-
SIMPLATFORM="tvOS"
52+
SIMPLATFORM_SHORT="tvOS"
5253
SIMPLATFORM_REGEX="tvOS"
5354
SIMDEVICE_REGEX="AppleTV"
5455
;;
5556

5657
watchos)
57-
SIMPLATFORM="watchOS"
58+
SIMPLATFORM_SHORT="watchOS"
5859
SIMPLATFORM_REGEX="watchOS"
5960
SIMDEVICE_REGEX="Apple\sWatch\sSeries"
6061
;;
6162

6263
visionos)
63-
SIMPLATFORM="visionOS"
64+
SIMPLATFORM_SHORT="visionOS"
6465
SIMPLATFORM_REGEX="visionOS"
6566
SIMDEVICE_REGEX="Apple\sVision\sPro"
6667
;;
6768

6869
iphone)
69-
SIMPLATFORM="iOS"
70+
SIMPLATFORM_SHORT="iOS"
7071
SIMPLATFORM_REGEX="iOS"
7172
SIMDEVICE_REGEX="iPhone\s\d{2}\s"
7273
;;
7374

7475
iphone-air)
75-
SIMPLATFORM="iOS"
76+
SIMPLATFORM_SHORT="iOS"
7677
SIMPLATFORM_REGEX="iOS"
7778
SIMDEVICE_REGEX="iPhone\sAir"
7879
;;
7980

8081
iphone-pro)
81-
SIMPLATFORM="iOS"
82+
SIMPLATFORM_SHORT="iOS"
8283
SIMPLATFORM_REGEX="iOS"
8384
SIMDEVICE_REGEX="iPhone\s\d{2}\sPro\s"
8485
;;
8586

8687
iphone-pro-max)
87-
SIMPLATFORM="iOS"
88+
SIMPLATFORM_SHORT="iOS"
8889
SIMPLATFORM_REGEX="iOS"
8990
SIMDEVICE_REGEX="iPhone\s\d{2}\sPro\sMax"
9091
;;
9192

9293
ipad)
93-
SIMPLATFORM="iOS"
94+
SIMPLATFORM_SHORT="iOS"
9495
SIMPLATFORM_REGEX="iOS"
9596
SIMDEVICE_REGEX="iPad\s"
9697
;;
9798

9899
ipad-air)
99-
SIMPLATFORM="iOS"
100+
SIMPLATFORM_SHORT="iOS"
100101
SIMPLATFORM_REGEX="iOS"
101102
SIMDEVICE_REGEX="iPad\sAir"
102103
;;
103104

104105
ipad-mini)
105-
SIMPLATFORM="iOS"
106+
SIMPLATFORM_SHORT="iOS"
106107
SIMPLATFORM_REGEX="iOS"
107108
SIMDEVICE_REGEX="iPad\smini"
108109
;;
109110

110111
ipad-pro)
111-
SIMPLATFORM="iOS"
112+
SIMPLATFORM_SHORT="iOS"
112113
SIMPLATFORM_REGEX="iOS"
113114
SIMDEVICE_REGEX="iPad\sPro"
114115
;;
115116

116117
tv)
117-
SIMPLATFORM="tvOS"
118+
SIMPLATFORM_SHORT="tvOS"
118119
SIMPLATFORM_REGEX="tvOS"
119120
SIMDEVICE_REGEX="Apple\sTV"
120121
;;
121122

122123
tv-4k)
123-
SIMPLATFORM="tvOS"
124+
SIMPLATFORM_SHORT="tvOS"
124125
SIMPLATFORM_REGEX="tvOS"
125126
SIMDEVICE_REGEX="Apple\sTV\s4K"
126127
;;
127128

128129
watch)
129-
SIMPLATFORM="watchOS"
130+
SIMPLATFORM_SHORT="watchOS"
130131
SIMPLATFORM_REGEX="watchOS"
131132
SIMDEVICE_REGEX="Apple\sWatch"
132133
;;
133134

134135
watch-se)
135-
SIMPLATFORM="watchOS"
136+
SIMPLATFORM_SHORT="watchOS"
136137
SIMPLATFORM_REGEX="watchOS"
137138
SIMDEVICE_REGEX="Apple\sWatch\sSE"
138139
;;
139140

140141
watch-series)
141-
SIMPLATFORM="watchOS"
142+
SIMPLATFORM_SHORT="watchOS"
142143
SIMPLATFORM_REGEX="watchOS"
143144
SIMDEVICE_REGEX="Apple\sWatch\sSeries"
144145
;;
145146

146147
watch-ultra)
147-
SIMPLATFORM="watchOS"
148+
SIMPLATFORM_SHORT="watchOS"
148149
SIMPLATFORM_REGEX="watchOS"
149150
SIMDEVICE_REGEX="Apple\sWatch\sUltra"
150151
;;
151152

152153
visionpro)
153-
SIMPLATFORM="visionOS"
154+
SIMPLATFORM_SHORT="visionOS"
154155
SIMPLATFORM_REGEX="visionOS"
155156
SIMDEVICE_REGEX="Apple\sVision\sPro"
156157
;;
157158

158159
visionpro-4k)
159-
SIMPLATFORM="visionOS"
160+
SIMPLATFORM_SHORT="visionOS"
160161
SIMPLATFORM_REGEX="visionOS"
161162
SIMDEVICE_REGEX="Apple\sVision\sPro\s4K"
162163
;;
@@ -175,29 +176,34 @@ case $INPUT_TARGET_LOWERCASE in
175176
XCODE_OUTPUT_REGEX="m/\{\splatform:(.*\sSimulator),.*id:([A-F0-9\-]{36}),.*OS:(\d{1,2}\.\d),.*name:([a-zA-Z0-9\(\)\s]*)\s\}/g"
176177

177178
# Parse out platform name from first sorted result.
178-
SIMPLATFORM=$(echo "${XCODE_OUTPUT}" | perl -nle 'if ('$XCODE_OUTPUT_REGEX') { ($plat, $id, $os, $name) = ($1, $2, $3, $4); if ($name =~ /'$SIMDEVICE_REGEX'/) { print "${plat}"; } }' | sort -rV | head -n 1)
179+
SIMPLATFORM_SHORT=$(echo "${XCODE_OUTPUT}" | perl -nle 'if ('$XCODE_OUTPUT_REGEX') { ($plat, $id, $os, $name) = ($1, $2, $3, $4); if ($name =~ /'$SIMDEVICE_REGEX'/) { print "${plat}"; } }' | sort -rV | head -n 1)
179180

180-
if [[ -n $SIMPLATFORM ]]; then
181+
if [[ -n $SIMPLATFORM_SHORT ]]; then
181182
# Copy to regex as-is
182-
SIMPLATFORM_REGEX="$SIMPLATFORM"
183+
SIMPLATFORM_REGEX="$SIMPLATFORM_SHORT"
183184
else
184185
# If no platform is found, substitute with a pass-thru regex.
185186
# This should probably exit with an error code, but being more permissive may be useful.
186-
SIMPLATFORM="Unknown"
187+
SIMPLATFORM_SHORT="Unknown"
187188
SIMPLATFORM_REGEX=".*"
188189
fi
189190
;;
190191
esac
191192

193+
# Short Platform
194+
SIMPLATFORM="$SIMPLATFORM_SHORT Simulator"
195+
192196
# Provide diagnostic output of platform and device regex strings.
193-
echo "Using platform: $SIMPLATFORM"
197+
echo "Using platform name: $SIMPLATFORM"
198+
echo "Using platform name (short): $SIMPLATFORM_SHORT"
194199
echo "Using platform name regex: $SIMPLATFORM_REGEX"
195200
echo "Using device name regex: $SIMDEVICE_REGEX"
196201

197202
# Set output variables.
198203
echo "parsed-workspace-path=$(echo $WORKSPACEPATH)" >> $GITHUB_OUTPUT
199204
echo "parsed-scheme=$(echo $SCHEME)" >> $GITHUB_OUTPUT
200205
echo "parsed-platform=$(echo $SIMPLATFORM)" >> $GITHUB_OUTPUT
206+
echo "parsed-platform-short=$(echo $SIMPLATFORM_SHORT)" >> $GITHUB_OUTPUT
201207
echo "parsed-platform-regex=$(echo $SIMPLATFORM_REGEX)" >> $GITHUB_OUTPUT
202208
echo "parsed-device-regex=$(echo $SIMDEVICE_REGEX)" >> $GITHUB_OUTPUT
203209
echo "parsed-os-version-regex=$(echo $OSVERSION_REGEX)" >> $GITHUB_OUTPUT

0 commit comments

Comments
 (0)