-
Notifications
You must be signed in to change notification settings - Fork 0
509 lines (452 loc) · 18.5 KB
/
Copy pathrelease.yml
File metadata and controls
509 lines (452 loc) · 18.5 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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
name: Release
on:
push:
tags:
- "[0-9]+.[0-9]+.[0-9]+"
jobs:
# ============================================
# Find and wait for watchOS build
# ============================================
find-and-wait:
name: Find watchOS Build
runs-on: ubuntu-latest
outputs:
run_id: ${{ steps.find.outputs.run_id }}
steps:
- name: Find or wait for main build
id: find
env:
GH_TOKEN: ${{ github.token }}
run: |
COMMIT_SHA="${{ github.sha }}"
MAX_WAIT=3600
POLL_INTERVAL=30
WAITED=0
while [ $WAITED -lt $MAX_WAIT ]; do
RESULT=$(gh api repos/${{ github.repository }}/actions/workflows/build.yml/runs \
--jq ".workflow_runs[] | select(.head_sha==\"$COMMIT_SHA\") | {id, status, conclusion}" \
| head -1)
if [ -z "$RESULT" ]; then
echo "::error::No build found for commit $COMMIT_SHA"
exit 1
fi
STATUS=$(echo "$RESULT" | jq -r '.status')
CONCLUSION=$(echo "$RESULT" | jq -r '.conclusion')
RUN_ID=$(echo "$RESULT" | jq -r '.id')
if [ "$STATUS" = "completed" ]; then
if [ "$CONCLUSION" = "success" ]; then
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT
echo "Found successful build: $RUN_ID"
exit 0
else
echo "::error::Build $RUN_ID failed: $CONCLUSION"
exit 1
fi
fi
echo "Build $RUN_ID still running ($STATUS). Waiting ${POLL_INTERVAL}s..."
sleep $POLL_INTERVAL
WAITED=$((WAITED + POLL_INTERVAL))
done
echo "::error::Timeout waiting for build"
exit 1
# ============================================
# Build Garmin .iq package
# ============================================
build-garmin:
name: Build Garmin App
runs-on: ubuntu-latest
container:
image: ghcr.io/matco/connectiq-tester:latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Check for Garmin credentials
id: check_creds
env:
GARMIN_DEVELOPER_KEY: ${{ secrets.GARMIN_DEVELOPER_KEY }}
run: |
if [ -z "$GARMIN_DEVELOPER_KEY" ]; then
echo "has_creds=false" >> $GITHUB_OUTPUT
echo "::notice::GARMIN_DEVELOPER_KEY not configured - skipping Garmin build"
else
echo "has_creds=true" >> $GITHUB_OUTPUT
fi
- name: Install developer key
if: steps.check_creds.outputs.has_creds == 'true'
env:
GARMIN_DEVELOPER_KEY: ${{ secrets.GARMIN_DEVELOPER_KEY }}
run: |
mkdir -p ~/.Garmin
echo "$GARMIN_DEVELOPER_KEY" | base64 -d > ~/.Garmin/developer_key.der
- name: Generate Garmin secrets
if: steps.check_creds.outputs.has_creds == 'true'
env:
TRAINTIME_API_KEY: ${{ secrets.TRAINTIME_API_KEY }}
run: |
cat > garmin/TrainTime/source/Secrets.mc <<EOF
module Secrets {
const API_KEY = "$TRAINTIME_API_KEY";
}
EOF
- name: Build .iq package
if: steps.check_creds.outputs.has_creds == 'true'
working-directory: garmin/TrainTime
run: |
monkeyc -e -f monkey.jungle -o ../TrainTime.iq -y ~/.Garmin/developer_key.der -r
echo "Built TrainTime.iq ($(stat -c%s ../TrainTime.iq) bytes)"
- name: Upload Garmin artifact
if: steps.check_creds.outputs.has_creds == 'true'
uses: actions/upload-artifact@v4
with:
name: garmin-iq
path: garmin/TrainTime.iq
retention-days: 30
# ============================================
# Build Android .aab package
# ============================================
build-android:
name: Build Android App
runs-on: ubuntu-latest
steps:
- name: Check for Android signing credentials
id: check_creds
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: |
if [ -z "$ANDROID_KEYSTORE_BASE64" ]; then
echo "has_creds=false" >> $GITHUB_OUTPUT
echo "::notice::ANDROID_KEYSTORE_BASE64 not configured - skipping Android build"
else
echo "has_creds=true" >> $GITHUB_OUTPUT
fi
- name: Checkout
if: steps.check_creds.outputs.has_creds == 'true'
uses: actions/checkout@v4
- name: Verify tag matches versionName
if: steps.check_creds.outputs.has_creds == 'true'
run: |
VN=$(grep 'versionName = ' android/app/build.gradle.kts | sed 's/.*"\(.*\)".*/\1/')
VN_WEAR=$(grep 'versionName = ' android/wear/build.gradle.kts | sed 's/.*"\(.*\)".*/\1/')
echo "Tag: ${{ github.ref_name }} | app versionName: $VN | wear versionName: $VN_WEAR"
if [ "$VN" != "${{ github.ref_name }}" ]; then
echo "::error::Tag ${{ github.ref_name }} does not match versionName $VN. Bump versionName (and versionCode) in android/app/build.gradle.kts before tagging."
exit 1
fi
if [ "$VN_WEAR" != "${{ github.ref_name }}" ]; then
echo "::error::Tag ${{ github.ref_name }} does not match wear versionName $VN_WEAR. Bump versionName (and versionCode) in android/wear/build.gradle.kts before tagging."
exit 1
fi
- name: Setup Java
if: steps.check_creds.outputs.has_creds == 'true'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "17"
- name: Setup Gradle
if: steps.check_creds.outputs.has_creds == 'true'
uses: gradle/actions/setup-gradle@v4
- name: Decode signing keystore
if: steps.check_creds.outputs.has_creds == 'true'
working-directory: android
env:
ANDROID_KEYSTORE_BASE64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
run: echo "$ANDROID_KEYSTORE_BASE64" | base64 -d > upload-keystore.jks
- name: Build release AAB
if: steps.check_creds.outputs.has_creds == 'true'
working-directory: android
env:
TRAINTIME_API_KEY: ${{ secrets.TRAINTIME_API_KEY }}
KEYSTORE_FILE: upload-keystore.jks
KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
run: |
./gradlew :app:bundleRelease :wear:bundleRelease
mkdir -p dist
cp app/build/outputs/bundle/release/app-release.aab dist/
cp wear/build/outputs/bundle/release/wear-release.aab dist/
echo "Built app-release.aab ($(stat -c%s dist/app-release.aab) bytes), wear-release.aab ($(stat -c%s dist/wear-release.aab) bytes)"
- name: Upload Android artifact
if: steps.check_creds.outputs.has_creds == 'true'
uses: actions/upload-artifact@v4
with:
name: android-aab
path: android/dist/*.aab
retention-days: 30
# ============================================
# Create Release
# ============================================
release:
name: Create Release
needs: [find-and-wait, build-garmin, build-android]
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
ipa_path: ${{ steps.prepare.outputs.ipa_path }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version from tag
id: version
run: echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
- name: Download iOS/watchOS artifacts from main build
uses: actions/download-artifact@v4
with:
run-id: ${{ needs.find-and-wait.outputs.run_id }}
github-token: ${{ github.token }}
path: artifacts
- name: Download Garmin artifact
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: garmin-iq
path: artifacts/garmin
- name: Download Android artifact
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: android-aab
path: artifacts/android
- name: Prepare release artifacts
id: prepare
run: |
mkdir -p release
VERSION="${{ steps.version.outputs.version }}"
echo "=== Downloaded artifacts ==="
find artifacts -type f
echo "============================="
IPA=$(find artifacts -name "*.ipa" | head -1)
if [ -n "$IPA" ]; then
IPA_DEST="release/traintime-${VERSION}.ipa"
cp "$IPA" "$IPA_DEST"
echo "ipa_path=$IPA_DEST" >> $GITHUB_OUTPUT
echo "IPA: traintime-${VERSION}.ipa"
else
echo "::warning::No IPA found in artifacts"
fi
IQ=$(find artifacts -name "*.iq" | head -1)
if [ -n "$IQ" ]; then
cp "$IQ" "release/TrainTime-${VERSION}.iq"
echo "Garmin: TrainTime-${VERSION}.iq"
else
echo "::notice::No Garmin .iq found"
fi
AAB=$(find artifacts -name "app-release.aab" | head -1)
if [ -n "$AAB" ]; then
cp "$AAB" "release/traintime-${VERSION}.aab"
echo "Android: traintime-${VERSION}.aab"
else
echo "::notice::No Android .aab found"
fi
WEAR_AAB=$(find artifacts -name "wear-release.aab" | head -1)
if [ -n "$WEAR_AAB" ]; then
cp "$WEAR_AAB" "release/traintime-wear-${VERSION}.aab"
echo "Wear OS: traintime-wear-${VERSION}.aab"
else
echo "::notice::No Wear OS .aab found"
fi
echo ""
echo "=== Release artifacts ==="
ls -la release/
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
name: TrainTime v${{ steps.version.outputs.version }}
body: |
## TrainTime v${{ steps.version.outputs.version }}
## Downloads
- **iOS IPA**: For TestFlight / App Store (includes iOS app, watchOS companion, widget)
- **Garmin .iq**: Upload to [Connect IQ Store](https://apps.garmin.com/developer/dashboard)
- **Android .aab**: Signed release bundle for the [Play Console](https://play.google.com/console)
- **Wear OS .aab**: Signed watch bundle, uploaded to the same Play release
---
Built from commit: ${{ github.sha }}
files: release/*
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload IPA for deployment
if: steps.prepare.outputs.ipa_path != ''
uses: actions/upload-artifact@v4
with:
name: release-ipa
path: ${{ steps.prepare.outputs.ipa_path }}
retention-days: 1
# ============================================
# Deploy to TestFlight
# ============================================
deploy-testflight:
name: Deploy to TestFlight
needs: release
runs-on: macos-26
if: needs.release.outputs.ipa_path != ''
steps:
- name: Check for TestFlight credentials
id: check_creds
env:
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_API_KEY: ${{ secrets.ASC_API_KEY }}
run: |
if [ -z "$ASC_KEY_ID" ] || [ -z "$ASC_ISSUER_ID" ] || [ -z "$ASC_API_KEY" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "::notice::Skipping TestFlight - credentials not configured"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
if: steps.check_creds.outputs.skip != 'true'
uses: actions/checkout@v4
- name: Setup Ruby
if: steps.check_creds.outputs.skip != 'true'
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
working-directory: apple/fastlane
bundler-cache: true
- name: Download IPA
if: steps.check_creds.outputs.skip != 'true'
uses: actions/download-artifact@v4
with:
name: release-ipa
path: release/
- name: Upload to TestFlight
if: steps.check_creds.outputs.skip != 'true'
working-directory: apple/fastlane
env:
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_API_KEY: ${{ secrets.ASC_API_KEY }}
IPA_PATH: ${{ github.workspace }}/release/traintime-${{ needs.release.outputs.version }}.ipa
run: |
if [ ! -f "$IPA_PATH" ]; then
echo "Error: IPA file not found at $IPA_PATH"
ls -la "${{ github.workspace }}/release/" || echo "Directory not found"
exit 1
fi
bundle exec fastlane ios beta ipa:"$IPA_PATH"
- name: Summary
if: steps.check_creds.outputs.skip != 'true'
run: |
echo "## TestFlight Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ needs.release.outputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Track:** Internal TestFlight" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Build will be available in [App Store Connect](https://appstoreconnect.apple.com) shortly." >> $GITHUB_STEP_SUMMARY
# ============================================
# Prepare App Store version + upload metadata
# ============================================
prepare-appstore:
name: Prepare App Store version
needs: release
runs-on: ubuntu-latest
steps:
- name: Check for App Store Connect credentials
id: check_creds
env:
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_API_KEY: ${{ secrets.ASC_API_KEY }}
run: |
if [ -z "$ASC_KEY_ID" ] || [ -z "$ASC_ISSUER_ID" ] || [ -z "$ASC_API_KEY" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "::notice::Skipping App Store metadata - credentials not configured"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
if: steps.check_creds.outputs.skip != 'true'
uses: actions/checkout@v4
- name: Verify tag matches MARKETING_VERSION
if: steps.check_creds.outputs.skip != 'true'
run: |
MV=$(grep 'MARKETING_VERSION' apple/TrainTimeWatch.xcodeproj/project.pbxproj | head -1 | sed 's/.*= *\(.*\);/\1/' | tr -d ' ')
echo "Tag: ${{ github.ref_name }} | MARKETING_VERSION: $MV"
if [ "$MV" != "${{ github.ref_name }}" ]; then
echo "::error::Tag ${{ github.ref_name }} does not match MARKETING_VERSION $MV. Bump the version in Xcode before tagging."
exit 1
fi
- name: Setup Ruby
if: steps.check_creds.outputs.skip != 'true'
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
working-directory: apple/fastlane
bundler-cache: true
- name: Create App Store version and upload metadata
if: steps.check_creds.outputs.skip != 'true'
working-directory: apple/fastlane
env:
ASC_KEY_ID: ${{ secrets.ASC_KEY_ID }}
ASC_ISSUER_ID: ${{ secrets.ASC_ISSUER_ID }}
ASC_API_KEY: ${{ secrets.ASC_API_KEY }}
run: bundle exec fastlane ios sync_metadata version:${{ github.ref_name }}
- name: Summary
if: steps.check_creds.outputs.skip != 'true'
run: |
echo "## App Store Version Prepared" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ github.ref_name }} (Prepare for Submission, not submitted)" >> $GITHUB_STEP_SUMMARY
echo "- **Metadata:** uploaded from apple/fastlane/metadata/" >> $GITHUB_STEP_SUMMARY
# ============================================
# Deploy to Google Play
# ============================================
deploy-android:
name: Deploy to Google Play
needs: [release, build-android]
runs-on: ubuntu-latest
timeout-minutes: 25
steps:
- name: Check for Play credentials
id: check_creds
env:
PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
run: |
if [ -z "$PLAY_SERVICE_ACCOUNT_JSON" ]; then
echo "skip=true" >> $GITHUB_OUTPUT
echo "::notice::Skipping Google Play - PLAY_SERVICE_ACCOUNT_JSON not configured"
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
- name: Checkout repository
if: steps.check_creds.outputs.skip != 'true'
uses: actions/checkout@v4
- name: Setup Ruby
if: steps.check_creds.outputs.skip != 'true'
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2"
working-directory: android
bundler-cache: true
- name: Download Android AAB
if: steps.check_creds.outputs.skip != 'true'
uses: actions/download-artifact@v4
with:
name: android-aab
path: android/release
- name: Write Play credentials
if: steps.check_creds.outputs.skip != 'true'
working-directory: android
env:
PLAY_SERVICE_ACCOUNT_JSON: ${{ secrets.PLAY_SERVICE_ACCOUNT_JSON }}
run: echo "$PLAY_SERVICE_ACCOUNT_JSON" > play-service-account.json
- name: Upload to Google Play
if: steps.check_creds.outputs.skip != 'true'
working-directory: android
env:
SUPPLY_JSON_KEY: ${{ github.workspace }}/android/play-service-account.json
run: bundle exec fastlane android ci_release aab:"${{ github.workspace }}/android/release/app-release.aab" wear_aab:"${{ github.workspace }}/android/release/wear-release.aab"
- name: Summary
if: steps.check_creds.outputs.skip != 'true'
run: |
echo "## Google Play Deployment" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "- **Version:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "- **Internal testing:** published (live to internal testers, phone + Wear OS)" >> $GITHUB_STEP_SUMMARY
echo "- **Open testing:** staged as a draft (review and roll out in the console)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Build will appear in the [Play Console](https://play.google.com/console) shortly." >> $GITHUB_STEP_SUMMARY