-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathupdate_version.rb
50 lines (35 loc) · 1.21 KB
/
update_version.rb
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
@version_name_regex = /VERSION_NAME=(.*)/
@version_code_regex = /VERSION_CODE=(.*)/
@file_name = "gradle.properties"
def update_version_name
text = File.read(@file_name)
versionName = @version_name_regex.match(text)[0].split('=')[1]
# 2.0.0-SNAPSHOT
versionNumber = versionName.split('-')[0]
# 2.0.0
(major, minor, patch) = versionNumber.split(".")
major = (major.to_i + 0).to_s
minor = (minor.to_i + 0).to_s
patch = (patch.to_i + 1).to_s
newVersionNumber = [major, minor, patch].join(".")
# 2.0.1
newVersionName = "#{newVersionNumber}-SNAPSHOT"
# 2.0.1-SNAPSHOT
# VERSION_NAME=2.0.0-SNAPSHOT
new_content = text.gsub(@version_name_regex, "VERSION_NAME=#{newVersionName}")
# VERSION_NAME=2.0.1-SNAPSHOT
File.open(@file_name, "w") {|file| file.puts new_content }
end
def update_version_code
text = File.read(@file_name)
versionCode = @version_code_regex.match(text)[0].split('=')[1]
# 20
newVersionCode = (versionCode.to_i + 1).to_s
# 21
# VERSION_CODE=20
new_content = text.gsub(@version_code_regex, "VERSION_CODE=#{newVersionCode}")
# VERSION_CODE=21
File.open(@file_name, "w") {|file| file.puts new_content }
end
update_version_name
update_version_code