Skip to content

Commit 4fbc5ca

Browse files
committed
[CI] Share fastlane lanes across platforms
1 parent 2c8d222 commit 4fbc5ca

File tree

5 files changed

+22
-176
lines changed

5 files changed

+22
-176
lines changed

.github/workflows/cron-checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ name: Cron Checks
22

33
on:
44
schedule:
5-
# Runs "At 02:00 every night"
6-
- cron: '0 2 * * *'
5+
# Runs "At 02:00 every night except weekends"
6+
- cron: '0 2 * * 1-5'
77

88
workflow_dispatch:
99

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fastlane/screenshots
7171
fastlane/test_output
7272
fastlane/allurectl
7373
fastlane/xcresults
74-
fastlane/metrics
74+
**/metrics/
7575
fastlane/recordings
7676
StreamChatCore.framework.coverage.txt
7777
StreamChatCoreTests.xctest.coverage.txt

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ GEM
199199
fastlane
200200
pry
201201
fastlane-plugin-sonarcloud_metric_kit (0.2.1)
202-
fastlane-plugin-stream_actions (0.3.38)
202+
fastlane-plugin-stream_actions (0.3.56)
203203
xctest_list (= 1.2.1)
204204
fastlane-plugin-versioning (0.5.2)
205205
ffi (1.17.0)
@@ -427,7 +427,7 @@ DEPENDENCIES
427427
fastlane-plugin-create_xcframework
428428
fastlane-plugin-lizard
429429
fastlane-plugin-sonarcloud_metric_kit
430-
fastlane-plugin-stream_actions (= 0.3.38)
430+
fastlane-plugin-stream_actions (= 0.3.56)
431431
fastlane-plugin-versioning
432432
jazzy
433433
json

fastlane/Fastfile

Lines changed: 16 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,15 @@ sdk_names = ['StreamChatSwiftUI']
1313
github_repo = ENV['GITHUB_REPOSITORY'] || 'GetStream/stream-chat-swiftui'
1414
derived_data_path = 'derived_data'
1515
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"
1816
buildcache_xcargs = 'CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++'
1917
is_localhost = !is_ci
2018
project_package_resolved = "#{xcode_project}/project.xcworkspace/xcshareddata/swiftpm/Package.resolved"
2119
@force_check = false
2220

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-
2821
before_all do |lane|
2922
if is_ci
3023
setup_ci
31-
sh('git config --global user.name "Stream Bot"')
24+
setup_git_config
3225
xcversion(version: xcode_version) unless [:publish_release, :allure_launch, :allure_upload, :copyright, :pod_lint].include?(lane)
3326
end
3427
end
@@ -152,7 +145,7 @@ lane :merge_release_to_main do |options|
152145

153146
comment = "[Publication of the release](https://github.com/#{github_repo}/actions/workflows/release-publish.yml) has been launched 👍"
154147
UI.important(comment)
155-
create_pr_comment(pr_num: ENV.fetch('GITHUB_PR_NUM'), text: comment)
148+
pr_comment(text: comment)
156149
end
157150

158151
lane :merge_main_to_develop do
@@ -234,7 +227,7 @@ lane :test_ui do |options|
234227
png_files.each { |png| sh("git add #{png}") || true }
235228
sh('git restore .')
236229

237-
create_pr(
230+
pr_create(
238231
title: '[CI] Snapshots',
239232
base_branch: current_branch,
240233
head_branch: "#{current_branch}-snapshots"
@@ -448,21 +441,7 @@ lane :rubocop do
448441
end
449442

450443
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')
466445
end
467446

468447
desc 'Remove UI Snapshots'
@@ -492,92 +471,26 @@ lane :copyright do
492471
update_copyright(ignore: [derived_data_path, source_packages_path, 'vendor/'])
493472
next unless is_ci
494473

495-
create_pr(
474+
pr_create(
496475
title: '[CI] Update Copyright',
497476
head_branch: "ci/update-copyright-#{Time.now.to_i}"
498477
)
499478
end
500479

501-
desc 'Show current frameworks size'
502480
lane :show_frameworks_sizes do |options|
503481
next unless is_check_required(sources: sources_matrix[:size], force_check: @force_check)
504482

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]
560486
end
561487

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+
)
581494
end
582495

583496
def frameworks_sizes
@@ -603,74 +516,7 @@ def frameworks_sizes
603516

604517
frameworks_path = "../#{archive_dir}/Products/Applications/DemoAppSwiftUI.app/Frameworks"
605518
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)
654520

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 }
676522
end

fastlane/Pluginfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44

55
gem 'fastlane-plugin-versioning'
66
gem 'fastlane-plugin-sonarcloud_metric_kit'
7-
gem 'fastlane-plugin-stream_actions', '0.3.38'
7+
gem 'fastlane-plugin-stream_actions', '0.3.56'
88
gem 'fastlane-plugin-create_xcframework'

0 commit comments

Comments
 (0)