-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathrelease-apps.sh
More file actions
executable file
·699 lines (581 loc) · 18.6 KB
/
release-apps.sh
File metadata and controls
executable file
·699 lines (581 loc) · 18.6 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
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
#!/bin/bash
#
# Release script for Flutter SDK Example Apps
# Builds and distributes Android and iOS apps using Fastlane
#
# Usage: ./release-apps.sh [--android-only] [--ios-only] [--dry-run] [--no-commit]
#
set -e # Exit on error
set -o pipefail # Catch errors in pipes
# ============================================================================
# CONFIGURATION
# ============================================================================
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="${SCRIPT_DIR}/packages/hmssdk_flutter"
EXAMPLE_DIR="${PROJECT_DIR}/example"
BUILD_GRADLE="${EXAMPLE_DIR}/android/app/build.gradle"
IOS_INFO_PLIST="${EXAMPLE_DIR}/ios/Runner/Info.plist"
# Build flags
BUILD_ANDROID=true
BUILD_IOS=true
DRY_RUN=false
SKIP_COMMIT=false
# ============================================================================
# COLORS AND LOGGING
# ============================================================================
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log_info() {
echo -e "${BLUE}[INFO]${NC} $(date '+%H:%M:%S') - $1"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $(date '+%H:%M:%S') - $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $(date '+%H:%M:%S') - $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $(date '+%H:%M:%S') - $1"
}
# ============================================================================
# CLEANUP AND ERROR HANDLING
# ============================================================================
cleanup() {
local exit_code=$?
if [ $exit_code -ne 0 ]; then
log_error "Script failed with exit code $exit_code"
log_info "Cleaning up background processes..."
jobs -p | xargs -r kill 2>/dev/null || true
fi
}
trap cleanup EXIT
# ============================================================================
# VALIDATION FUNCTIONS
# ============================================================================
check_requirements() {
log_info "Checking requirements..."
local missing_tools=()
command -v git >/dev/null 2>&1 || missing_tools+=("git")
command -v node >/dev/null 2>&1 || missing_tools+=("node")
command -v flutter >/dev/null 2>&1 || missing_tools+=("flutter")
command -v bundle >/dev/null 2>&1 || missing_tools+=("bundle (Ruby)")
if [ "$BUILD_IOS" = true ]; then
command -v pod >/dev/null 2>&1 || missing_tools+=("pod (CocoaPods)")
fi
if [ ${#missing_tools[@]} -ne 0 ]; then
log_error "Missing required tools: ${missing_tools[*]}"
exit 1
fi
log_success "All required tools are installed"
}
validate_directories() {
log_info "Validating directory structure..."
if [ ! -d "$PROJECT_DIR" ]; then
log_error "Project directory not found: $PROJECT_DIR"
exit 1
fi
if [ ! -d "$EXAMPLE_DIR" ]; then
log_error "Example directory not found: $EXAMPLE_DIR"
exit 1
fi
if [ "$BUILD_ANDROID" = true ] && [ ! -d "${EXAMPLE_DIR}/android" ]; then
log_error "Android directory not found: ${EXAMPLE_DIR}/android"
exit 1
fi
if [ "$BUILD_IOS" = true ] && [ ! -d "${EXAMPLE_DIR}/ios" ]; then
log_error "iOS directory not found: ${EXAMPLE_DIR}/ios"
exit 1
fi
log_success "Directory structure validated"
}
check_git_status() {
log_info "Checking git status..."
pushd "$SCRIPT_DIR" >/dev/null
if [ "$DRY_RUN" = false ] && [ "$SKIP_COMMIT" = false ]; then
if ! git diff-index --quiet HEAD -- 2>/dev/null; then
log_warn "You have uncommitted changes"
log_info "Uncommitted files:"
git status --short
read -p "Continue anyway? (y/N): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_info "Aborted by user"
exit 0
fi
fi
fi
popd >/dev/null
}
# ============================================================================
# MAIN FUNCTIONS
# ============================================================================
perform_pub_actions() {
log_info "Starting Flutter pub get..."
pushd "$PROJECT_DIR" >/dev/null
log_info "Git branch: $(git rev-parse --abbrev-ref HEAD)"
log_info "Git pull in project directory..."
if [ "$DRY_RUN" = false ]; then
git pull --verbose || {
log_error "Git pull failed"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: git pull --verbose"
fi
log_info "Running flutter pub get..."
if [ "$DRY_RUN" = false ]; then
flutter pub get || {
log_error "flutter pub get failed in project directory"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: flutter pub get"
fi
pushd example >/dev/null
log_info "Running flutter pub get in example..."
if [ "$DRY_RUN" = false ]; then
flutter pub get || {
log_error "flutter pub get failed in example directory"
popd >/dev/null
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: flutter pub get"
fi
popd >/dev/null
popd >/dev/null
log_success "Flutter pub get completed"
return 0
}
bump_android_version() {
log_info "Bumping Android version..."
pushd "${EXAMPLE_DIR}/android" >/dev/null
log_info "Installing Ruby dependencies..."
if [ "$DRY_RUN" = false ]; then
bundle install --verbose || {
log_error "bundle install failed for Android"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: bundle install --verbose"
fi
if [ "$DRY_RUN" = false ]; then
bundle exec fastlane bump_version || {
log_error "Fastlane bump_version failed for Android"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: bundle exec fastlane bump_version"
fi
popd >/dev/null
log_success "Android version bump completed"
return 0
}
release_android() {
log_info "Starting Android distribution..."
pushd "${EXAMPLE_DIR}/android" >/dev/null
log_info "Running Fastlane distribute_app_only for Android..."
if [ "$DRY_RUN" = false ]; then
bundle exec fastlane distribute_app_only || {
log_error "Fastlane distribute_app_only failed for Android"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: bundle exec fastlane distribute_app_only"
fi
popd >/dev/null
log_success "Android distribution completed"
return 0
}
bump_ios_version() {
log_info "Bumping iOS version..."
pushd "${EXAMPLE_DIR}/ios" >/dev/null
log_info "Installing CocoaPods dependencies..."
if [ "$DRY_RUN" = false ]; then
pod install --verbose || {
log_error "pod install failed"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: pod install --verbose"
fi
log_info "Installing Ruby dependencies..."
if [ "$DRY_RUN" = false ]; then
bundle install --verbose || {
log_error "bundle install failed for iOS"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: bundle install --verbose"
fi
if [ "$DRY_RUN" = false ]; then
bundle exec fastlane bump_version || {
log_error "Fastlane bump_version failed for iOS"
popd >/dev/null
return 1
}
else
log_info "[DRY RUN] Would run: bundle exec fastlane bump_version"
fi
popd >/dev/null
log_success "iOS version bump completed"
return 0
}
release_ios() {
log_info "Starting iOS distribution to Firebase and TestFlight..."
pushd "${EXAMPLE_DIR}/ios" >/dev/null
local firebase_failed=false
local testflight_failed=false
if [ "$DRY_RUN" = false ]; then
# Run Firebase distribution first
log_info "Running Firebase distribution..."
if ! bundle exec fastlane distribute_firebase_only; then
log_error "Firebase distribution failed"
firebase_failed=true
else
log_success "Firebase distribution completed"
fi
# Run TestFlight distribution second
log_info "Running TestFlight distribution..."
if ! bundle exec fastlane distribute_testflight_only; then
log_error "TestFlight distribution failed"
testflight_failed=true
else
log_success "TestFlight distribution completed"
fi
# Check results
if [ "$firebase_failed" = true ] && [ "$testflight_failed" = true ]; then
log_error "Both Firebase and TestFlight distributions failed"
popd >/dev/null
return 1
elif [ "$firebase_failed" = true ]; then
log_warn "Firebase distribution failed, but TestFlight succeeded"
elif [ "$testflight_failed" = true ]; then
log_warn "TestFlight distribution failed, but Firebase succeeded"
else
log_success "Both Firebase and TestFlight distributions completed successfully"
fi
# Post Slack notification
log_info "Posting Slack notification..."
bundle exec fastlane post_message_on_slack || {
log_warn "Slack notification failed (non-fatal)"
}
else
log_info "[DRY RUN] Would run: bundle exec fastlane distribute_firebase_only"
log_info "[DRY RUN] Would run: bundle exec fastlane distribute_testflight_only"
log_info "[DRY RUN] Would run: bundle exec fastlane post_message_on_slack"
fi
popd >/dev/null
log_success "iOS release completed"
return 0
}
get_android_version_info() {
local build_gradle="$1"
local version_code=""
local version_name=""
while IFS= read -r line; do
if [[ $line =~ ^[[:space:]]*versionCode[[:space:]]+([0-9]+) ]]; then
version_code="${BASH_REMATCH[1]}"
elif [[ $line =~ ^[[:space:]]*versionName[[:space:]]+\"([0-9]+\.[0-9]+\.[0-9]+)\" ]]; then
version_name="${BASH_REMATCH[1]}"
fi
done <"$build_gradle"
if [ -z "$version_code" ] || [ -z "$version_name" ]; then
log_error "Failed to parse version info from build.gradle"
return 1
fi
echo "${version_name}:${version_code}"
return 0
}
get_ios_version_info() {
local info_plist="$1"
local version=""
local build=""
if [ ! -f "$info_plist" ]; then
log_error "Info.plist not found at: $info_plist"
return 1
fi
# Use /usr/libexec/PlistBuddy to read plist values (macOS built-in)
if command -v /usr/libexec/PlistBuddy >/dev/null 2>&1; then
version=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "$info_plist" 2>/dev/null)
build=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "$info_plist" 2>/dev/null)
else
# Fallback: parse with grep/sed
version=$(grep -A 1 "CFBundleShortVersionString" "$info_plist" | grep "<string>" | sed -E 's/.*<string>(.*)<\/string>.*/\1/' | tr -d '[:space:]')
build=$(grep -A 1 "CFBundleVersion" "$info_plist" | grep "<string>" | sed -E 's/.*<string>(.*)<\/string>.*/\1/' | tr -d '[:space:]')
fi
if [ -z "$version" ] || [ -z "$build" ]; then
log_error "Failed to get iOS version info from Info.plist"
return 1
fi
echo "${version}:${build}"
return 0
}
perform_git_actions() {
log_info "Starting git actions..."
pushd "$SCRIPT_DIR" >/dev/null
# Get version info after builds complete (Fastlane updates these during build)
local android_version=""
local ios_version=""
local commit_message=""
if [ "$BUILD_ANDROID" = true ]; then
android_version=$(get_android_version_info "${BUILD_GRADLE}") || {
log_error "Failed to get Android version info"
popd >/dev/null
return 1
}
log_info "Android version: $android_version"
fi
if [ "$BUILD_IOS" = true ]; then
ios_version=$(get_ios_version_info "${IOS_INFO_PLIST}") || {
log_error "Failed to get iOS version info"
popd >/dev/null
return 1
}
log_info "iOS version: $ios_version"
fi
# Build commit message
if [ "$BUILD_ANDROID" = true ] && [ "$BUILD_IOS" = true ]; then
local android_ver="${android_version%:*}"
local android_build="${android_version#*:}"
commit_message="released sample app version ${android_ver} (${android_build}) 🍀"
elif [ "$BUILD_ANDROID" = true ]; then
local android_ver="${android_version%:*}"
local android_build="${android_version#*:}"
commit_message="released sample app - Android ${android_ver} (${android_build}) 🤖"
elif [ "$BUILD_IOS" = true ]; then
local ios_ver="${ios_version%:*}"
local ios_build="${ios_version#*:}"
commit_message="released sample app - iOS ${ios_ver} (${ios_build}) 🍎"
fi
log_info "Staging changed files..."
if [ "$DRY_RUN" = false ]; then
# Add Android files if built
if [ "$BUILD_ANDROID" = true ]; then
git add packages/hmssdk_flutter/example/android/app/build.gradle 2>/dev/null || log_warn "No changes in Android build.gradle"
fi
# Add iOS files if built
if [ "$BUILD_IOS" = true ]; then
git add packages/hmssdk_flutter/example/ios/Podfile.lock 2>/dev/null || log_warn "No changes in Podfile.lock"
git add packages/hmssdk_flutter/example/ios/Runner/Info.plist 2>/dev/null || log_warn "No changes in Info.plist"
git add packages/hmssdk_flutter/example/ios/Runner.xcodeproj/project.pbxproj 2>/dev/null || log_warn "No changes in project.pbxproj"
fi
# Add updated changelog file with version info
git add packages/hmssdk_flutter/example/ExampleAppChangelog.txt 2>/dev/null || log_warn "No changes in changelog"
# Check if there are staged changes
if git diff --cached --quiet; then
log_warn "No changes to commit"
else
log_info "Committing changes..."
git commit -m "$commit_message" || {
log_error "Git commit failed"
popd >/dev/null
return 1
}
log_info "Pushing to remote..."
git push --verbose || {
log_error "Git push failed"
popd >/dev/null
return 1
}
fi
else
log_info "[DRY RUN] Would commit: $commit_message"
log_info "[DRY RUN] Would push to remote"
fi
popd >/dev/null
log_success "Git actions completed"
return 0
}
# ============================================================================
# ARGUMENT PARSING
# ============================================================================
parse_arguments() {
while [[ $# -gt 0 ]]; do
case $1 in
--android-only)
BUILD_IOS=false
log_info "Building Android only"
shift
;;
--ios-only)
BUILD_ANDROID=false
log_info "Building iOS only"
shift
;;
--dry-run)
DRY_RUN=true
log_info "Dry run mode enabled"
shift
;;
--no-commit)
SKIP_COMMIT=true
log_info "Skipping git commit"
shift
;;
-h | --help)
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Release script for Flutter SDK Example Apps"
echo ""
echo "Options:"
echo " --android-only Build and release Android only"
echo " --ios-only Build and release iOS only"
echo " --dry-run Show what would be done without executing"
echo " --no-commit Skip git commit and push"
echo " -h, --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Build and release both platforms"
echo " $0 --android-only # Build Android only"
echo " $0 --dry-run # Preview what would happen"
echo " $0 --no-commit # Build without committing"
exit 0
;;
*)
log_error "Unknown option: $1"
echo "Use --help for usage information"
exit 1
;;
esac
done
}
# ============================================================================
# MAIN EXECUTION
# ============================================================================
main() {
log_info "=========================================="
log_info "Flutter SDK Release Script"
log_info "=========================================="
echo ""
# Parse command line arguments
parse_arguments "$@"
# Pre-flight checks
check_requirements
validate_directories
check_git_status
echo ""
log_info "Starting release process..."
echo ""
# Step 1: Perform Flutter pub get
log_info "[1/5] Running flutter pub get..."
perform_pub_actions &
pub_pid=$!
# Wait for pub get to complete
if ! wait $pub_pid; then
log_error "Flutter pub get failed"
exit 1
fi
echo ""
log_info "[2/5] Bumping versions..."
echo ""
# Step 2: Bump versions for Android & iOS in parallel
local android_bump_pid=""
local ios_bump_pid=""
if [ "$BUILD_ANDROID" = true ]; then
bump_android_version &
android_bump_pid=$!
log_info "Android version bump started (PID: $android_bump_pid)"
fi
if [ "$BUILD_IOS" = true ]; then
bump_ios_version &
ios_bump_pid=$!
log_info "iOS version bump started (PID: $ios_bump_pid)"
fi
# Wait for version bumps to complete
local bump_failed=false
if [ -n "$android_bump_pid" ]; then
if ! wait $android_bump_pid; then
log_error "Android version bump failed"
bump_failed=true
fi
fi
if [ -n "$ios_bump_pid" ]; then
if ! wait $ios_bump_pid; then
log_error "iOS version bump failed"
bump_failed=true
fi
fi
if [ "$bump_failed" = true ]; then
log_error "Version bump failed"
exit 1
fi
echo ""
log_info "[3/5] Updating changelog with bumped versions..."
if [ "$DRY_RUN" = false ]; then
node "${SCRIPT_DIR}/scripts/update-changelog-versions.js" || {
log_warn "Failed to update changelog versions (non-fatal, continuing...)"
}
else
log_info "[DRY RUN] Would run: node scripts/update-changelog-versions.js"
fi
echo ""
echo ""
log_info "[4/5] Building and distributing apps..."
echo ""
# Step 4: Build and release Android & iOS in parallel
local android_pid=""
local ios_pid=""
if [ "$BUILD_ANDROID" = true ]; then
release_android &
android_pid=$!
log_info "Android distribution started (PID: $android_pid)"
fi
if [ "$BUILD_IOS" = true ]; then
release_ios &
ios_pid=$!
log_info "iOS distribution started (PID: $ios_pid)"
fi
# Wait for distributions to complete
local build_failed=false
if [ -n "$android_pid" ]; then
if ! wait $android_pid; then
log_error "Android distribution failed"
build_failed=true
fi
fi
if [ -n "$ios_pid" ]; then
if ! wait $ios_pid; then
log_error "iOS distribution failed"
build_failed=true
fi
fi
if [ "$build_failed" = true ]; then
log_error "One or more distributions failed"
exit 1
fi
echo ""
log_success "All distributions completed successfully"
echo ""
# Step 5: Perform git actions
if [ "$SKIP_COMMIT" = false ]; then
log_info "[5/5] Committing and pushing changes..."
perform_git_actions || {
log_error "Git actions failed"
exit 1
}
else
log_info "[5/5] Skipping git commit (--no-commit flag)"
fi
echo ""
log_success "=========================================="
log_success "Release completed successfully! 🎉"
log_success "=========================================="
# Optional: macOS voice notification
if command -v say >/dev/null 2>&1; then
say "Release completed" &
fi
}
# Run main function
main "$@"