Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
287 lines (255 loc) · 13.7 KB
/
Copy pathTaskfile.yml
File metadata and controls
287 lines (255 loc) · 13.7 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
# ============================================================
# KVM Client — build and distribution from the command line (go-task).
#
# One-time setup:
# cp .env.example .env # then fill it in (App Store Connect API key, keychain)
#
# Everyday use:
# task check # compile macOS + iOS, no signing
# task appstore # iOS + Mac → App Store Connect (TestFlight)
# task direct # Mac Developer ID build, notarized DMG
# task github:release # publish the DMG as a GitHub release
# task release # all of the above
#
# Every step that publishes something (upload, GitHub release) asks first.
# Full list: task --list
# ============================================================
version: "3"
dotenv: [".env"]
vars:
PROJECT: KVMUI.xcodeproj
SCHEME: KVMUI
APP: KVM Client
# Build number: the commit count, so every commit gets a higher one. Override with BUILD=…
# (e.g. to re-upload the same commit after Apple rejected a binary).
BUILD:
sh: echo "${BUILD:-$(git rev-list --count HEAD)}"
VERSION:
sh: xcodebuild -project KVMUI.xcodeproj -showBuildSettings 2>/dev/null | awk '/ MARKETING_VERSION/ { print $3; exit }'
# The API key does two jobs: uploading, and letting -allowProvisioningUpdates create and fetch
# profiles without an Apple ID signed in to Xcode (impossible over SSH or on a build machine).
AUTH: >-
-authenticationKeyPath $HOME/.appstoreconnect/private_keys/AuthKey_$ASC_KEY_ID.p8
-authenticationKeyID $ASC_KEY_ID
-authenticationKeyIssuerID $ASC_ISSUER_ID
NOTARY_AUTH: >-
--key $HOME/.appstoreconnect/private_keys/AuthKey_$ASC_KEY_ID.p8
--key-id $ASC_KEY_ID --issuer $ASC_ISSUER_ID
tasks:
default:
cmds: [task --list]
silent: true
# ---- Development --------------------------------------------
check:
desc: Compile macOS and iOS (Release, unsigned)
cmds:
- for: [macosx, iphonesimulator]
cmd: >-
xcodebuild -project {{.PROJECT}} -scheme {{.SCHEME}} -configuration Release -sdk {{.ITEM}}
-derivedDataPath build/check CODE_SIGNING_ALLOWED=NO build -quiet
screenshots:
desc: Retake the iPhone and iPad App Store screenshots (LANGS="en fr")
cmds:
- Distribution/take-screenshots.sh {{.LANGS | default "en fr"}}
header:
desc: Render the App Store product page header
cmds: [Distribution/render-header.sh]
version:
desc: "Set the marketing version: task version -- 1.1"
requires:
vars: [CLI_ARGS]
preconditions:
- sh: echo "{{.CLI_ARGS}}" | grep -Eq '^[0-9]+(\.[0-9]+){1,2}$'
msg: "Usage: task version -- 1.1 (got \"{{.CLI_ARGS}}\")"
cmds:
- sed -i '' -E 's/MARKETING_VERSION = [0-9.]+;/MARKETING_VERSION = {{.CLI_ARGS}};/' {{.PROJECT}}/project.pbxproj
- echo "version {{.VERSION}} → {{.CLI_ARGS}} (commit it, then release)"
clean:
desc: Delete build products
cmds: [rm -rf build]
# ---- Signing prerequisites ----------------------------------
check-key:
internal: true
preconditions:
- sh: test -n "$ASC_KEY_ID" && test -n "$ASC_ISSUER_ID"
msg: |
❌ ASC_KEY_ID / ASC_ISSUER_ID missing from .env (cp .env.example .env)
App Store Connect › Users and Access › Integrations › App Store Connect API
- sh: test -f "$HOME/.appstoreconnect/private_keys/AuthKey_$ASC_KEY_ID.p8"
msg: "❌ API key not found: ~/.appstoreconnect/private_keys/AuthKey_$ASC_KEY_ID.p8"
keychain:
desc: Unlock the signing keychain (BUILD_KEYCHAIN / BUILD_KEYCHAIN_PASSWORD from .env)
# macOS keeps keychains unlocked per session: an SSH session or a fresh login can't reach the
# login keychain, and codesign then fails with errSecInternalComponent. A dedicated build
# keychain whose password lives in .env avoids that. Skipped when not configured (a local
# session with the login keychain unlocked works as is).
cmds:
- |
if [ -n "${BUILD_KEYCHAIN_PASSWORD:-}" ]; then
keychain="${BUILD_KEYCHAIN:-login.keychain-db}"
case "$keychain" in */*) ;; *) keychain="$HOME/Library/Keychains/$keychain" ;; esac
security unlock-keychain -p "$BUILD_KEYCHAIN_PASSWORD" "$keychain"
security set-keychain-settings "$keychain" # no timeout, no lock on sleep
echo "keychain unlocked: $keychain"
fi
keychain:setup:
desc: "Create the dedicated signing keychain and import a certificate: task keychain:setup -- ~/cert.p12"
# Export the certificate with its private key from Keychain Access (right-click › Export,
# .p12). Run once per certificate a release uses: "Apple Distribution" (export/upload),
# "Apple Development" (automatic signing archives with it) and "Developer ID Application"
# (DMG). The keychain then unlocks itself on every task run.
interactive: true
preconditions:
- sh: test -n "${BUILD_KEYCHAIN:-}" && test -n "${BUILD_KEYCHAIN_PASSWORD:-}"
msg: "❌ Set BUILD_KEYCHAIN and BUILD_KEYCHAIN_PASSWORD in .env first (see .env.example)."
- sh: test -f "{{.CLI_ARGS}}"
msg: "Usage: task keychain:setup -- path/to/certificate.p12"
cmds:
- |
keychain="$BUILD_KEYCHAIN"
case "$keychain" in */*) ;; *) keychain="$HOME/Library/Keychains/$keychain" ;; esac
[ -f "$keychain" ] || security create-keychain -p "$BUILD_KEYCHAIN_PASSWORD" "$keychain"
security unlock-keychain -p "$BUILD_KEYCHAIN_PASSWORD" "$keychain"
security set-keychain-settings "$keychain"
printf "Password of {{.CLI_ARGS}}: "; stty -echo; read p12; stty echo; echo
security import "{{.CLI_ARGS}}" -k "$keychain" -P "$p12" -T /usr/bin/codesign -T /usr/bin/security
# Let codesign use the key without a confirmation dialog nobody would see.
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k "$BUILD_KEYCHAIN_PASSWORD" "$keychain" >/dev/null
# Make it visible to codesign and xcodebuild, keeping the existing search list.
if ! security list-keychains -d user | grep -q "$keychain"; then
security list-keychains -d user -s "$keychain" $(security list-keychains -d user | tr -d '"')
fi
security find-identity -v -p codesigning "$keychain"
check-signing:
internal: true
deps: [check-key]
interactive: true
cmds:
- task: keychain
# Automatic signing archives with the development certificate; export re-signs for
# distribution (locally or with a cloud-managed certificate through the API key).
#
# Seeing the identity isn't enough: in an SSH or remote session the keychain is listed but
# locked, and codesign only fails minutes into the archive (errSecInternalComponent). So sign
# a throwaway file first, and offer to unlock when there's a terminal to type into.
- |
identity=$(security find-identity -v -p codesigning | awk '/Apple Development/ { print $2; exit }')
if [ -z "$identity" ]; then
echo "❌ No \"Apple Development\" certificate found (see .env.example)." >&2
exit 1
fi
keychain="${BUILD_KEYCHAIN:-login.keychain-db}"
case "$keychain" in */*) ;; *) keychain="$HOME/Library/Keychains/$keychain" ;; esac
probe=$(mktemp -t kvmclient-sign); cp /usr/bin/true "$probe"
trap 'rm -f "$probe"' EXIT
if ! codesign --force --sign "$identity" "$probe" 2>/dev/null; then
if [ -t 0 ]; then
echo "🔒 The keychain is locked in this session: $keychain"
security unlock-keychain "$keychain"
security set-keychain-settings "$keychain"
fi
if ! codesign --force --sign "$identity" "$probe" 2>/dev/null; then
printf '%s\n' "❌ Can't sign: the keychain holding the private key is locked in this session." \
" Run: security unlock-keychain $keychain" \
" or set BUILD_KEYCHAIN / BUILD_KEYCHAIN_PASSWORD in .env (see .env.example)." >&2
exit 1
fi
fi
echo "✓ signing works ($(security find-identity -v -p codesigning | awk -v id="$identity" '$2 == id { $1 = $2 = ""; print; exit }' | sed 's/^ *//'))"
# ---- Generic steps ------------------------------------------
_archive:
internal: true
deps: [check-signing]
cmds:
- >-
xcodebuild archive -project {{.PROJECT}} -scheme {{.SCHEME}} -configuration Release
-destination "generic/platform={{.PLATFORM}}" -archivePath build/{{.DIR}}/KVMClient.xcarchive
CURRENT_PROJECT_VERSION={{.BUILD}} {{.EXTRA}} -allowProvisioningUpdates {{.AUTH}} -quiet
- echo "✓ archived {{.DIR}} {{.VERSION}} ({{.BUILD}})"
_export:
internal: true
deps: [check-signing]
cmds:
- rm -rf build/{{.DIR}}/export
- >-
xcodebuild -exportArchive -archivePath build/{{.DIR}}/KVMClient.xcarchive
-exportOptionsPlist {{.OPTIONS}} -exportPath build/{{.DIR}}/export
-allowProvisioningUpdates {{.AUTH}}
_validate:
internal: true
deps: [check-key]
cmds:
- xcrun altool --validate-app -f "{{.ARTIFACT}}" -t {{.TYPE}} --apiKey "$ASC_KEY_ID" --apiIssuer "$ASC_ISSUER_ID"
_upload:
internal: true
deps: [check-key]
prompt: "Upload {{.ARTIFACT}} ({{.VERSION}} build {{.BUILD}}) to App Store Connect?"
cmds:
- xcrun altool --upload-app -f "{{.ARTIFACT}}" -t {{.TYPE}} --apiKey "$ASC_KEY_ID" --apiIssuer "$ASC_ISSUER_ID"
# ---- App Store: iPhone / iPad -------------------------------
ios:archive: {desc: "iOS — archive", cmds: [{task: _archive, vars: {PLATFORM: iOS, DIR: ios}}]}
ios:export: {desc: "iOS — export the IPA", cmds: [{task: _export, vars: {DIR: ios, OPTIONS: Distribution/ExportOptions-AppStore.plist}}]}
ios:validate: {desc: "iOS — validate with Apple, no upload", cmds: [{task: _validate, vars: {ARTIFACT: "build/ios/export/{{.APP}}.ipa", TYPE: ios}}]}
ios:upload: {desc: "iOS — upload to App Store Connect", cmds: [{task: _upload, vars: {ARTIFACT: "build/ios/export/{{.APP}}.ipa", TYPE: ios}}]}
ios:
desc: "iOS — archive → export → validate → upload"
cmds: [{task: ios:archive}, {task: ios:export}, {task: ios:validate}, {task: ios:upload}]
# ---- App Store: Mac (sandboxed) -----------------------------
mac:archive: {desc: "Mac App Store — archive (sandboxed)", cmds: [{task: _archive, vars: {PLATFORM: macOS, DIR: mac}}]}
mac:export: {desc: "Mac App Store — export the PKG", cmds: [{task: _export, vars: {DIR: mac, OPTIONS: Distribution/ExportOptions-AppStore.plist}}]}
mac:validate: {desc: "Mac App Store — validate with Apple, no upload", cmds: [{task: _validate, vars: {ARTIFACT: "build/mac/export/{{.APP}}.pkg", TYPE: macos}}]}
mac:upload: {desc: "Mac App Store — upload to App Store Connect", cmds: [{task: _upload, vars: {ARTIFACT: "build/mac/export/{{.APP}}.pkg", TYPE: macos}}]}
mac:
desc: "Mac App Store — archive → export → validate → upload"
cmds: [{task: mac:archive}, {task: mac:export}, {task: mac:validate}, {task: mac:upload}]
appstore:
desc: iPhone, iPad and Mac → App Store Connect
cmds: [{task: ios}, {task: mac}]
# ---- Direct distribution: Mac, Developer ID -----------------
direct:archive:
desc: "Mac Developer ID — archive (not sandboxed: full ⌘Tab/⌘Space capture)"
cmds: [{task: _archive, vars: {PLATFORM: macOS, DIR: direct, EXTRA: CODE_SIGN_ENTITLEMENTS=Config/KVMUI-Direct.entitlements}}]
direct:export:
desc: Mac Developer ID — export the signed app
cmds: [{task: _export, vars: {DIR: direct, OPTIONS: Distribution/ExportOptions-DeveloperID.plist}}]
direct:dmg:
desc: Mac Developer ID — package, notarize and staple the DMG
deps: [check-key]
vars:
DMG: build/direct/KVM-Client-{{.VERSION}}.dmg
cmds:
- rm -rf build/direct/dmg "{{.DMG}}" && mkdir -p build/direct/dmg
- cp -R "build/direct/export/{{.APP}}.app" build/direct/dmg/
- ln -s /Applications build/direct/dmg/Applications
- hdiutil create -volname "{{.APP}}" -srcfolder build/direct/dmg -fs HFS+ -format UDZO "{{.DMG}}" -quiet
# Signing the DMG itself needs the Developer ID certificate in the keychain; with a
# cloud-managed one only the app is signed, which notarization accepts.
- |
if security find-identity -v -p codesigning | grep -q "Developer ID Application"; then
codesign --sign "Developer ID Application" --timestamp "{{.DMG}}"
fi
- xcrun notarytool submit "{{.DMG}}" {{.NOTARY_AUTH}} --wait
- xcrun stapler staple "{{.DMG}}"
- spctl --assess --type open --context context:primary-signature -v "{{.DMG}}"
- echo "✓ {{.DMG}}"
direct:
desc: "Mac Developer ID — archive → export → notarized DMG"
cmds: [{task: direct:archive}, {task: direct:export}, {task: direct:dmg}]
github:release:
desc: Publish the notarized DMG as a GitHub release (v + marketing version)
vars:
DMG: build/direct/KVM-Client-{{.VERSION}}.dmg
preconditions:
- sh: test -f "{{.DMG}}"
msg: "❌ {{.DMG}} not found — run: task direct"
- sh: test -z "$(git status --porcelain)"
msg: "❌ Uncommitted changes: commit first, the release is tagged on HEAD."
- sh: '[ "$(git rev-parse HEAD)" = "$(git rev-parse @{u})" ]'
msg: "❌ HEAD isn't pushed: push first, the release points at a GitHub commit."
prompt: "Publish GitHub release v{{.VERSION}} with {{.DMG}} on dumanhaydar/kvmclient (public)?"
cmds:
- gh release create "v{{.VERSION}}" "{{.DMG}}" --title "KVM Client {{.VERSION}}" --generate-notes --target "$(git rev-parse HEAD)"
# ---- Everything ---------------------------------------------
release:
desc: App Store (iOS + Mac), then the notarized DMG on GitHub
cmds: [{task: check}, {task: appstore}, {task: direct}, {task: github:release}]