-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
200 lines (185 loc) · 8.48 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
require 'bundler/gem_tasks'
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
require 'rbeapi/version'
task :build do
system 'gem build rbeapi.gemspec'
end
# rubocop:disable Style/FormatStringToken
RPM_OPTS = '--define "_topdir %(pwd)/rpmbuild" --define "_builddir ' \
'%{_topdir}" --define "_rpmdir %(pwd)/rpms" --define "_srcrpmdir ' \
'%{_rpmdir}" --define "_sourcedir %(pwd)" --define "_specdir %(pwd)" '\
'-bb'.freeze
# rubocop:enable Style/FormatStringToken
desc 'Generate regular and puppet-enterprise rbeapi RPMs for EOS'
task rpm: :build do
system "sed -e 's/^Version:.*/Version: #{Rbeapi::VERSION}/g' " \
'rbeapi.spec.tmpl > rbeapi.spec'
system "rpmbuild #{RPM_OPTS} rbeapi.spec"
RPMS = `find rpms/noarch -name "*rbeapi*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
end
desc 'Package the inifile gem in to regular and puppet-enterprise RPMs for EOS'
task :inifile do
# Get the latest version info
INIFILE_VERSION = `wget -q --output-document=- \
https://rubygems.org/gems/inifile/versions.atom | \
awk '/title>inifile/ {match($2, \"[0-9.]+\", a); print a[0]; exit}'`.strip
system "gem fetch inifile --version '=#{INIFILE_VERSION}'"
puts "Building rpm for inifile (#{INIFILE_VERSION})"
system "sed -e 's/^Version:.*/Version: #{INIFILE_VERSION}/g' " \
'gems/inifile/inifile.spec.tmpl > gems/inifile/inifile.spec'
system "rpmbuild #{RPM_OPTS} gems/inifile/inifile.spec"
RPMS = `find rpms/noarch -name "*inifile*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
end
desc 'Package the net_http_unix gem in to an RPM for EOS'
task :net_http_unix do
# Get the latest version info
NET_HTTP_VERSION = `wget -q --output-document=- \
https://rubygems.org/gems/net_http_unix/versions.atom | awk \
'/title>net_http_unix/ {match($2, \"[0-9.]+\", a); print a[0]; exit}'`.strip
system "gem fetch net_http_unix --version '=#{NET_HTTP_VERSION}'"
puts "Building rpm for net_http_unix (#{NET_HTTP_VERSION})"
system "sed -e 's/^Version:.*/Version: #{NET_HTTP_VERSION}/g' " \
'gems/net_http_unix/net_http_unix.spec.tmpl > ' \
'gems/net_http_unix/net_http_unix.spec'
system "rpmbuild #{RPM_OPTS} gems/net_http_unix/net_http_unix.spec"
RPMS = `find rpms/noarch -name "*net_http_unix*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
end
desc 'Package the netaddr gem in to regular and puppet-enterprise RPMs for EOS'
task :netaddr do
# Get the latest version info
NETADDR_VERSION = `wget -q --output-document=- \
https://rubygems.org/gems/netaddr/versions.atom | \
awk '/title>netaddr/ {match($2, \"[0-9.]+\", a); print a[0]; exit}'`.strip
system "gem fetch netaddr --version '=#{NETADDR_VERSION}'"
puts "Building rpm for netaddr (#{NETADDR_VERSION})"
system "sed -e 's/^Version:.*/Version: #{NETADDR_VERSION}/g' " \
'gems/netaddr/netaddr.spec.tmpl > gems/netaddr/netaddr.spec'
system "rpmbuild #{RPM_OPTS} gems/netaddr/netaddr.spec"
RPMS = `find rpms/noarch -name "*netaddr*rpm"`.freeze
puts "\n################################################\n#"
puts "Created the following in rpms/noarch/\n#{RPMS}"
puts "#\n################################################\n\n"
end
desc 'Generate all RPM packages needed for an EOS SWIX'
task all_rpms: :build do
Rake::Task['rpm'].invoke
Rake::Task['inifile'].invoke
Rake::Task['net_http_unix'].invoke
Rake::Task['netaddr'].invoke
puts 'RPMs are available in rpms/noarch/'
puts "Copy the RPMs to an EOS device then run the 'swix create' command."
puts ' Examples: '
puts ' Chef client: '
puts ' cd /mnt/flash; \\'
puts " swix create rbeapi-chef-#{Rbeapi::VERSION}-1.swix \\"
puts " rubygem-rbeapi-chef-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \\"
puts ' rubygem-inifile-chef-3.0.0-5.eos4.noarch.rpm \\'
puts ' rubygem-netaddr-chef-1.5.1-4.eos4.noarch.rpm \\'
puts ' rubygem-net_http_unix-chef-0.2.2-5.eos4.noarch.rpm'
puts ' Puppet Open Source: '
puts ' cd /mnt/flash; \\'
puts " swix create rbeapi-#{Rbeapi::VERSION}-1.swix \\"
puts " rubygem-rbeapi-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \\"
puts ' rubygem-inifile-3.0.0-5.eos4.noarch.rpm \\'
puts ' rubygem-netaddr-1.5.1-4.eos4.noarch.rpm \\'
puts ' rubygem-net_http_unix-0.2.2-5.eos4.noarch.rpm'
puts ' Puppet-enterprise agent (3.x): '
puts ' cd/mnt/flash; \\'
puts " swix create rbeapi-puppet3-#{Rbeapi::VERSION}-1.swix \\"
puts " rubygem-rbeapi-puppet3-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \\"
puts ' rubygem-inifile-puppet3-3.0.0-5.eos4.noarch.rpm \\'
puts ' rubygem-netaddr-puppet3-1.5.1-4.eos4.noarch.rpm'
puts ' Puppet-All-in-one agent (2015.x/4.x): '
puts ' cd/mnt/flash; \\'
puts " swix create rbeapi-puppet-aio-#{Rbeapi::VERSION}-1.swix \\"
puts " rubygem-rbeapi-puppet-aio-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \\"
puts ' rubygem-inifile-puppet-aio-3.0.0-5.eos4.noarch.rpm \\'
puts ' rubygem-netaddr-puppet-aio-1.5.1-4.eos4.noarch.rpm \\'
puts ' rubygem-net_http_unix-puppet-aio-0.2.2-5.eos4.noarch.rpm'
end
desc 'Generate SWIX files from RPMs'
task swix: :all_rpms do
SWIX = 'PYTHONPATH=${PYTHONPATH}:/nfs/misc/tools/swix \
/nfs/misc/tools/swix/swix'.freeze
system "(cd rpms/noarch;
rm -f rbeapi-#{Rbeapi::VERSION}-1.swix;
#{SWIX} create rbeapi-#{Rbeapi::VERSION}-1.swix \
rubygem-rbeapi-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \
rubygem-inifile-3.0.0-5.eos4.noarch.rpm \
rubygem-netaddr-1.5.1-4.eos4.noarch.rpm \
rubygem-net_http_unix-0.2.2-5.eos4.noarch.rpm)"
system "(cd rpms/noarch;
rm -f rbeapi-chef-#{Rbeapi::VERSION}-1.swix;
#{SWIX} create rbeapi-chef-#{Rbeapi::VERSION}-1.swix \
rubygem-rbeapi-chef-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \
rubygem-inifile-chef-3.0.0-5.eos4.noarch.rpm \
rubygem-netaddr-chef-1.5.1-4.eos4.noarch.rpm)"
system "(cd rpms/noarch;
rm -f rbeapi-puppet3-#{Rbeapi::VERSION}-1.swix;
#{SWIX} create rbeapi-puppet3-#{Rbeapi::VERSION}-1.swix \
rubygem-rbeapi-puppet3-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \
rubygem-inifile-puppet3-3.0.0-5.eos4.noarch.rpm \
rubygem-netaddr-puppet3-1.5.1-4.eos4.noarch.rpm)"
system "(cd rpms/noarch;
rm -f rbeapi-puppet-aio-#{Rbeapi::VERSION}-1.swix;
#{SWIX} create rbeapi-puppet-aio-#{Rbeapi::VERSION}-1.swix \
rubygem-rbeapi-puppet-aio-#{Rbeapi::VERSION}-1.eos4.noarch.rpm \
rubygem-inifile-puppet-aio-3.0.0-5.eos4.noarch.rpm \
rubygem-netaddr-puppet-aio-1.5.1-4.eos4.noarch.rpm \
rubygem-net_http_unix-puppet-aio-0.2.2-5.eos4.noarch.rpm)"
SWIXS = `find rpms/noarch -name "rbeapi*swix" -ls`.freeze
puts "\n################################################\n#"
puts "The following artifacts are in rpms/noarch/\n#{SWIXS}"
puts "#\n################################################\n\n"
end
task release: :build do
system "gem push rbeapi-#{Rbeapi::VERSION}.gem"
end
require 'ci/reporter/rake/rspec'
desc 'Prep CI RSpec tests'
task :ci_prep do
require 'rubygems'
begin
gem 'ci_reporter'
require 'ci/reporter/rake/rspec'
ENV['CI_REPORTS'] = 'results'
rescue LoadError
puts 'Missing ci_reporter gem. You must have the ci_reporter gem installed'\
' to run the CI spec tests'
end
end
desc 'Run the CI RSpec tests'
task ci_spec: [:ci_prep, 'ci:setup:rspec', :spec]
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(:unit) do |t|
t.pattern = './**/unit/**/*_spec.rb'
end
RSpec::Core::RakeTask.new(:system) do |t|
t.pattern = './**/system/**/*_spec.rb'
end
desc 'Generate typedoc.rst for the guide'
task :typedoc do
system 'rbeapi doc -r type \
| awk \'/This page/{flag=1}/augeas/{flag=0}/eos_/{flag=1}/ exec/\
{flag=0}/\*This page/{flag=1}flag\' \
| pandoc --from=markdown --to=rst --output=- \
> guide/typedoc.rst'
end
desc 'Generate Getting Started Guide HTML'
task guide: [:typedoc] do
system 'make -C guide html'
end
desc 'Clean Getting Started docs'
task :guide_clean do
system 'make -C guide clean'
end