forked from DSI-Ville-Noumea/gasel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtag_version
55 lines (42 loc) · 1.26 KB
/
tag_version
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
#! /usr/bin/ruby
require 'xml'
$pom_files = %w<pom.xml model/pom.xml webapp/pom.xml>
def find_version_tag(doc)
tag = doc.find_first('/m:project/m:version', "m:#{doc.root.namespaces.default.href}")
tag = doc.find_first('/m:project/m:parent/m:version', "m:#{doc.root.namespaces.default.href}") \
unless tag
tag
end
def set_version(file, version)
doc = XML::Parser.file(file).parse
find_version_tag(doc).content = version
doc.save(file)
end
def set_version_all(version)
$pom_files.each do |file|
set_version file, version
end
end
def git(*args)
system "git",*args or exit $?.exitstatus
end
doc = XML::Parser.file('pom.xml').parse
p doc.root.namespaces.default.prefix
version_tag = find_version_tag(doc)
version = version_tag.content
release_version = version.sub(/-SNAPSHOT$/, '')
next_version = release_version.split(".").map{|v|v.to_i}
next_version[-1] += 1
next_version = next_version.join(".")+"-SNAPSHOT"
puts "Current: #{version}"
puts "Release: #{release_version}"
puts "Next: #{next_version}"
set_version_all release_version
tag = "v#{release_version}"
git "add",*$pom_files
git "commit","-m",tag
git "tag",tag
set_version_all next_version
git "add",*$pom_files
git "commit","-m","Move to v#{next_version}"
git "push"