forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.rake
91 lines (80 loc) · 2.98 KB
/
version.rake
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
require 'yaml'
VERSION_FILE = "versions.yml"
README_FILE = "README.md"
INDEX_SHARED1_FILE = "docs/index-shared1.asciidoc"
def get_versions
yaml_versions = YAML.safe_load(IO.read(VERSION_FILE))
{
"logstash" => yaml_versions["logstash"],
"logstash-core" => yaml_versions["logstash-core"],
"logstash-core-plugin-api" => yaml_versions["logstash-core-plugin-api"],
}
end
# Update the version file, keeping the comments in tact
def update_version_file(old_version, new_version)
versions_as_text = IO.read(VERSION_FILE)
%w(logstash logstash-core logstash-core-plugin-api).each do |field|
versions_as_text.gsub!(/(?<=#{field}: )#{old_version[field]}/, "#{new_version[field]}")
end
IO.write(VERSION_FILE, versions_as_text)
end
def update_index_shared1(new_version)
index_shared1 = IO.read(INDEX_SHARED1_FILE)
old_version = index_shared1.match(':logstash_version:\s+(?<logstash_version>\d[.]\d[.]\d.*)')[:logstash_version]
%w(logstash elasticsearch kibana).each do |field|
index_shared1.gsub!(/(:#{field}_version:\s+)#{old_version}/) { "#{$1}#{new_version}" }
end
IO.write(INDEX_SHARED1_FILE, index_shared1)
end
def update_readme(old_version, new_version)
readme = IO.read(README_FILE)
readme.gsub!(/(logstash\-(oss\-)?)#{old_version['logstash']}/) { "#{$1}#{new_version['logstash']}" }
IO.write(README_FILE, readme)
end
namespace :version do
desc "show version of core components"
task :show do
get_versions.each do |component, version|
puts "#{component}: #{version}"
end
end
desc "set version of logstash, logstash-core"
task :set, [:version] => [:validate] do |t, args|
new_version = {}
get_versions.each do |component, version|
# we just assume that, usually, all components except
# "logstash-core-plugin-api" will be versioned together
# so let's skip this one and have a separate task for it
if component == "logstash-core-plugin-api"
new_version[component] = version
else
new_version[component] = args[:version]
end
end
old_version = YAML.safe_load(File.read(VERSION_FILE))
update_readme(old_version, new_version)
update_version_file(old_version, new_version)
end
desc "set stack version referenced in docs"
task :set_doc_version, [:version] => [:validate] do |t, args|
update_index_shared1(args[:version])
end
desc "set version of logstash-core-plugin-api"
task :set_plugin_api, [:version] => [:validate] do |t, args|
new_version = {}
get_versions.each do |component, version|
if component == "logstash-core-plugin-api"
new_version[component] = args[:version]
else
new_version[component] = version
end
end
old_version = YAML.safe_load(File.read(VERSION_FILE))
update_version_file(old_version, new_version)
end
task :validate, :version do |t, args|
unless Regexp.new('^\d+\.\d+\.\d+(?:-\w+\d+)?$').match(args[:version])
abort("Invalid version argument: \"#{args[:version]}\". Aborting...")
end
end
end