forked from lkorth/device-automator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
112 lines (88 loc) · 3.08 KB
/
Rakefile
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
109
110
111
require 'rake'
require 'io/console'
task :default => :tests
desc "Run Android lint"
task :lint do
sh "./gradlew clean lint"
end
desc "Run Android unit tests and tests on a device or emulator"
task :tests => [:unit_tests, :integration_tests]
desc "Run Android unit tests"
task :unit_tests => :lint do
sh "./gradlew --continue testRelease"
end
desc "Run Android tests on a device or emulator"
task :integration_tests do
output = `adb devices`
if output.match(/device$/)
sh "./gradlew --continue connectedAndroidTest"
else
puts "Please connect a device or start an emulator and try again"
exit 1
end
end
desc "Interactive release to publish new version"
task :release => :unit_tests do
Rake::Task["assumptions"].invoke
puts "What version are you releasing? (x.x.x format)"
version = $stdin.gets.chomp
update_version(version)
update_readme_version(version)
prompt_for_sonatype_username_and_password
sh "./gradlew clean :DeviceAutomator:publishToSonatype"
sh "./gradlew closeAndReleaseRepository"
post_release(version)
end
def post_release(version)
puts "\nArchives are uploaded! Committing and tagging #{version} and preparing for the next development iteration"
sh "git commit -am 'Release #{version}'"
sh "git tag #{version} -a -m 'Release #{version}'"
version_values = version.split('.')
version_values[2] = version_values[2].to_i + 1
update_version("#{version_values.join('.')}-SNAPSHOT")
increment_version_code
sh "git commit -am 'Prepare for deployment'"
puts "\nDone. 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}"
end
task :assumptions do
puts "Release Assumptions"
puts "* [ ] You are on the branch and commit you want to release."
puts "* [ ] You have already merged hotfixes and pulled changes."
puts "* [ ] You have already reviewed the diff between the current release and the last tag, noting breaking changes in the semver and CHANGELOG."
puts "* [ ] Tests (rake integration_tests) are passing, manual verifications complete."
puts "Ready to release? Press any key to continue. "
$stdin.gets
end
def prompt_for_sonatype_username_and_password
puts "Enter Sonatype username:"
ENV["SONATYPE_USERNAME"] = $stdin.gets.chomp
puts "Enter Sonatype password:"
ENV["SONATYPE_PASSWORD"] = $stdin.noecho(&:gets).chomp
end
def increment_version_code
new_build_file = ""
File.foreach("build.gradle") 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('build.gradle', new_build_file)
end
def update_version(version)
IO.write("build.gradle",
File.open("build.gradle") do |file|
file.read.gsub(/^version '\d+\.\d+\.\d+(-SNAPSHOT)?'/, "version '#{version}'")
end
)
end
def update_readme_version(version)
IO.write("README.md",
File.open("README.md") do |file|
file.read.gsub(/:device-automator:\d+\.\d+\.\d+'/, ":device-automator:#{version}'")
end
)
end