-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
348 lines (326 loc) · 12.4 KB
/
Makefile
File metadata and controls
348 lines (326 loc) · 12.4 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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
SHELL := /bin/bash
SIMULATOR_DEVICE ?= iPhone 16
CONFIGURATION ?= Debug
DERIVED_DATA ?= /tmp/delight-ios
BUNDLED_GOCACHE ?= $(CURDIR)/.gocache
BUNDLED_GOMODCACHE ?= $(CURDIR)/.gomodcache
BUNDLED_GOLANGCI_CACHE ?= $(CURDIR)/.golangci-cache
BUNDLE_ID ?=
APP_PATH := $(DERIVED_DATA)/Build/Products/$(CONFIGURATION)-iphonesimulator/Delight.app
SIMULATOR_UDID_FILE := $(DERIVED_DATA)/booted_simulator_udid
IOS_PROJECT ?= ios/DelightApp.xcodeproj
IOS_SCHEME ?= DelightApp
IOS_RELEASE_CONFIGURATION ?= Release
IOS_ARCHIVE_PATH ?= $(DERIVED_DATA)/archive/$(IOS_SCHEME).xcarchive
IOS_EXPORT_PATH ?= $(DERIVED_DATA)/export
IOS_EXPORT_OPTIONS_PLIST ?= $(DERIVED_DATA)/ExportOptions.plist
IOS_SIGNING_ENV ?= $(DERIVED_DATA)/ios-signing.env
IOS_PROFILE_RESOLVER ?= ios/scripts/resolve_profile.py
IOS_EXPORT_METHOD ?= app-store-connect
IOS_EXPORT_SIGNING_STYLE ?= automatic
IOS_PROFILE_NAME ?=
IOS_SIGNING_CERT ?=
IOS_AUTO_BUMP_BUILD ?= 1
IOS_BUILD_NUMBER ?=
ASC_API_KEY_ID ?=
ASC_API_ISSUER_ID ?=
ASC_API_KEY_PATH ?=
ASC_APPLE_ID ?=
ASC_PUBLIC_ID ?=
ASC_OUTPUT_FORMAT ?= normal
SERVER_DOCKER_IMAGE ?= delight-server:local
.PHONY: ios-sdk ios-build ios-sim-boot ios-install ios-run ios-signing-resolve ios-release-archive ios-export-ipa ios-testflight-upload
CLI_TEST_PKGS ?= ./...
SERVER_TEST_PKGS ?= ./...
WEBCLIENT_TEST_PKGS ?= ./...
GO_TEST_ARGS ?= -cover
IOS_TEST_RESULT ?= $(DERIVED_DATA)/TestResults
ios-sdk:
./cli/scripts/build_ios_sdk.sh
ios-build: ios-sdk
xcodebuild \
-project ios/DelightApp.xcodeproj \
-scheme DelightApp \
-configuration $(CONFIGURATION) \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$(SIMULATOR_DEVICE)" \
-derivedDataPath "$(DERIVED_DATA)" \
build
ios-sim-boot:
@mkdir -p "$(DERIVED_DATA)"
@./cli/scripts/ensure_ios_sim_booted.sh "$(SIMULATOR_DEVICE)" > "$(SIMULATOR_UDID_FILE)"
@echo "Booted simulator UDID: $$(cat "$(SIMULATOR_UDID_FILE)")"
@UDID="$$(cat "$(SIMULATOR_UDID_FILE)")"; \
open -a Simulator --args -CurrentDeviceUDID "$$UDID" >/dev/null 2>&1 || true
ios-install: ios-build ios-sim-boot
@UDID="$$(cat "$(SIMULATOR_UDID_FILE)")"; \
xcrun simctl install "$$UDID" "$(APP_PATH)"
ios-run: ios-install
@set -euo pipefail; \
UDID="$$(cat "$(SIMULATOR_UDID_FILE)")"; \
bundle_id="$(BUNDLE_ID)"; \
if [[ -z "$$bundle_id" ]]; then \
bundle_id="$$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$(APP_PATH)/Info.plist" 2>/dev/null || true)"; \
fi; \
if [[ -z "$$bundle_id" ]]; then \
echo "error: unable to determine app bundle id. Build output may be missing at $(APP_PATH)."; \
exit 1; \
fi; \
echo "Launching $$bundle_id on simulator $$UDID..."; \
xcrun simctl launch "$$UDID" "$$bundle_id"
ios-signing-resolve:
@set -euo pipefail; \
mkdir -p "$(DERIVED_DATA)"; \
signing_style="$(IOS_EXPORT_SIGNING_STYLE)"; \
profile_ref="$(IOS_PROFILE_NAME)"; \
resolved_profile_name=""; \
resolved_profile_uuid=""; \
resolved_profile_path=""; \
resolved_profile_cert_sha1=""; \
resolved_profile_get_task_allow=""; \
resolved_signing_cert="$(IOS_SIGNING_CERT)"; \
if [[ -n "$$profile_ref" ]]; then \
signing_style="manual"; \
fi; \
if [[ "$$signing_style" == "manual" ]]; then \
if [[ -z "$$profile_ref" ]]; then \
echo "error: IOS_PROFILE_NAME is required when IOS_EXPORT_SIGNING_STYLE=manual."; \
exit 1; \
fi; \
IFS=$$'\t' read -r resolved_profile_name resolved_profile_uuid resolved_profile_path resolved_profile_cert_sha1 resolved_profile_get_task_allow <<< "$$(python3 "$(IOS_PROFILE_RESOLVER)" "$$profile_ref")"; \
if [[ "$$resolved_profile_get_task_allow" == "true" ]]; then \
echo "warning: selected profile looks like a Development profile (get-task-allow=true)."; \
fi; \
if [[ -z "$$resolved_signing_cert" ]]; then \
resolved_signing_cert="$$resolved_profile_cert_sha1"; \
fi; \
if [[ -z "$$resolved_profile_uuid" ]]; then \
echo "error: selected profile did not include a UUID."; \
exit 1; \
fi; \
fi; \
{ \
printf 'IOS_RESOLVED_SIGNING_STYLE=%q\n' "$$signing_style"; \
printf 'IOS_RESOLVED_PROFILE_NAME=%q\n' "$$resolved_profile_name"; \
printf 'IOS_RESOLVED_PROFILE_UUID=%q\n' "$$resolved_profile_uuid"; \
printf 'IOS_RESOLVED_PROFILE_PATH=%q\n' "$$resolved_profile_path"; \
printf 'IOS_RESOLVED_PROFILE_CERT_SHA1=%q\n' "$$resolved_profile_cert_sha1"; \
printf 'IOS_RESOLVED_SIGNING_CERT=%q\n' "$$resolved_signing_cert"; \
} >"$(IOS_SIGNING_ENV)"; \
echo "Resolved iOS signing style: $$signing_style"; \
if [[ "$$signing_style" == "manual" ]]; then \
echo "Resolved profile: $$resolved_profile_name ($$resolved_profile_uuid)"; \
echo "Resolved profile path: $$resolved_profile_path"; \
echo "Resolved signing cert SHA1: $$resolved_signing_cert"; \
fi
ios-release-archive: ios-sdk ios-signing-resolve
@set -euo pipefail; \
source "$(IOS_SIGNING_ENV)"; \
rm -rf "$(IOS_ARCHIVE_PATH)"; \
signing_style="$$IOS_RESOLVED_SIGNING_STYLE"; \
build_number="$(IOS_BUILD_NUMBER)"; \
if [[ -z "$$build_number" && "$(IOS_AUTO_BUMP_BUILD)" == "1" ]]; then \
build_number="$$(date +%s)"; \
fi; \
if [[ -n "$$build_number" ]]; then \
echo "Using iOS build number: $$build_number"; \
else \
echo "Using project CURRENT_PROJECT_VERSION from Xcode settings."; \
fi; \
archive_cmd=( \
xcodebuild \
-project "$(IOS_PROJECT)" \
-scheme "$(IOS_SCHEME)" \
-configuration "$(IOS_RELEASE_CONFIGURATION)" \
-destination "generic/platform=iOS" \
-archivePath "$(IOS_ARCHIVE_PATH)" \
-allowProvisioningUpdates \
); \
if [[ -n "$$build_number" ]]; then \
archive_cmd+=(CURRENT_PROJECT_VERSION="$$build_number"); \
fi; \
if [[ "$$signing_style" == "manual" ]]; then \
archive_cmd+=( \
CODE_SIGN_STYLE=Manual \
PROVISIONING_PROFILE_SPECIFIER="$$IOS_RESOLVED_PROFILE_UUID" \
); \
if [[ -n "$$IOS_RESOLVED_SIGNING_CERT" ]]; then \
archive_cmd+=(CODE_SIGN_IDENTITY="$$IOS_RESOLVED_SIGNING_CERT"); \
fi; \
fi; \
"$${archive_cmd[@]}" archive
ios-export-ipa: ios-release-archive
@set -euo pipefail; \
source "$(IOS_SIGNING_ENV)"; \
archive_info_plist="$(IOS_ARCHIVE_PATH)/Info.plist"; \
if [[ ! -f "$$archive_info_plist" ]]; then \
echo "error: archive metadata not found at $$archive_info_plist"; \
exit 1; \
fi; \
bundle_id="$$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleIdentifier" "$$archive_info_plist" 2>/dev/null || true)"; \
if [[ -z "$$bundle_id" ]]; then \
echo "error: failed to read archive bundle id from $$archive_info_plist"; \
exit 1; \
fi; \
mkdir -p "$(DERIVED_DATA)"; \
signing_style="$$IOS_RESOLVED_SIGNING_STYLE"; \
if [[ "$$signing_style" == "manual" ]]; then \
if [[ -z "$$IOS_RESOLVED_PROFILE_UUID" ]]; then \
echo "error: manual signing selected but no resolved profile UUID is available."; \
exit 1; \
fi; \
{ \
printf '%s\n' \
'<?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>destination</key>' \
' <string>export</string>' \
' <key>method</key>' \
' <string>$(IOS_EXPORT_METHOD)</string>' \
' <key>signingStyle</key>' \
' <string>manual</string>'; \
if [[ -n "$$IOS_RESOLVED_SIGNING_CERT" ]]; then \
printf '%s\n' \
' <key>signingCertificate</key>' \
" <string>$$IOS_RESOLVED_SIGNING_CERT</string>"; \
fi; \
printf '%s\n' \
' <key>provisioningProfiles</key>' \
' <dict>' \
" <key>$$bundle_id</key>" \
" <string>$$IOS_RESOLVED_PROFILE_UUID</string>" \
' </dict>' \
' <key>stripSwiftSymbols</key>' \
' <true/>' \
' <key>manageAppVersionAndBuildNumber</key>' \
' <false/>' \
'</dict>' \
'</plist>'; \
} > "$(IOS_EXPORT_OPTIONS_PLIST)"; \
else \
printf '%s\n' \
'<?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>destination</key>' \
' <string>export</string>' \
' <key>method</key>' \
' <string>$(IOS_EXPORT_METHOD)</string>' \
' <key>signingStyle</key>' \
' <string>automatic</string>' \
' <key>stripSwiftSymbols</key>' \
' <true/>' \
' <key>manageAppVersionAndBuildNumber</key>' \
' <false/>' \
'</dict>' \
'</plist>' \
> "$(IOS_EXPORT_OPTIONS_PLIST)"; \
fi
rm -rf "$(IOS_EXPORT_PATH)"
xcodebuild \
-exportArchive \
-archivePath "$(IOS_ARCHIVE_PATH)" \
-exportPath "$(IOS_EXPORT_PATH)" \
-exportOptionsPlist "$(IOS_EXPORT_OPTIONS_PLIST)" \
-allowProvisioningUpdates
ios-testflight-upload: ios-export-ipa
@set -euo pipefail; \
if [[ -z "$(ASC_API_KEY_ID)" ]]; then \
echo "error: ASC_API_KEY_ID is required."; \
exit 1; \
fi; \
if [[ -z "$(ASC_API_ISSUER_ID)" ]]; then \
echo "error: ASC_API_ISSUER_ID is required."; \
exit 1; \
fi; \
if [[ -z "$(ASC_APPLE_ID)" ]]; then \
echo "error: ASC_APPLE_ID is required (numeric App Store Connect app ID)."; \
exit 1; \
fi; \
archive_info_plist="$(IOS_ARCHIVE_PATH)/Info.plist"; \
if [[ ! -f "$$archive_info_plist" ]]; then \
echo "error: archive metadata not found at $$archive_info_plist"; \
exit 1; \
fi; \
bundle_id="$$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleIdentifier" "$$archive_info_plist" 2>/dev/null || true)"; \
bundle_version="$$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleVersion" "$$archive_info_plist" 2>/dev/null || true)"; \
bundle_short_version="$$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleShortVersionString" "$$archive_info_plist" 2>/dev/null || true)"; \
if [[ -z "$$bundle_id" || -z "$$bundle_version" || -z "$$bundle_short_version" ]]; then \
echo "error: failed to read bundle metadata from $$archive_info_plist"; \
exit 1; \
fi; \
ipa_path="$$(find "$(IOS_EXPORT_PATH)" -maxdepth 1 -name '*.ipa' -print -quit)"; \
if [[ -z "$$ipa_path" ]]; then \
echo "error: no .ipa found under $(IOS_EXPORT_PATH)."; \
exit 1; \
fi; \
if [[ -n "$(ASC_API_KEY_PATH)" ]]; then \
keys_dir="$(DERIVED_DATA)/private_keys"; \
mkdir -p "$$keys_dir"; \
install -m 600 "$(ASC_API_KEY_PATH)" "$$keys_dir/AuthKey_$(ASC_API_KEY_ID).p8"; \
export API_PRIVATE_KEYS_DIR="$$keys_dir"; \
fi; \
echo "Uploading $$ipa_path to TestFlight..."; \
if [[ -n "$(ASC_PUBLIC_ID)" ]]; then \
xcrun altool \
--upload-package "$$ipa_path" \
--type ios \
--asc-public-id "$(ASC_PUBLIC_ID)" \
--apple-id "$(ASC_APPLE_ID)" \
--bundle-id "$$bundle_id" \
--bundle-version "$$bundle_version" \
--bundle-short-version-string "$$bundle_short_version" \
--apiKey "$(ASC_API_KEY_ID)" \
--apiIssuer "$(ASC_API_ISSUER_ID)" \
--show-progress \
--output-format "$(ASC_OUTPUT_FORMAT)"; \
else \
xcrun altool \
--upload-package "$$ipa_path" \
--type ios \
--apple-id "$(ASC_APPLE_ID)" \
--bundle-id "$$bundle_id" \
--bundle-version "$$bundle_version" \
--bundle-short-version-string "$$bundle_short_version" \
--apiKey "$(ASC_API_KEY_ID)" \
--apiIssuer "$(ASC_API_ISSUER_ID)" \
--show-progress \
--output-format "$(ASC_OUTPUT_FORMAT)"; \
fi
.PHONY: ios-test test
ios-test: ios-sdk ios-sim-boot
rm -rf "$(IOS_TEST_RESULT)"
rm -rf "$(IOS_TEST_RESULT).xcresult"
xcodebuild \
-project ios/DelightApp.xcodeproj \
-scheme DelightApp \
-configuration $(CONFIGURATION) \
-sdk iphonesimulator \
-destination "platform=iOS Simulator,name=$(SIMULATOR_DEVICE)" \
-derivedDataPath "$(DERIVED_DATA)" \
-resultBundlePath "$(IOS_TEST_RESULT)" \
-enableCodeCoverage YES \
test
test:
(cd cli && go test $(GO_TEST_ARGS) $(CLI_TEST_PKGS))
(cd webclient && go test $(GO_TEST_ARGS) $(WEBCLIENT_TEST_PKGS))
(cd server && go test $(GO_TEST_ARGS) $(SERVER_TEST_PKGS))
.PHONY: lint
lint:
@mkdir -p "$(BUNDLED_GOCACHE)" "$(BUNDLED_GOMODCACHE)" "$(BUNDLED_GOLANGCI_CACHE)"
(cd shared && GOCACHE="$(BUNDLED_GOCACHE)" GOMODCACHE="$(BUNDLED_GOMODCACHE)" GOLANGCI_LINT_CACHE="$(BUNDLED_GOLANGCI_CACHE)" golangci-lint run ./...)
(cd cli && GOCACHE="$(BUNDLED_GOCACHE)" GOMODCACHE="$(BUNDLED_GOMODCACHE)" GOLANGCI_LINT_CACHE="$(BUNDLED_GOLANGCI_CACHE)" golangci-lint run ./...)
(cd server && GOCACHE="$(BUNDLED_GOCACHE)" GOMODCACHE="$(BUNDLED_GOMODCACHE)" GOLANGCI_LINT_CACHE="$(BUNDLED_GOLANGCI_CACHE)" golangci-lint run ./...)
.PHONY: docker-build
docker-build:
docker build -f server/Dockerfile -t "$(SERVER_DOCKER_IMAGE)" .
.PHONY: cli server webclient
cli:
$(MAKE) -C cli
server:
$(MAKE) -C server
webclient:
$(MAKE) -C webclient