Skip to content

Commit 6eb6721

Browse files
authored
Merge pull request #303 from BranchMetrics/automation-updates
Automation updates
2 parents e459150 + f2f6f60 commit 6eb6721

File tree

4 files changed

+73
-41
lines changed

4 files changed

+73
-41
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
source "https://rubygems.org"
22

33
gem "cocoapods", "~> 1.2"
4-
gem "fastlane", "~> 2.26"
4+
gem "fastlane", "~> 2.69"
55
gem "rubocop"
66
gem "travis"
77

Gemfile.lock

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ GEM
7979
faraday_middleware (0.12.2)
8080
faraday (>= 0.7.4, < 1.0)
8181
fastimage (2.1.0)
82-
fastlane (2.68.2)
82+
fastlane (2.69.0)
8383
CFPropertyList (>= 2.3, < 3.0.0)
8484
addressable (>= 2.3, < 3.0.0)
8585
babosa (>= 1.0.2, < 2.0.0)
@@ -107,7 +107,7 @@ GEM
107107
slack-notifier (>= 1.3, < 2.0.0)
108108
terminal-notifier (>= 1.6.2, < 2.0.0)
109109
terminal-table (>= 1.4.5, < 2.0.0)
110-
tty-screen (~> 0.6.2)
110+
tty-screen (~> 0.6.3)
111111
word_wrap (~> 1.0.0)
112112
xcodeproj (>= 1.5.2, < 2.0.0)
113113
xcpretty (>= 0.2.4, < 1.0.0)
@@ -185,20 +185,18 @@ GEM
185185
pusher-client (0.6.2)
186186
json
187187
websocket (~> 1.0)
188-
rainbow (2.2.2)
189-
rake
190-
rake (12.3.0)
188+
rainbow (3.0.0)
191189
representable (3.0.4)
192190
declarative (< 0.1.0)
193191
declarative-option (< 0.2.0)
194192
uber (< 0.2.0)
195193
retriable (3.1.1)
196194
rouge (2.0.7)
197-
rubocop (0.51.0)
195+
rubocop (0.52.0)
198196
parallel (~> 1.10)
199-
parser (>= 2.3.3.1, < 3.0)
197+
parser (>= 2.4.0.2, < 3.0)
200198
powerpack (~> 0.1)
201-
rainbow (>= 2.2.2, < 3.0)
199+
rainbow (>= 2.2.2, < 4.0)
202200
ruby-progressbar (~> 1.7)
203201
unicode-display_width (~> 1.0, >= 1.0.1)
204202
ruby-macho (1.1.0)
@@ -251,7 +249,7 @@ PLATFORMS
251249

252250
DEPENDENCIES
253251
cocoapods (~> 1.2)
254-
fastlane (~> 2.26)
252+
fastlane (~> 2.69)
255253
fastlane-plugin-branch
256254
fastlane-plugin-patch
257255
fastlane-plugin-yarn

fastlane/Fastfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
actions_path("lib")
22

3-
fastlane_version "2.26.1"
3+
fastlane_version "2.69.0"
44

55
default_platform :ios
66

fastlane/lib/update_native_sdks.rb

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)