chef-config 13.8.5 → 13.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/README.md +4 -4
- data/Rakefile +17 -17
- data/chef-config.gemspec +35 -35
- data/lib/chef-config.rb +20 -20
- data/lib/chef-config/config.rb +1113 -1113
- data/lib/chef-config/exceptions.rb +27 -27
- data/lib/chef-config/fips.rb +51 -51
- data/lib/chef-config/logger.rb +59 -59
- data/lib/chef-config/mixin/credentials.rb +57 -57
- data/lib/chef-config/mixin/dot_d.rb +38 -38
- data/lib/chef-config/mixin/fuzzy_hostname_matcher.rb +41 -41
- data/lib/chef-config/package_task.rb +289 -289
- data/lib/chef-config/path_helper.rb +283 -283
- data/lib/chef-config/version.rb +34 -34
- data/lib/chef-config/windows.rb +28 -28
- data/lib/chef-config/workstation_config_loader.rb +222 -222
- data/spec/spec_helper.rb +75 -75
- data/spec/unit/config_spec.rb +1190 -1190
- data/spec/unit/fips_spec.rb +128 -128
- data/spec/unit/path_helper_spec.rb +307 -307
- data/spec/unit/workstation_config_loader_spec.rb +510 -510
- metadata +2 -2
@@ -1,41 +1,41 @@
|
|
1
|
-
#
|
2
|
-
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
-
# License:: Apache License, Version 2.0
|
4
|
-
#
|
5
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
-
# you may not use this file except in compliance with the License.
|
7
|
-
# You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing, software
|
12
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
-
# See the License for the specific language governing permissions and
|
15
|
-
# limitations under the License.
|
16
|
-
|
17
|
-
require "fuzzyurl"
|
18
|
-
|
19
|
-
module ChefConfig
|
20
|
-
module Mixin
|
21
|
-
module FuzzyHostnameMatcher
|
22
|
-
|
23
|
-
def fuzzy_hostname_match_any?(hostname, matches)
|
24
|
-
if (!hostname.nil?) && (!matches.nil?)
|
25
|
-
return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
|
26
|
-
fuzzy_hostname_match?(hostname, m)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
false
|
31
|
-
end
|
32
|
-
|
33
|
-
def fuzzy_hostname_match?(hostname, match)
|
34
|
-
# Do greedy matching by adding wildcard if it is not specified
|
35
|
-
match = "*" + match if !match.start_with?("*")
|
36
|
-
Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
#
|
2
|
+
# Copyright:: Copyright 2016, Chef Software Inc.
|
3
|
+
# License:: Apache License, Version 2.0
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require "fuzzyurl"
|
18
|
+
|
19
|
+
module ChefConfig
|
20
|
+
module Mixin
|
21
|
+
module FuzzyHostnameMatcher
|
22
|
+
|
23
|
+
def fuzzy_hostname_match_any?(hostname, matches)
|
24
|
+
if (!hostname.nil?) && (!matches.nil?)
|
25
|
+
return matches.to_s.split(/\s*,\s*/).compact.any? do |m|
|
26
|
+
fuzzy_hostname_match?(hostname, m)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
|
33
|
+
def fuzzy_hostname_match?(hostname, match)
|
34
|
+
# Do greedy matching by adding wildcard if it is not specified
|
35
|
+
match = "*" + match if !match.start_with?("*")
|
36
|
+
Fuzzyurl.matches?(Fuzzyurl.mask(hostname: match), hostname)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,289 +1,289 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
|
3
|
-
# Copyright:: Copyright 2015-2016, Chef, Inc.
|
4
|
-
# License:: Apache License, Version 2.0
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
|
-
#
|
18
|
-
|
19
|
-
require "rake"
|
20
|
-
require "rubygems"
|
21
|
-
require "rubygems/package_task"
|
22
|
-
|
23
|
-
module ChefConfig
|
24
|
-
class PackageTask < Rake::TaskLib
|
25
|
-
|
26
|
-
# Full path to root of top-level repository. All other files (like VERSION or
|
27
|
-
# lib/<module_path>/version.rb are rooted at this path).
|
28
|
-
attr_accessor :root_path
|
29
|
-
|
30
|
-
# Name of the top-level module/library build built. This is used to define
|
31
|
-
# the top level module which contains VERSION and MODULE_ROOT.
|
32
|
-
attr_accessor :module_name
|
33
|
-
|
34
|
-
# Name of the gem being built. This is used to find the lines to fix in
|
35
|
-
# Gemfile.lock.
|
36
|
-
attr_accessor :gem_name
|
37
|
-
|
38
|
-
# Should the generated version.rb be in a class or module? Default is false (module).
|
39
|
-
attr_accessor :generate_version_class
|
40
|
-
|
41
|
-
# Paths to the roots of any components that also support ChefPackageTask.
|
42
|
-
# If relative paths are provided, they are rooted against root_path.
|
43
|
-
attr_accessor :component_paths
|
44
|
-
|
45
|
-
# This is the module name as it appears on the path "lib/module/".
|
46
|
-
# e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
|
47
|
-
# The default is module_name but lower-cased.
|
48
|
-
attr_writer :module_path
|
49
|
-
|
50
|
-
def module_path
|
51
|
-
@module_path || module_name.downcase
|
52
|
-
end
|
53
|
-
|
54
|
-
# Directory used to store package files and output that is generated.
|
55
|
-
# This has the same meaning (or lack thereof) as package_dir in
|
56
|
-
# rake/packagetask.
|
57
|
-
attr_accessor :package_dir
|
58
|
-
|
59
|
-
# Name of git remote used to push tags during a release. Default is origin.
|
60
|
-
attr_accessor :git_remote
|
61
|
-
|
62
|
-
# True if should use Chef::VersionString.
|
63
|
-
attr_accessor :use_versionstring
|
64
|
-
|
65
|
-
def initialize(root_path = nil, module_name = nil, gem_name = nil)
|
66
|
-
init(root_path, module_name, gem_name)
|
67
|
-
yield self if block_given?
|
68
|
-
define unless root_path.nil? || module_name.nil?
|
69
|
-
end
|
70
|
-
|
71
|
-
def init(root_path, module_name, gem_name)
|
72
|
-
@root_path = root_path
|
73
|
-
@module_name = module_name
|
74
|
-
@gem_name = gem_name
|
75
|
-
@component_paths = []
|
76
|
-
@module_path = nil
|
77
|
-
@package_dir = "pkg"
|
78
|
-
@git_remote = "origin"
|
79
|
-
@generate_version_class = false
|
80
|
-
end
|
81
|
-
|
82
|
-
def component_full_paths
|
83
|
-
component_paths.map { |path| File.expand_path(path, root_path) }
|
84
|
-
end
|
85
|
-
|
86
|
-
def version_rb_path
|
87
|
-
File.expand_path("lib/#{module_path}/version.rb", root_path)
|
88
|
-
end
|
89
|
-
|
90
|
-
def chef_root_path
|
91
|
-
module_name == "Chef" ? root_path : File.dirname(root_path)
|
92
|
-
end
|
93
|
-
|
94
|
-
def version_file_path
|
95
|
-
File.join(chef_root_path, "VERSION")
|
96
|
-
end
|
97
|
-
|
98
|
-
def gemfile_lock_path
|
99
|
-
File.join(root_path, "Gemfile.lock")
|
100
|
-
end
|
101
|
-
|
102
|
-
def version
|
103
|
-
IO.read(version_file_path).strip
|
104
|
-
end
|
105
|
-
|
106
|
-
def full_package_dir
|
107
|
-
File.expand_path(package_dir, root_path)
|
108
|
-
end
|
109
|
-
|
110
|
-
def class_or_module
|
111
|
-
generate_version_class ? "class" : "module"
|
112
|
-
end
|
113
|
-
|
114
|
-
def with_clean_env(&block)
|
115
|
-
if defined?(Bundler)
|
116
|
-
Bundler.with_clean_env(&block)
|
117
|
-
else
|
118
|
-
yield
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def define
|
123
|
-
raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
|
124
|
-
|
125
|
-
desc "Build Gems of component dependencies"
|
126
|
-
task :package_components do
|
127
|
-
component_full_paths.each do |component_path|
|
128
|
-
Dir.chdir(component_path) do
|
129
|
-
sh "rake package"
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
task :package => :package_components
|
135
|
-
|
136
|
-
desc "Build and install component dependencies"
|
137
|
-
task :install_components => :package_components do
|
138
|
-
component_full_paths.each do |component_path|
|
139
|
-
Dir.chdir(component_path) do
|
140
|
-
sh "rake install"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
end
|
144
|
-
|
145
|
-
task :install => :install_components
|
146
|
-
|
147
|
-
desc "Clean up builds of component dependencies"
|
148
|
-
task :clobber_component_packages do
|
149
|
-
component_full_paths.each do |component_path|
|
150
|
-
Dir.chdir(component_path) do
|
151
|
-
sh "rake clobber_package"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
156
|
-
task :clobber_package => :clobber_component_packages
|
157
|
-
|
158
|
-
desc "Update the version number for component dependencies"
|
159
|
-
task :update_components_versions do
|
160
|
-
component_full_paths.each do |component_path|
|
161
|
-
Dir.chdir(component_path) do
|
162
|
-
sh "rake version"
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
namespace :version do
|
168
|
-
desc "Regenerate lib/#{module_path}/version.rb from VERSION file"
|
169
|
-
task :update => :update_components_versions do
|
170
|
-
update_version_rb
|
171
|
-
update_gemfile_lock
|
172
|
-
end
|
173
|
-
|
174
|
-
task :bump => %w{version:bump_patch version:update}
|
175
|
-
|
176
|
-
task :show do
|
177
|
-
puts version
|
178
|
-
end
|
179
|
-
|
180
|
-
# Add 1 to the current patch version in the VERSION file, and write it back out.
|
181
|
-
task :bump_patch do
|
182
|
-
current_version = version
|
183
|
-
new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
|
184
|
-
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
185
|
-
IO.write(version_file_path, new_version)
|
186
|
-
end
|
187
|
-
|
188
|
-
task :bump_minor do
|
189
|
-
current_version = version
|
190
|
-
new_version = current_version.sub(/^(\d+)\.(\d+)\.(\d+)/) { "#{$1}.#{$2.to_i + 1}.0" }
|
191
|
-
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
192
|
-
IO.write(version_file_path, new_version)
|
193
|
-
end
|
194
|
-
|
195
|
-
task :bump_major do
|
196
|
-
current_version = version
|
197
|
-
new_version = current_version.sub(/^(\d+)\.(\d+\.\d+)/) { "#{$1.to_i + 1}.0.0" }
|
198
|
-
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
199
|
-
IO.write(version_file_path, new_version)
|
200
|
-
end
|
201
|
-
|
202
|
-
def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
|
203
|
-
puts "Updating #{version_rb_path} to include version #{version} ..."
|
204
|
-
contents = <<-VERSION_RB
|
205
|
-
# Copyright:: Copyright 2010-2016, Chef Software, Inc.
|
206
|
-
# License:: Apache License, Version 2.0
|
207
|
-
#
|
208
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
209
|
-
# you may not use this file except in compliance with the License.
|
210
|
-
# You may obtain a copy of the License at
|
211
|
-
#
|
212
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
213
|
-
#
|
214
|
-
# Unless required by applicable law or agreed to in writing, software
|
215
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
216
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
217
|
-
# See the License for the specific language governing permissions and
|
218
|
-
# limitations under the License.
|
219
|
-
|
220
|
-
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
221
|
-
# NOTE: This file is generated by running `rake version` in the top level of
|
222
|
-
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
223
|
-
# task instead.
|
224
|
-
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
225
|
-
#{"\nrequire \"chef/version_string\"\n" if use_versionstring}
|
226
|
-
#{class_or_module} #{module_name}
|
227
|
-
#{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
|
228
|
-
VERSION = #{use_versionstring ? "Chef::VersionString.new(\"#{version}\")" : "\"#{version}\""}
|
229
|
-
end
|
230
|
-
|
231
|
-
#
|
232
|
-
# NOTE: the Chef::Version class is defined in version_class.rb
|
233
|
-
#
|
234
|
-
# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
|
235
|
-
# Chef::Version class is for _cookbooks_ only, and cannot handle
|
236
|
-
# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
|
237
|
-
# Gem::Version class instead.
|
238
|
-
#
|
239
|
-
VERSION_RB
|
240
|
-
IO.write(version_rb_path, contents)
|
241
|
-
end
|
242
|
-
|
243
|
-
def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition
|
244
|
-
if File.exist?(gemfile_lock_path)
|
245
|
-
puts "Updating #{gemfile_lock_path} to include version #{version} ..."
|
246
|
-
contents = IO.read(gemfile_lock_path)
|
247
|
-
contents.gsub!(/^\s*(chef|chef-config)\s*\((= )?\S+\)\s*$/) do |line|
|
248
|
-
line.gsub(/\((= )?\d+(\.\d+)+/) { "(#{$1}#{version}" }
|
249
|
-
end
|
250
|
-
IO.write(gemfile_lock_path, contents)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
|
255
|
-
task :version => "version:update"
|
256
|
-
|
257
|
-
gemspec_platform_to_install = ""
|
258
|
-
Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
|
259
|
-
gemspec = eval(IO.read(gemspec_path))
|
260
|
-
Gem::PackageTask.new(gemspec) do |task|
|
261
|
-
task.package_dir = full_package_dir
|
262
|
-
end
|
263
|
-
gemspec_platform_to_install = "-#{gemspec.platform}" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)
|
264
|
-
end
|
265
|
-
|
266
|
-
desc "Build and install a #{module_path} gem"
|
267
|
-
task :install => [:package] do
|
268
|
-
with_clean_env do
|
269
|
-
full_module_path = File.join(full_package_dir, module_path)
|
270
|
-
sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
task :uninstall do
|
275
|
-
sh %{gem uninstall #{module_path} -x -v #{version} }
|
276
|
-
end
|
277
|
-
|
278
|
-
desc "Build it, tag it and ship it"
|
279
|
-
task :ship => [:clobber_package, :gem] do
|
280
|
-
sh("git tag #{version}")
|
281
|
-
sh("git push #{git_remote} --tags")
|
282
|
-
Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
|
283
|
-
sh("gem push #{built_gem}")
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
|
3
|
+
# Copyright:: Copyright 2015-2016, Chef, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require "rake"
|
20
|
+
require "rubygems"
|
21
|
+
require "rubygems/package_task"
|
22
|
+
|
23
|
+
module ChefConfig
|
24
|
+
class PackageTask < Rake::TaskLib
|
25
|
+
|
26
|
+
# Full path to root of top-level repository. All other files (like VERSION or
|
27
|
+
# lib/<module_path>/version.rb are rooted at this path).
|
28
|
+
attr_accessor :root_path
|
29
|
+
|
30
|
+
# Name of the top-level module/library build built. This is used to define
|
31
|
+
# the top level module which contains VERSION and MODULE_ROOT.
|
32
|
+
attr_accessor :module_name
|
33
|
+
|
34
|
+
# Name of the gem being built. This is used to find the lines to fix in
|
35
|
+
# Gemfile.lock.
|
36
|
+
attr_accessor :gem_name
|
37
|
+
|
38
|
+
# Should the generated version.rb be in a class or module? Default is false (module).
|
39
|
+
attr_accessor :generate_version_class
|
40
|
+
|
41
|
+
# Paths to the roots of any components that also support ChefPackageTask.
|
42
|
+
# If relative paths are provided, they are rooted against root_path.
|
43
|
+
attr_accessor :component_paths
|
44
|
+
|
45
|
+
# This is the module name as it appears on the path "lib/module/".
|
46
|
+
# e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
|
47
|
+
# The default is module_name but lower-cased.
|
48
|
+
attr_writer :module_path
|
49
|
+
|
50
|
+
def module_path
|
51
|
+
@module_path || module_name.downcase
|
52
|
+
end
|
53
|
+
|
54
|
+
# Directory used to store package files and output that is generated.
|
55
|
+
# This has the same meaning (or lack thereof) as package_dir in
|
56
|
+
# rake/packagetask.
|
57
|
+
attr_accessor :package_dir
|
58
|
+
|
59
|
+
# Name of git remote used to push tags during a release. Default is origin.
|
60
|
+
attr_accessor :git_remote
|
61
|
+
|
62
|
+
# True if should use Chef::VersionString.
|
63
|
+
attr_accessor :use_versionstring
|
64
|
+
|
65
|
+
def initialize(root_path = nil, module_name = nil, gem_name = nil)
|
66
|
+
init(root_path, module_name, gem_name)
|
67
|
+
yield self if block_given?
|
68
|
+
define unless root_path.nil? || module_name.nil?
|
69
|
+
end
|
70
|
+
|
71
|
+
def init(root_path, module_name, gem_name)
|
72
|
+
@root_path = root_path
|
73
|
+
@module_name = module_name
|
74
|
+
@gem_name = gem_name
|
75
|
+
@component_paths = []
|
76
|
+
@module_path = nil
|
77
|
+
@package_dir = "pkg"
|
78
|
+
@git_remote = "origin"
|
79
|
+
@generate_version_class = false
|
80
|
+
end
|
81
|
+
|
82
|
+
def component_full_paths
|
83
|
+
component_paths.map { |path| File.expand_path(path, root_path) }
|
84
|
+
end
|
85
|
+
|
86
|
+
def version_rb_path
|
87
|
+
File.expand_path("lib/#{module_path}/version.rb", root_path)
|
88
|
+
end
|
89
|
+
|
90
|
+
def chef_root_path
|
91
|
+
module_name == "Chef" ? root_path : File.dirname(root_path)
|
92
|
+
end
|
93
|
+
|
94
|
+
def version_file_path
|
95
|
+
File.join(chef_root_path, "VERSION")
|
96
|
+
end
|
97
|
+
|
98
|
+
def gemfile_lock_path
|
99
|
+
File.join(root_path, "Gemfile.lock")
|
100
|
+
end
|
101
|
+
|
102
|
+
def version
|
103
|
+
IO.read(version_file_path).strip
|
104
|
+
end
|
105
|
+
|
106
|
+
def full_package_dir
|
107
|
+
File.expand_path(package_dir, root_path)
|
108
|
+
end
|
109
|
+
|
110
|
+
def class_or_module
|
111
|
+
generate_version_class ? "class" : "module"
|
112
|
+
end
|
113
|
+
|
114
|
+
def with_clean_env(&block)
|
115
|
+
if defined?(Bundler)
|
116
|
+
Bundler.with_clean_env(&block)
|
117
|
+
else
|
118
|
+
yield
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def define
|
123
|
+
raise "Need to provide package root and module name" if root_path.nil? || module_name.nil?
|
124
|
+
|
125
|
+
desc "Build Gems of component dependencies"
|
126
|
+
task :package_components do
|
127
|
+
component_full_paths.each do |component_path|
|
128
|
+
Dir.chdir(component_path) do
|
129
|
+
sh "rake package"
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
task :package => :package_components
|
135
|
+
|
136
|
+
desc "Build and install component dependencies"
|
137
|
+
task :install_components => :package_components do
|
138
|
+
component_full_paths.each do |component_path|
|
139
|
+
Dir.chdir(component_path) do
|
140
|
+
sh "rake install"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
task :install => :install_components
|
146
|
+
|
147
|
+
desc "Clean up builds of component dependencies"
|
148
|
+
task :clobber_component_packages do
|
149
|
+
component_full_paths.each do |component_path|
|
150
|
+
Dir.chdir(component_path) do
|
151
|
+
sh "rake clobber_package"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
task :clobber_package => :clobber_component_packages
|
157
|
+
|
158
|
+
desc "Update the version number for component dependencies"
|
159
|
+
task :update_components_versions do
|
160
|
+
component_full_paths.each do |component_path|
|
161
|
+
Dir.chdir(component_path) do
|
162
|
+
sh "rake version"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
namespace :version do
|
168
|
+
desc "Regenerate lib/#{module_path}/version.rb from VERSION file"
|
169
|
+
task :update => :update_components_versions do
|
170
|
+
update_version_rb
|
171
|
+
update_gemfile_lock
|
172
|
+
end
|
173
|
+
|
174
|
+
task :bump => %w{version:bump_patch version:update}
|
175
|
+
|
176
|
+
task :show do
|
177
|
+
puts version
|
178
|
+
end
|
179
|
+
|
180
|
+
# Add 1 to the current patch version in the VERSION file, and write it back out.
|
181
|
+
task :bump_patch do
|
182
|
+
current_version = version
|
183
|
+
new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" }
|
184
|
+
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
185
|
+
IO.write(version_file_path, new_version)
|
186
|
+
end
|
187
|
+
|
188
|
+
task :bump_minor do
|
189
|
+
current_version = version
|
190
|
+
new_version = current_version.sub(/^(\d+)\.(\d+)\.(\d+)/) { "#{$1}.#{$2.to_i + 1}.0" }
|
191
|
+
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
192
|
+
IO.write(version_file_path, new_version)
|
193
|
+
end
|
194
|
+
|
195
|
+
task :bump_major do
|
196
|
+
current_version = version
|
197
|
+
new_version = current_version.sub(/^(\d+)\.(\d+\.\d+)/) { "#{$1.to_i + 1}.0.0" }
|
198
|
+
puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}"
|
199
|
+
IO.write(version_file_path, new_version)
|
200
|
+
end
|
201
|
+
|
202
|
+
def update_version_rb # rubocop:disable Lint/NestedMethodDefinition
|
203
|
+
puts "Updating #{version_rb_path} to include version #{version} ..."
|
204
|
+
contents = <<-VERSION_RB
|
205
|
+
# Copyright:: Copyright 2010-2016, Chef Software, Inc.
|
206
|
+
# License:: Apache License, Version 2.0
|
207
|
+
#
|
208
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
209
|
+
# you may not use this file except in compliance with the License.
|
210
|
+
# You may obtain a copy of the License at
|
211
|
+
#
|
212
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
213
|
+
#
|
214
|
+
# Unless required by applicable law or agreed to in writing, software
|
215
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
216
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
217
|
+
# See the License for the specific language governing permissions and
|
218
|
+
# limitations under the License.
|
219
|
+
|
220
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
221
|
+
# NOTE: This file is generated by running `rake version` in the top level of
|
222
|
+
# this repo. Do not edit this manually. Edit the VERSION file and run the rake
|
223
|
+
# task instead.
|
224
|
+
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
225
|
+
#{"\nrequire \"chef/version_string\"\n" if use_versionstring}
|
226
|
+
#{class_or_module} #{module_name}
|
227
|
+
#{module_name.upcase}_ROOT = File.expand_path("../..", __FILE__)
|
228
|
+
VERSION = #{use_versionstring ? "Chef::VersionString.new(\"#{version}\")" : "\"#{version}\""}
|
229
|
+
end
|
230
|
+
|
231
|
+
#
|
232
|
+
# NOTE: the Chef::Version class is defined in version_class.rb
|
233
|
+
#
|
234
|
+
# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
|
235
|
+
# Chef::Version class is for _cookbooks_ only, and cannot handle
|
236
|
+
# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
|
237
|
+
# Gem::Version class instead.
|
238
|
+
#
|
239
|
+
VERSION_RB
|
240
|
+
IO.write(version_rb_path, contents)
|
241
|
+
end
|
242
|
+
|
243
|
+
def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition
|
244
|
+
if File.exist?(gemfile_lock_path)
|
245
|
+
puts "Updating #{gemfile_lock_path} to include version #{version} ..."
|
246
|
+
contents = IO.read(gemfile_lock_path)
|
247
|
+
contents.gsub!(/^\s*(chef|chef-config)\s*\((= )?\S+\)\s*$/) do |line|
|
248
|
+
line.gsub(/\((= )?\d+(\.\d+)+/) { "(#{$1}#{version}" }
|
249
|
+
end
|
250
|
+
IO.write(gemfile_lock_path, contents)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
task :version => "version:update"
|
256
|
+
|
257
|
+
gemspec_platform_to_install = ""
|
258
|
+
Dir[File.expand_path("*.gemspec", root_path)].reverse_each do |gemspec_path|
|
259
|
+
gemspec = eval(IO.read(gemspec_path))
|
260
|
+
Gem::PackageTask.new(gemspec) do |task|
|
261
|
+
task.package_dir = full_package_dir
|
262
|
+
end
|
263
|
+
gemspec_platform_to_install = "-#{gemspec.platform}" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)
|
264
|
+
end
|
265
|
+
|
266
|
+
desc "Build and install a #{module_path} gem"
|
267
|
+
task :install => [:package] do
|
268
|
+
with_clean_env do
|
269
|
+
full_module_path = File.join(full_package_dir, module_path)
|
270
|
+
sh %{gem install #{full_module_path}-#{version}#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
task :uninstall do
|
275
|
+
sh %{gem uninstall #{module_path} -x -v #{version} }
|
276
|
+
end
|
277
|
+
|
278
|
+
desc "Build it, tag it and ship it"
|
279
|
+
task :ship => [:clobber_package, :gem] do
|
280
|
+
sh("git tag #{version}")
|
281
|
+
sh("git push #{git_remote} --tags")
|
282
|
+
Dir[File.expand_path("*.gem", full_package_dir)].reverse_each do |built_gem|
|
283
|
+
sh("gem push #{built_gem}")
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
end
|