This repository has been archived by the owner on Jan 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Rakefile
130 lines (101 loc) · 4.13 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
require "rspec/core/rake_task"
require "yaml"
ENV["CHORIA_RAKE"] = $$.to_s
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = "--profile" if ENV["TRAVIS"] == "true"
end
task :default => ["spec", "rubocop"]
desc "Run rubycop style checks"
task :rubocop do
sh("rubocop")
end
namespace :doc do
desc "Serve YARD documentation on %s:%d" % [ENV.fetch("YARD_BIND", "127.0.0.1"), ENV.fetch("YARD_PORT", "9292")]
task :serve do
system("yard server --reload --bind %s --port %d" % [ENV.fetch("YARD_BIND", "127.0.0.1"), ENV.fetch("YARD_PORT", "9292")])
end
desc "Generate documentatin into the %s" % ENV.fetch("YARD_OUT", "doc")
task :yard do
system("yard doc --markup markdown --output-dir %s" % ENV.fetch("YARD_OUT", "doc"))
end
end
desc "Set versions and create docs for a release"
task :prep_version do
abort("Please specify CHORIA_VERSION") unless ENV["CHORIA_VERSION"]
sh 'sed -i.bak -re \'s/(.+"version": ").+/\1%s",/\' module/choria/metadata.json' % ENV["CHORIA_VERSION"]
sh 'sed -i.bak -re \'s/(.+"version": ").+/\1%s",/\' module/tasks/metadata.json' % ENV["CHORIA_VERSION"]
sh 'sed -i.bak -re \'s/mcollective_choria(.+"version_requirement":").+?"/mcollective_choria\1%s"/\' module/tasks/metadata.json' % ENV["CHORIA_VERSION"]
sh 'sed -i.bak -re \'s/(\s+VERSION\s+=\s+").+/\1%s".freeze/\' ./lib/mcollective/util/choria.rb' % ENV["CHORIA_VERSION"]
Rake::FileList["lib/**/*.ddl"].each do |file|
sh 'sed -i.bak -re \'s/(\s+:version\s+=>\s+").+/\1%s",/\' %s' % [ENV["CHORIA_VERSION"], file]
end
changelog = File.readlines("CHANGELOG.md")
File.open("CHANGELOG.md", "w") do |cl|
changelog.each do |line|
# rubocop:disable Layout/LineLength
cl.puts line
if line =~ /^\|----------/
cl.puts "|%s| |Release %s |" % [Time.now.strftime("%Y/%m/%d"), ENV["CHORIA_VERSION"]]
end
# rubocop:enable Layout/LineLength
end
end
Rake::Task[:update_ddl].execute
sh "git add CHANGELOG.md lib module"
sh "git commit -e -m '(misc) Release %s'" % ENV["CHORIA_VERSION"]
end
desc "Update JSON DDL files"
task :update_ddl do
require "mcollective"
Dir.glob("lib/mcollective/agent/*.ddl") do |ddlfile|
next if ddlfile =~ /^choria_uril/
agent_dir = File.dirname(ddlfile)
agent_name = File.basename(ddlfile, ".ddl")
json_file = File.join(agent_dir, "%s.json" % agent_name)
ddl = MCollective::DDL.new(agent_name, :agent, false)
ddl.instance_eval(File.read(ddlfile))
data = {
"$schema" => "https://choria.io/schemas/mcorpc/ddl/v1/agent.json",
"metadata" => ddl.meta,
"actions" => []
}
ddl.actions.sort.each do |action|
data["actions"] << ddl.action_interface(action)
end
puts "Writing JSON DDL in %s" % json_file
File.open(json_file, "w") do |jddl|
jddl.print(JSON.pretty_generate(data))
end
end
end
desc "Prepare and build the Puppet modules"
task :release do
Rake::Task[:spec].execute
Rake::Task[:rubocop].execute
Rake::Task[:prep_version].execute if ENV["CHORIA_VERSION"]
["choria", "tasks"].each do |mod|
puts "=" * 20
puts "Building module %s" % mod
puts "=" * 20
puts
sh("mkdir -p module/%s/files/mcollective" % mod)
sh("rm -rf module/%s/files/mcollective/*" % mod)
sh("cp .gitignore LICENSE.txt NOTICE module/%s" % mod)
sh("cp CHANGELOG.md module/choria") if mod == "choria"
datafile = "module/%s/data/plugin.yaml" % mod
if File.exist?(datafile)
plugin = YAML.load(File.read(datafile))
files = plugin.keys.grep(/_files$/).map {|k| plugin[k]}.flatten
files.each do |file|
source = File.join("lib/mcollective", file)
target = File.join("module", mod, "files/mcollective", file)
puts "Copying plugin file: %s -> %s" % [source, target]
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(File.join("lib/mcollective", file), File.join("module", mod, "files/mcollective", file))
end
end
Dir.chdir("module/%s" % mod) do
sh("/usr/bin/env -i PATH=/bin:/usr/bin bash -e /opt/puppetlabs/pdk/bin/pdk build --force")
end
end
end