@@ -13,22 +13,15 @@ sdk_names = ['StreamChatSwiftUI']
13
13
github_repo = ENV [ 'GITHUB_REPOSITORY' ] || 'GetStream/stream-chat-swiftui'
14
14
derived_data_path = 'derived_data'
15
15
source_packages_path = 'spm_cache'
16
- metrics_git = 'git@github.com:GetStream/stream-internal-metrics.git'
17
- sdk_size_path = "metrics/#{ github_repo . split ( '/' ) . last } -size.json"
18
16
buildcache_xcargs = 'CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++'
19
17
is_localhost = !is_ci
20
18
project_package_resolved = "#{ xcode_project } /project.xcworkspace/xcshareddata/swiftpm/Package.resolved"
21
19
@force_check = false
22
20
23
- warning_status = '🟡' # Warning if a branch is #{max_tolerance} less performant than the benchmark
24
- fail_status = '🔴' # Failure if a branch is more than #{max_tolerance} less performant than the benchmark
25
- success_status = '🟢' # Success if a branch is more performant or equals to the benchmark
26
- outstanding_status = '🚀' # Outstanding performance
27
-
28
21
before_all do |lane |
29
22
if is_ci
30
23
setup_ci
31
- sh ( 'git config --global user.name "Stream Bot"' )
24
+ setup_git_config
32
25
xcversion ( version : xcode_version ) unless [ :publish_release , :allure_launch , :allure_upload , :copyright , :pod_lint ] . include? ( lane )
33
26
end
34
27
end
@@ -152,7 +145,7 @@ lane :merge_release_to_main do |options|
152
145
153
146
comment = "[Publication of the release](https://github.com/#{ github_repo } /actions/workflows/release-publish.yml) has been launched 👍"
154
147
UI . important ( comment )
155
- create_pr_comment ( pr_num : ENV . fetch ( 'GITHUB_PR_NUM' ) , text : comment )
148
+ pr_comment ( text : comment )
156
149
end
157
150
158
151
lane :merge_main_to_develop do
@@ -234,7 +227,7 @@ lane :test_ui do |options|
234
227
png_files . each { |png | sh ( "git add #{ png } " ) || true }
235
228
sh ( 'git restore .' )
236
229
237
- create_pr (
230
+ pr_create (
238
231
title : '[CI] Snapshots' ,
239
232
base_branch : current_branch ,
240
233
head_branch : "#{ current_branch } -snapshots"
@@ -448,21 +441,7 @@ lane :rubocop do
448
441
end
449
442
450
443
lane :install_runtime do |options |
451
- runtimes = `xcrun simctl runtime list -j`
452
- UI . message ( "👉 Runtime list:\n #{ runtimes } " )
453
- simulators = JSON . parse ( runtimes ) . select do |_ , sim |
454
- sim [ 'platformIdentifier' ] . end_with? ( 'iphonesimulator' ) && sim [ 'version' ] == options [ :ios ] && sim [ 'state' ] == 'Ready'
455
- end
456
-
457
- if simulators . empty?
458
- Dir . chdir ( '..' ) do
459
- sh ( "echo 'iOS #{ options [ :ios ] } Simulator' | ipsw download xcode --sim" ) if Dir [ '*.dmg' ] . first . nil?
460
- sh ( "./Scripts/install_ios_runtime.sh #{ Dir [ '*.dmg' ] . first } " )
461
- UI . success ( "iOS #{ options [ :ios ] } Runtime successfuly installed" )
462
- end
463
- else
464
- UI . important ( "iOS #{ options [ :ios ] } Runtime already exists" )
465
- end
444
+ install_ios_runtime ( version : options [ :ios ] , custom_script : 'Scripts/install_ios_runtime.sh' )
466
445
end
467
446
468
447
desc 'Remove UI Snapshots'
@@ -492,92 +471,26 @@ lane :copyright do
492
471
update_copyright ( ignore : [ derived_data_path , source_packages_path , 'vendor/' ] )
493
472
next unless is_ci
494
473
495
- create_pr (
474
+ pr_create (
496
475
title : '[CI] Update Copyright' ,
497
476
head_branch : "ci/update-copyright-#{ Time . now . to_i } "
498
477
)
499
478
end
500
479
501
- desc 'Show current frameworks size'
502
480
lane :show_frameworks_sizes do |options |
503
481
next unless is_check_required ( sources : sources_matrix [ :size ] , force_check : @force_check )
504
482
505
- [ 'metrics/' ] . each { |dir | FileUtils . remove_dir ( dir , force : true ) }
506
-
507
- sh ( "git clone #{ metrics_git } #{ File . dirname ( sdk_size_path ) } " )
508
- is_release = current_branch . include? ( 'release/' )
509
- benchmark_config = JSON . parse ( File . read ( sdk_size_path ) )
510
- benchmark_key = is_release ? 'release' : 'develop'
511
- benchmark_sizes = benchmark_config [ benchmark_key ]
512
- branch_sizes = options [ :sizes ] || frameworks_sizes
513
-
514
- table_header = '## SDK Size'
515
- markdown_table = "#{ table_header } \n | `title` | `#{ is_release ? 'previous release' : 'develop' } ` | `#{ is_release ? 'current release' : 'branch' } ` | `diff` | `status` |\n | - | - | - | - | - |\n "
516
- sdk_names . each do |title |
517
- benchmark_value = benchmark_sizes [ title ]
518
- branch_value = branch_sizes [ title . to_sym ]
519
- max_tolerance = 0.5 # Max Tolerance is 0.5MB
520
- fine_tolerance = 0.25 # Fine Tolerance is 0.25MB
521
-
522
- diff = ( branch_value - benchmark_value ) . round ( 2 )
523
-
524
- status_emoji =
525
- if diff < 0
526
- outstanding_status
527
- elsif diff >= max_tolerance
528
- fail_status
529
- elsif diff >= fine_tolerance
530
- warning_status
531
- else
532
- success_status
533
- end
534
-
535
- markdown_table << "|#{ title } |#{ benchmark_value } MB|#{ branch_value } MB|#{ diff } MB|#{ status_emoji } |\n "
536
- end
537
-
538
- FastlaneCore ::PrintTable . print_values ( title : 'Benchmark' , config : benchmark_sizes )
539
- FastlaneCore ::PrintTable . print_values ( title : 'SDK Size' , config : branch_sizes )
540
-
541
- if is_ci
542
- if is_release || ENV [ 'GITHUB_EVENT_NAME' ] . to_s == 'push'
543
- benchmark_config [ benchmark_key ] = branch_sizes
544
- File . write ( sdk_size_path , JSON . pretty_generate ( benchmark_config ) )
545
- Dir . chdir ( File . dirname ( sdk_size_path ) ) do
546
- if sh ( 'git status -s' , log : false ) . to_s . empty?
547
- UI . important ( 'No changes in SDK sizes benchmarks.' )
548
- else
549
- sh ( 'git add -A' )
550
- sh ( "git commit -m 'Update #{ sdk_size_path } '" )
551
- sh ( 'git push' )
552
- end
553
- end
554
- end
555
-
556
- create_pr_comment ( pr_num : ENV . fetch ( 'GITHUB_PR_NUM' ) , text : markdown_table , edit_last_comment_with_text : table_header )
557
- end
558
-
559
- UI . user_error! ( "#{ table_header } benchmark failed." ) if markdown_table . include? ( fail_status )
483
+ sizes = options [ :sizes ] || frameworks_sizes
484
+ show_sdk_size ( branch_sizes : sizes , github_repo : github_repo )
485
+ update_img_shields_sdk_sizes ( sizes : sizes , open_pr : options [ :open_pr ] ) if options [ :update_readme ]
560
486
end
561
487
562
- desc 'Update img shields SDK size labels'
563
- lane :update_img_shields_sdk_sizes do
564
- sizes = frameworks_sizes
565
-
566
- # Read the file into a string
567
- readme_path = '../README.md'
568
- readme_content = File . read ( readme_path )
569
-
570
- # Define the new value for the badge
571
- stream_chat_swiftui_size = "#{ sizes [ :StreamChatSwiftUI ] } MB"
572
-
573
- # Replace the value in the badge URL
574
- readme_content . gsub! ( %r{(https://img.shields.io/badge/StreamChatSwiftUI-)(.*?)(-blue)} , "\\ 1#{ stream_chat_swiftui_size } \\ 3" )
575
-
576
- # Write the updated content back to the file
577
- File . write ( readme_path , readme_content )
578
-
579
- # Notify success
580
- UI . success ( 'Successfully updated the SDK size labels in README.md!' )
488
+ lane :update_img_shields_sdk_sizes do |options |
489
+ update_sdk_size_in_readme (
490
+ open_pr : options [ :open_pr ] || false ,
491
+ readme_path : 'README.md' ,
492
+ sizes : options [ :sizes ] || frameworks_sizes
493
+ )
581
494
end
582
495
583
496
def frameworks_sizes
@@ -603,74 +516,7 @@ def frameworks_sizes
603
516
604
517
frameworks_path = "../#{ archive_dir } /Products/Applications/DemoAppSwiftUI.app/Frameworks"
605
518
stream_chat_swiftui_size = File . size ( "#{ frameworks_path } /StreamChatSwiftUI.framework/StreamChatSwiftUI" )
606
- stream_chat_swiftui_size_mb = ( ( stream_chat_swiftui_size + assets_thinned_size ) . to_f / 1024 / 1024 ) . round ( 2 )
607
-
608
- {
609
- StreamChatSwiftUI : stream_chat_swiftui_size_mb
610
- }
611
- end
612
-
613
- private_lane :create_pr do |options |
614
- options [ :base_branch ] ||= 'develop'
615
- sh ( "git checkout -b #{ options [ :head_branch ] } " )
616
- sh ( 'git add -A' )
617
- sh ( "git commit -m '#{ options [ :title ] } '" )
618
- push_to_git_remote ( tags : false )
619
-
620
- create_pull_request (
621
- api_token : ENV . fetch ( 'GITHUB_TOKEN' , nil ) ,
622
- repo : github_repo ,
623
- title : options [ :title ] ,
624
- head : options [ :head_branch ] ,
625
- base : options [ :base_branch ] ,
626
- body : 'This PR was created automatically by CI.'
627
- )
628
- end
629
-
630
- private_lane :create_pr_comment do |options |
631
- if is_ci && !options [ :pr_num ] . to_s . empty?
632
- last_comment = sh ( "gh pr view #{ options [ :pr_num ] } --json comments --jq '.comments | map(select(.author.login == \" Stream-SDK-Bot\" )) | last'" )
633
- edit_last_comment = options [ :edit_last_comment_with_text ] && last_comment . include? ( options [ :edit_last_comment_with_text ] ) ? '--edit-last' : ''
634
- sh ( "gh pr comment #{ options [ :pr_num ] } #{ edit_last_comment } -b '#{ options [ :text ] } '" )
635
- end
636
- end
637
-
638
- lane :current_branch do
639
- branch = if ENV [ 'GITHUB_PR_NUM' ] . to_s . empty?
640
- git_branch
641
- else
642
- sh ( "gh pr view #{ ENV . fetch ( 'GITHUB_PR_NUM' ) } --json headRefName -q .headRefName" ) . strip
643
- end
644
-
645
- UI . important ( "Current branch: #{ branch } 🕊️" )
646
- branch
647
- end
648
-
649
- private_lane :git_status do |options |
650
- UI . user_error! ( 'Extension should be provided' ) unless options [ :ext ]
651
-
652
- untracked_files = sh ( 'git status -s' , log : false ) . split ( "\n " ) . map ( &:strip )
653
- UI . important ( "Git Status: #{ untracked_files } " )
519
+ stream_chat_swiftui_size_kb = ( ( stream_chat_swiftui_size + assets_thinned_size ) . to_f / 1024 )
654
520
655
- deleted_files = select_files_from ( files : untracked_files , with_extension : options [ :ext ] , that_start_with : 'D' )
656
- added_files = select_files_from ( files : untracked_files , with_extension : options [ :ext ] , that_start_with : [ 'A' , '??' ] )
657
- renamed_files = select_files_from ( files : untracked_files , with_extension : options [ :ext ] , that_start_with : 'R' )
658
- modified_files = select_files_from ( files : untracked_files , with_extension : options [ :ext ] , that_start_with : 'M' )
659
-
660
- renamed_files . each do |renamed_file |
661
- content = renamed_file . split . drop ( 1 ) . join . split ( '->' ) . map ( &:strip )
662
- deleted_files << content . first
663
- added_files << content . last
664
- end
665
- { a : added_files , d : deleted_files , m : modified_files }
666
- end
667
-
668
- def select_files_from ( files :, with_extension :, that_start_with :)
669
- files . select do |f |
670
- f . start_with? ( *that_start_with )
671
- end . map do |f |
672
- f . split . drop ( 1 ) . join ( ' ' )
673
- end . select do |f |
674
- f . gsub ( /['"]/ , '' ) . end_with? ( with_extension )
675
- end
521
+ { StreamChatSwiftUI : stream_chat_swiftui_size_kb }
676
522
end
0 commit comments