-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
95 lines (80 loc) · 2.01 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
require 'nokogiri'
$:<< File.join(File.dirname(__FILE__), 'rubylib')
require 'android_version'
VERSION_ATTRIBUTE = 'android:versionName'
VERSION_CODE = 'android:versionCode'
ANDROID_MANIFEST = "TeddyHyde/src/main/AndroidManifest.xml"
def bump_point( current )
AndroidVersion.point( current )
end
def get_version_and_code( node )
current = node[VERSION_ATTRIBUTE]
code = node[VERSION_CODE]
[ current, code ]
end
def extract_current_and_code_from_xml( xml, bump=false )
# read and parse the old file
current = nil
code = nil
new_version = nil
new_code = nil
# replace \n and any additional whitespace with a space
xml.xpath("/manifest").each do |node|
tuple = get_version_and_code(node)
current = tuple.shift
code = tuple.shift
puts "Current version: #{current}/#{code}"
if bump
new_version = bump_point(current)
new_code = code.to_i + 1
node[VERSION_ATTRIBUTE] = new_version
node[VERSION_CODE] = new_code
puts "New version: #{new_version}/#{new_code}"
end
end
[ current, code ]
end
def get_xml
file = File.read( ANDROID_MANIFEST )
xml = Nokogiri::XML(file)
end
def version( bump=false )
xml = get_xml()
extract_current_and_code_from_xml( xml, bump )
if bump
# save the output into a new file
File.open( ANDROID_MANIFEST, "w") do |f|
f.write xml.to_xml
end
end
end
namespace :version do
desc "Tag current version and code"
task :commit_and_tag do
xml = get_xml()
tuple = extract_current_and_code_from_xml( xml )
current = tuple.shift
code = tuple.shift
# Do git tag
the_tag = "#{current}-#{code}"
`git add TeddyHyde/src/main/AndroidManifest.xml`
`git commit -m "Version upgrade: #{the_tag}"`
`git tag "#{the_tag}"`
end
desc "Current version"
task :current do
version()
end
desc "Point version"
task :point do
version(true)
end
desc "Major version change"
task :major do
puts "NYI"
end
desc "Minor version change"
task :minor do
puts "NYI"
end
end