forked from braintree/braintree_android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
108 lines (88 loc) · 3.72 KB
/
Rakefile
File metadata and controls
108 lines (88 loc) · 3.72 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
require 'rake'
task :default => :tests
task :lint do
sh "./gradlew clean lint"
end
task :tests => :lint do
output = `adb devices`
if output.match(/device$/)
begin
sh "ruby script/httpsd.rb /tmp/httpsd.pid"
log_listener_pid = fork { exec 'ruby', 'script/log_listener.rb' }
sh "./gradlew --info --continue runAllTests :BraintreeData:connectedAndroidTest :BraintreeApi:connectedAndroidTest :Drop-In:connectedAndroidTest"
ensure
`kill -9 \`cat /tmp/httpsd.pid\``
`kill -9 #{log_listener_pid}`
end
else
puts "Please connect a device or start an emulator and try again"
exit 1
end
end
task :release => :lint do
braintree_android_build_file = "build.gradle"
braintree_api_build_file = "BraintreeApi/build.gradle"
braintree_drop_in_build_file = "Drop-In/build.gradle"
last_version = `git tag | tail -1`.chomp
puts "Changes since #{last_version}:"
sh "git log --pretty=format:\"%h %ad%x20%s%x20%x28%an%x29\" --date=short #{last_version}.."
puts "Please update your CHANGELOG.md. Press ENTER when you are done"
$stdin.gets
puts "What version are you releasing? (x.x.x format)"
version = $stdin.gets.chomp
increment_version_code(braintree_android_build_file)
update_version(braintree_android_build_file, version)
sh "./gradlew clean :BraintreeData:uploadArchives"
puts "BraintreeData was uploaded, press ENTER to release it"
$stdin.gets
sh "./gradlew :BraintreeData:closeAndPromoteRepository"
puts "Sleeping for 60 seconds to allow promotion to finish"
sleep 60
replace_string(braintree_api_build_file, "compile project(':BraintreeData')", "compile 'com.braintreepayments.api:data:#{version}'")
sh "./gradlew clean :BraintreeApi:uploadArchives"
puts "BraintreeApi was uploaded, press ENTER to release it"
$stdin.gets
sh "./gradlew :BraintreeApi:closeAndPromoteRepository"
puts "Sleeping for 60 seconds to allow promotion to finish"
sleep 60
replace_string(braintree_drop_in_build_file, "compile project(':BraintreeApi')", "compile 'com.braintreepayments.api:braintree-api:#{version}'")
sh "./gradlew clean :Drop-In:uploadArchives"
puts "Drop-In was uploaded, press ENTER to release it"
$stdin.gets
sh "./gradlew :Drop-In:closeAndPromoteRepository"
puts "Archives are uploaded! Committing and tagging #{version} and preparing for the next development iteration"
sh "git commit -am 'Release #{version}'"
sh "git tag #{version} -am '#{version}'"
replace_string(braintree_api_build_file, "compile 'com.braintreepayments.api:data:#{version}'", "compile project(':BraintreeData')")
replace_string(braintree_drop_in_build_file, "compile 'com.braintreepayments.api:braintree-api:#{version}'", "compile project(':BraintreeApi')")
sh "git commit -am 'Prepare for development'"
puts "Done. Commits and tags have been created. If everything appears to be in order, hit ENTER to push."
$stdin.gets
sh "git push origin master #{version}"
puts "Pushed to GHE! Press ENTER to push to public Github."
$stdin.gets
sh "git push github master #{version}"
puts "Update client_releases.yml in the docs. Press ENTER when done."
$stdin.gets
end
def increment_version_code(filepath)
new_build_file = ""
File.foreach(filepath) do |line|
if line.match(/versionCode = (\d+)/)
new_build_file += line.gsub(/versionCode = \d+/, "versionCode = #{$1.to_i + 1}")
else
new_build_file += line
end
end
IO.write(filepath, new_build_file)
end
def update_version(filepath, version)
replace_string(filepath, /versionName = '\d+\.\d+\.\d+'/, "versionName = '#{version}'")
end
def replace_string(filepath, string_to_replace, new_string)
IO.write(filepath,
File.open(filepath) do |file|
file.read.gsub(string_to_replace, new_string)
end
)
end