@@ -9,35 +9,20 @@ def run(params)
99
1010 update_submodules params
1111
12+ return unless @android_update_needed || @ios_update_needed
13+
1214 @android_subdir = File . expand_path 'android' , '.'
1315 @ios_subdir = File . expand_path 'ios' , '.'
1416
1517 # Update embedded Android SDK
16- update_android_jar
18+ update_android_jar if @android_update_needed
1719
1820 # Update embedded iOS SDK
19- update_ios_branch_source
20- update_branch_podspec_from_submodule
21- adjust_rnbranch_xcodeproj
22-
23- %w{
24- examples/testbed_native_ios
25- examples/webview_example_native_ios
26- .
27- } . each { |f | other_action . yarn package_path : File . join ( ".." , f , "package.json" ) }
28-
29- %w{
30- examples/testbed_native_ios
31- examples/webview_example_native_ios
32- native-tests/ios
33- } . each do |folder |
34- other_action . cocoapods (
35- # relative to fastlane folder when using other_action
36- podfile : File . join ( ".." , folder , "Podfile" ) ,
37- silent : true ,
38- use_bundle_exec : true
39- )
40- other_action . git_add ( path : File . join ( ".." , folder ) )
21+ if @ios_update_needed
22+ update_ios_branch_source
23+ update_branch_podspec_from_submodule
24+ adjust_rnbranch_xcodeproj
25+ update_pods_in_tests_and_examples
4126 end
4227
4328 commit if params [ :commit ]
@@ -75,7 +60,11 @@ def git_q_flag
7560 end
7661
7762 def commit
78- sh "git commit -a -m'[Fastlane] Branch native SDK update: Android #{ @android_version } , iOS #{ @ios_version } '"
63+ message = "[Fastlane] Branch native SDK update:"
64+ message << " #{ @android_version } (Android)," if @android_update_needed
65+ message << " #{ @ios_version } (iOS)" if @ios_update_needed
66+
67+ sh "git" , "commit" , "-a" , "-m" , message . chomp ( "," )
7968 end
8069
8170 def update_submodules ( params )
@@ -85,6 +74,9 @@ def update_submodules(params)
8574 folder = "native-sdks/#{ platform } "
8675 Dir . chdir ( folder ) do
8776 UI . message "Updating submodule in #{ folder } "
77+
78+ original_commit = current_commit
79+
8880 sh "git checkout#{ git_q_flag } master"
8981 sh "git pull --tags#{ git_q_flag } " # Pull all available branch refs so anything can be checked out
9082 key = "#{ platform } _checkout" . to_sym
@@ -97,13 +89,24 @@ def update_submodules(params)
9789 version = checkout_last_git_tag
9890 end
9991
92+ update_needed = current_commit != original_commit
93+
10094 instance_variable_set "@#{ platform } _version" , version
95+ instance_variable_set "@#{ platform } _update_needed" , update_needed
10196
102- UI . success "Updated submodule in #{ folder } "
97+ if update_needed
98+ UI . success "Updated submodule in #{ folder } "
99+ else
100+ UI . message "#{ folder } is current. No update required."
101+ end
103102 end
104103 end
105104 end
106105
106+ def current_commit
107+ `git rev-list HEAD --max-count=1`
108+ end
109+
107110 def update_android_jar
108111 jar = Dir [ 'native-sdks/android/Branch*.jar' ] . reject { |j | j =~ /core/ } . first
109112 version = jar . sub ( /^.*Branch-/ , '' ) . sub ( /\. jar$/ , '' )
@@ -114,9 +117,9 @@ def update_android_jar
114117 # Remove the old and add the new
115118 Dir . chdir ( "#{ @android_subdir } /libs" ) do
116119 old_jars = Dir [ 'Branch*.jar' ]
117- sh "cp #{ jar_path } ."
118- sh "git add Branch-#{ version } .jar"
119- sh "git rm -f #{ old_jars . join ' ' } "
120+ sh "cp" , jar_path , " ."
121+ sh "git" , " add" , " Branch-#{ version } .jar"
122+ sh "git" , "rm" , "-f" , * old_jars unless old_jars . empty?
120123 end
121124
122125 # Patch build.gradle
@@ -138,8 +141,9 @@ def update_branch_podspec_from_submodule
138141 branch_sdk_podspec_path = "#{ @ios_subdir } /Branch-SDK.podspec"
139142
140143 # Copy the podspec from the submodule
141- sh "cp native-sdks/ios/Branch.podspec #{ branch_sdk_podspec_path } "
142- UI . user_error! "Unable to update #{ branch_sdk_podspec_path } " unless $?. exitstatus == 0
144+ sh "cp" , "native-sdks/ios/Branch.podspec" , branch_sdk_podspec_path do |status |
145+ UI . user_error! "Unable to update #{ branch_sdk_podspec_path } " unless status . success?
146+ end
143147
144148 # Change the pod name to Branch-SDK
145149 other_action . patch (
@@ -160,6 +164,36 @@ def update_branch_podspec_from_submodule
160164 UI . success "Updated ios/Branch-SDK.podspec"
161165 end
162166
167+ def update_pods_in_tests_and_examples
168+ # Updates to CocoaPods for unit tests and examples (requires
169+ # node_modules for each)
170+ %w{
171+ examples/testbed_native_ios
172+ examples/webview_example_native_ios
173+ .
174+ } . each do |folder |
175+ other_action . yarn package_path : File . join ( ".." , folder , "package.json" )
176+
177+ pods_folder = folder
178+
179+ # The Podfile there installs from node_modules in the repo root.
180+ pods_folder = "native-tests/ios" if folder == "."
181+
182+ other_action . cocoapods (
183+ # relative to fastlane folder when using other_action
184+ podfile : File . join ( ".." , pods_folder , "Podfile" ) ,
185+ silent : true ,
186+ use_bundle_exec : true
187+ )
188+
189+ other_action . git_add ( path : File . join ( ".." , pods_folder ) )
190+
191+ # node_modules only required for pod install. Remove to speed up
192+ # subsequent calls to yarn.
193+ sh "rm" , "-fr" , File . join ( folder , "node_modules" )
194+ end
195+ end
196+
163197 def adjust_rnbranch_xcodeproj
164198 @project = Xcodeproj ::Project . open "#{ @ios_subdir } /RNBranch.xcodeproj"
165199 # check_file_refs
0 commit comments