-
Notifications
You must be signed in to change notification settings - Fork 4
332 lines (306 loc) · 13 KB
/
Copy pathtestflight.yml
File metadata and controls
332 lines (306 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
name: iOS TestFlight
on:
workflow_dispatch:
inputs:
configure_app:
description: Register/update the App Store Connect app, beta group, and testers before uploading.
required: true
default: true
type: boolean
upload_build:
description: Build and upload an iOS archive to TestFlight.
required: true
default: true
type: boolean
build_number:
description: Optional CFBundleVersion. Defaults to the GitHub run number.
required: false
type: string
permissions:
contents: read
jobs:
ios-testflight:
name: Register Garyx iOS and upload TestFlight build
runs-on: macos-26
env:
GARYX_APP_NAME: ${{ vars.GARYX_APP_NAME || 'Garyx' }}
GARYX_APP_SKU: ${{ vars.GARYX_APP_SKU || 'garyx-ios' }}
IOS_BUNDLE_ID: ${{ vars.IOS_BUNDLE_ID || 'com.garyx.mobile' }}
IOS_WIDGET_BUNDLE_ID: ${{ vars.IOS_WIDGET_BUNDLE_ID || 'com.garyx.mobile.RecentThreadsWidget' }}
IOS_APP_GROUP_ID: ${{ vars.IOS_APP_GROUP_ID || 'group.com.garyx.mobile' }}
TESTFLIGHT_GROUP_NAME: ${{ vars.TESTFLIGHT_GROUP_NAME || 'Garyx Experimental' }}
TESTFLIGHT_TESTER_EMAILS: ${{ secrets.TESTFLIGHT_TESTER_EMAILS }}
APPLE_TEAM_ID: ${{ secrets.APPLE_TEAM_ID }}
APP_STORE_CONNECT_API_KEY_ID: ${{ secrets.APP_STORE_CONNECT_API_KEY_ID }}
APP_STORE_CONNECT_API_ISSUER_ID: ${{ secrets.APP_STORE_CONNECT_API_ISSUER_ID }}
APP_STORE_CONNECT_API_KEY_P8: ${{ secrets.APP_STORE_CONNECT_API_KEY_P8 }}
IOS_DISTRIBUTION_CERTIFICATE_P12_BASE64: ${{ secrets.IOS_DISTRIBUTION_CERTIFICATE_P12_BASE64 }}
IOS_DISTRIBUTION_CERTIFICATE_PASSWORD: ${{ secrets.IOS_DISTRIBUTION_CERTIFICATE_PASSWORD }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Check required TestFlight secrets
shell: bash
run: |
set -euo pipefail
missing=()
for name in \
APPLE_TEAM_ID \
APP_STORE_CONNECT_API_KEY_ID \
APP_STORE_CONNECT_API_ISSUER_ID \
APP_STORE_CONNECT_API_KEY_P8; do
if [[ -z "${!name:-}" ]]; then
missing+=("$name")
fi
done
if [[ "${{ inputs.upload_build }}" == "true" ]]; then
for name in \
IOS_DISTRIBUTION_CERTIFICATE_P12_BASE64 \
IOS_DISTRIBUTION_CERTIFICATE_PASSWORD; do
if [[ -z "${!name:-}" ]]; then
missing+=("$name")
fi
done
fi
if (( ${#missing[@]} > 0 )); then
printf 'Missing required GitHub secret(s): %s\n' "${missing[*]}" >&2
exit 1
fi
- name: Write App Store Connect API key
shell: bash
run: |
set -euo pipefail
key_dir="$RUNNER_TEMP/appstoreconnect"
mkdir -p "$key_dir" "$HOME/.appstoreconnect/private_keys"
key_path="$key_dir/AuthKey_${APP_STORE_CONNECT_API_KEY_ID}.p8"
printf '%s' "$APP_STORE_CONNECT_API_KEY_P8" > "$key_path"
python3 - "$key_path" <<'PY'
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
text = path.read_text()
if "\\n" in text and "-----BEGIN" in text and "\n" not in text.strip().split("-----BEGIN", 1)[1]:
text = text.replace("\\n", "\n")
path.write_text(text)
PY
chmod 600 "$key_path"
cp "$key_path" "$HOME/.appstoreconnect/private_keys/"
echo "APP_STORE_CONNECT_API_KEY_PATH=$key_path" >> "$GITHUB_ENV"
- name: Register App Store Connect app and TestFlight testers
if: inputs.configure_app
shell: bash
run: node scripts/appstore-connect/setup-testflight.mjs
- name: Resolve build number
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
build_number="${{ inputs.build_number }}"
if [[ -z "$build_number" ]]; then
build_number="${GITHUB_RUN_NUMBER}"
fi
echo "GARYX_IOS_BUILD_NUMBER=$build_number" >> "$GITHUB_ENV"
- name: Install iOS signing assets
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
signing_dir="$RUNNER_TEMP/ios-signing"
mkdir -p "$signing_dir"
certificate_path="$signing_dir/distribution.p12"
keychain_path="$signing_dir/app-signing.keychain-db"
keychain_password="$(openssl rand -base64 24)"
SIGNING_CERTIFICATE_P12_PATH="$certificate_path" \
python3 - <<'PY'
import base64
import os
from pathlib import Path
Path(os.environ["SIGNING_CERTIFICATE_P12_PATH"]).write_bytes(
base64.b64decode(os.environ["IOS_DISTRIBUTION_CERTIFICATE_P12_BASE64"])
)
PY
chmod 600 "$certificate_path"
security create-keychain -p "$keychain_password" "$keychain_path"
security set-keychain-settings -lut 21600 "$keychain_path"
security unlock-keychain -p "$keychain_password" "$keychain_path"
security import "$certificate_path" \
-P "$IOS_DISTRIBUTION_CERTIFICATE_PASSWORD" \
-A \
-t cert \
-f pkcs12 \
-k "$keychain_path"
security list-keychains -d user -s "$keychain_path"
security default-keychain -d user -s "$keychain_path"
security set-key-partition-list \
-S apple-tool:,apple:,codesign: \
-s \
-k "$keychain_password" \
"$keychain_path"
certificate_pem="$signing_dir/distribution.pem"
security find-certificate -p "$keychain_path" > "$certificate_pem"
certificate_serial="$(
openssl x509 -in "$certificate_pem" -noout -serial |
cut -d= -f2 |
tr -d '[:space:]'
)"
if [[ -z "$certificate_serial" ]]; then
echo "Could not read the imported distribution certificate serial." >&2
exit 1
fi
echo "::add-mask::$certificate_serial"
echo "SIGNING_KEYCHAIN_PATH=$keychain_path" >> "$GITHUB_ENV"
echo "IOS_DISTRIBUTION_CERTIFICATE_SERIAL=$certificate_serial" >> "$GITHUB_ENV"
- name: Create and install App Store provisioning profiles
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
profile_dir="$HOME/Library/MobileDevice/Provisioning Profiles"
mkdir -p "$profile_dir"
IOS_PROFILE_INSTALL_DIR="$profile_dir" \
node scripts/appstore-connect/prepare-ios-profiles.mjs
- name: Validate App Store provisioning profiles
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
validate_profile() {
local label="$1"
local profile_path="$2"
local bundle_id="$3"
local plist_path="$RUNNER_TEMP/${label}-profile.plist"
security cms -D -i "$profile_path" > "$plist_path"
local app_identifier
app_identifier="$(/usr/libexec/PlistBuddy -c 'Print :Entitlements:application-identifier' "$plist_path")"
if [[ "$app_identifier" != *".$bundle_id" ]]; then
echo "$label profile has app identifier '$app_identifier', expected bundle '$bundle_id'." >&2
exit 1
fi
local app_group
app_group="$(/usr/libexec/PlistBuddy -c 'Print :Entitlements:com.apple.security.application-groups:0' "$plist_path" 2>/dev/null || true)"
if [[ "$app_group" != "$IOS_APP_GROUP_ID" ]]; then
echo "$label profile does not include expected App Group '$IOS_APP_GROUP_ID'." >&2
exit 1
fi
}
validate_profile "app" "$IOS_APP_PROVISIONING_PROFILE_PATH" "$IOS_BUNDLE_ID"
validate_profile "widget" "$IOS_WIDGET_PROVISIONING_PROFILE_PATH" "$IOS_WIDGET_BUNDLE_ID"
- name: Archive Garyx iOS app
if: inputs.upload_build
shell: bash
working-directory: mobile/garyx-mobile
run: |
set -euo pipefail
xcodebuild \
-project GaryxMobile.xcodeproj \
-scheme GaryxMobile \
-configuration Release \
-destination 'generic/platform=iOS' \
-archivePath "$RUNNER_TEMP/GaryxMobile.xcarchive" \
archive \
DEVELOPMENT_TEAM="$APPLE_TEAM_ID" \
CURRENT_PROJECT_VERSION="$GARYX_IOS_BUILD_NUMBER" \
CODE_SIGN_STYLE=Manual \
CODE_SIGN_IDENTITY="Apple Distribution" \
IOS_APP_PROVISIONING_PROFILE_SPECIFIER="$IOS_APP_PROVISIONING_PROFILE_SPECIFIER" \
IOS_WIDGET_PROVISIONING_PROFILE_SPECIFIER="$IOS_WIDGET_PROVISIONING_PROFILE_SPECIFIER" \
OTHER_CODE_SIGN_FLAGS="--keychain $SIGNING_KEYCHAIN_PATH"
- name: Verify archived app icon
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
apps_dir="$RUNNER_TEMP/GaryxMobile.xcarchive/Products/Applications"
app_count="$(find "$apps_dir" -maxdepth 1 -type d -name '*.app' -print | wc -l | tr -d '[:space:]')"
if [[ "$app_count" != "1" ]]; then
echo "Expected exactly one archived app bundle in $apps_dir; found $app_count." >&2
find "$apps_dir" -maxdepth 1 -type d -name '*.app' -print >&2
exit 1
fi
app_path="$(find "$apps_dir" -maxdepth 1 -type d -name '*.app' -print -quit)"
echo "Verifying archived app bundle: $(basename "$app_path")"
if [[ ! -f "$app_path/AppIcon60x60@2x.png" ]]; then
echo "Archived app is missing the iPhone app icon." >&2
exit 1
fi
if [[ ! -f "$app_path/AppIcon76x76@2x~ipad.png" ]]; then
echo "Archived app is missing the iPad app icon." >&2
exit 1
fi
if [[ ! -f "$app_path/Assets.car" ]]; then
echo "Archived app is missing compiled asset catalog." >&2
exit 1
fi
icon_name="$(/usr/libexec/PlistBuddy -c 'Print CFBundleIconName' "$app_path/Info.plist" 2>/dev/null || true)"
legacy_icon="$(/usr/libexec/PlistBuddy -c 'Print CFBundleIcons:CFBundlePrimaryIcon:CFBundleIconFiles:0' "$app_path/Info.plist" 2>/dev/null || true)"
if [[ "$icon_name" != "AppIcon" && -z "$legacy_icon" ]]; then
echo "Archived Info.plist does not declare an app icon." >&2
exit 1
fi
- name: Export IPA
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
export_options="$RUNNER_TEMP/ExportOptions.plist"
cat > "$export_options" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>method</key>
<string>app-store-connect</string>
<key>destination</key>
<string>export</string>
<key>signingStyle</key>
<string>manual</string>
<key>signingCertificate</key>
<string>Apple Distribution</string>
<key>teamID</key>
<string>${APPLE_TEAM_ID}</string>
<key>provisioningProfiles</key>
<dict>
<key>${IOS_BUNDLE_ID}</key>
<string>${IOS_APP_PROVISIONING_PROFILE_SPECIFIER}</string>
<key>${IOS_WIDGET_BUNDLE_ID}</key>
<string>${IOS_WIDGET_PROVISIONING_PROFILE_SPECIFIER}</string>
</dict>
<key>stripSwiftSymbols</key>
<true/>
<key>uploadSymbols</key>
<true/>
</dict>
</plist>
PLIST
xcodebuild \
-exportArchive \
-archivePath "$RUNNER_TEMP/GaryxMobile.xcarchive" \
-exportPath "$RUNNER_TEMP/GaryxMobileExport" \
-exportOptionsPlist "$export_options"
- name: Upload IPA to TestFlight
if: inputs.upload_build
shell: bash
run: |
set -euo pipefail
ipa_path="$(find "$RUNNER_TEMP/GaryxMobileExport" -maxdepth 1 -name '*.ipa' -print -quit)"
if [[ -z "$ipa_path" ]]; then
echo "No IPA exported." >&2
exit 1
fi
xcrun altool \
--upload-app \
--type ios \
--file "$ipa_path" \
--apiKey "$APP_STORE_CONNECT_API_KEY_ID" \
--apiIssuer "$APP_STORE_CONNECT_API_ISSUER_ID"
- name: Make build available to internal testers
if: inputs.upload_build
shell: bash
run: node scripts/appstore-connect/publish-internal-testflight.mjs
- name: Clean up signing keychain
if: always() && inputs.upload_build
shell: bash
run: |
set -euo pipefail
if [[ -n "${SIGNING_KEYCHAIN_PATH:-}" ]]; then
security delete-keychain "$SIGNING_KEYCHAIN_PATH" || true
fi