halite 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bd9453c15ddb7b58021da152d53ee281e00e13e
4
- data.tar.gz: 641b09025f131006f0707625a4f22a475deac522
3
+ metadata.gz: 1a37de991e3e0d1627ffdef876685f8eec08df61
4
+ data.tar.gz: 6299278206fcadb36f2b6c6b5f6b33b63a563c58
5
5
  SHA512:
6
- metadata.gz: 7bdb648670ef4bc5afdb954e7c5f769c8bf643f8e58c6065c63211e90e4bfc5336cf358d68313585e53b31e0bad5c70b647c858f2f51d917cb921fbc603e7c19
7
- data.tar.gz: 36c524bb699a35b9a7c3f772e56d74cf220cc8e1a41df349dfcb632f52d9a815f0fc515922999457394d54fdc71ff91cc4c3cb097876df0b898301c247899c44
6
+ metadata.gz: 3e584b28d05cad1e885c1050c149e0b0541b8157e8493ecdbd9b50bad174379e51f0185b56284f8d50d61ee290ea2f15e2ef5babe02bf91e004b28967ad3f8c5
7
+ data.tar.gz: 0fdac57fd61e32efcc2017d937c3db4c58d5ec1673f9db36e73ba6057e5a8fc1697eac98242f398a0e48e2a8c08f6a759b4f22eb2baa4450c4970f1e09801ad4
@@ -1,5 +1,11 @@
1
1
  # Halite Changelog
2
2
 
3
+ ## v1.7.0
4
+
5
+ * Allow specifying which platforms a cookbook supports via gem metadata:
6
+ `spec.metadata['platforms'] = 'ubuntu centos'`.
7
+ * Support for automatic ChefSpec matchers in the future.
8
+
3
9
  ## v1.6.0
4
10
 
5
11
  * Chef 13 compatibility.
@@ -47,7 +47,10 @@ module Halite
47
47
  buf << ", #{dep.requirement.inspect}" if dep.requirement != '>= 0'
48
48
  buf << "\n"
49
49
  end
50
- buf << "chef_version(*#{gem_data.chef_version_requirement.inspect}) if defined?(chef_version)\n"
50
+ buf << "chef_version #{gem_data.chef_version_requirement.map(&:inspect).join(', ')} if defined?(chef_version)\n"
51
+ gem_data.platforms.each do |platform|
52
+ buf << "supports #{platform.map(&:inspect).join(', ')}\n"
53
+ end
51
54
  end
52
55
  end
53
56
 
@@ -116,6 +116,28 @@ module Halite
116
116
  end
117
117
  end
118
118
 
119
+ # Platform support to be used in the Chef metadata.
120
+ #
121
+ # @return [Array<Array<String>>]
122
+ def platforms
123
+ raw_platforms = spec.metadata.fetch('platforms', '').strip
124
+ case raw_platforms
125
+ when ''
126
+ []
127
+ when 'any', 'all', '*'
128
+ # Based on `ls lib/fauxhai/platforms | xargs echo`.
129
+ %w{aix amazon arch centos chefspec debian dragonfly4 fedora freebsd gentoo
130
+ ios_xr mac_os_x nexus omnios openbsd opensuse oracle raspbian redhat
131
+ slackware smartos solaris2 suse ubuntu windows}.map {|p| [p] }
132
+ when /,/
133
+ # Comma split mode. String looks like "name, name constraint, name constraint"
134
+ raw_platforms.split(/\s*,\s*/).map {|p| p.split(/\s+/, 2) }
135
+ else
136
+ # Whitepace split mode, assume no constraints.
137
+ raw_platforms.split(/\s+/).map {|p| [p] }
138
+ end
139
+ end
140
+
119
141
  # Iterate over all the files in the gem, with an optional prefix. Each
120
142
  # element in the iterable will be [full_path, relative_path], where
121
143
  # relative_path is relative to the prefix or gem path.
@@ -221,7 +243,8 @@ module Halite
221
243
  if spec.metadata['halite_chef_version']
222
244
  # Manually overridden by gem metadata, use that.
223
245
  [spec.metadata['halite_chef_version']]
224
- elsif dep = spec.dependencies.find {|dep| dep.name == 'chef' && !dep.requirement.none? }
246
+ elsif dep = spec.dependencies.find {|inner_dep| inner_dep.name == 'chef' && !inner_dep.requirement.none? }
247
+ # Parse through the dependencies looking for something like `spec.add_dependency 'chef', '>= 12.1''`.
225
248
  dep.requirement.as_list
226
249
  else
227
250
  ['>= 12']
@@ -21,7 +21,6 @@ require 'thor'
21
21
  require 'thor/shell'
22
22
 
23
23
  require 'halite/error'
24
- require 'halite/gem'
25
24
 
26
25
 
27
26
  module Halite
@@ -124,6 +123,7 @@ module Halite
124
123
  #
125
124
  # @return [Halite::Gem]
126
125
  def cookbook
126
+ require 'halite/gem'
127
127
  @cookbook ||= Halite::Gem.new(gemspec)
128
128
  end
129
129
  end
@@ -14,13 +14,15 @@
14
14
  # limitations under the License.
15
15
  #
16
16
 
17
+ # This must come first to ensure ChefSpec can patch in for matcher loading.
18
+ require 'chefspec'
19
+
17
20
  # Fix load ordering bug in Chef 12.0.1. Remove this when dropping support for 12.0.
18
21
  require 'chef/providers'
19
22
 
20
23
  require 'chef/node'
21
24
  require 'chef/provider'
22
25
  require 'chef/resource'
23
- require 'chefspec'
24
26
 
25
27
 
26
28
  module Halite
@@ -17,5 +17,5 @@
17
17
 
18
18
  module Halite
19
19
  # Halite version.
20
- VERSION = '1.6.0'
20
+ VERSION = '1.7.0'
21
21
  end
@@ -50,6 +50,7 @@ describe Halite::Converter::Metadata do
50
50
  cookbook_version: cookbook_version,
51
51
  issues_url: issues_url,
52
52
  chef_version_requirement: chef_version_requirement,
53
+ platforms: [],
53
54
  )
54
55
  end
55
56
  subject { described_class.generate(gem_data) }
@@ -58,7 +59,7 @@ describe Halite::Converter::Metadata do
58
59
  it { is_expected.to eq <<-EOH }
59
60
  name "mygem"
60
61
  version "1.0.0"
61
- chef_version(*[">= 12"]) if defined?(chef_version)
62
+ chef_version ">= 12" if defined?(chef_version)
62
63
  EOH
63
64
  end # /context with simple data
64
65
 
@@ -70,7 +71,7 @@ EOH
70
71
  # header
71
72
  name "mygem"
72
73
  version "1.0.0"
73
- chef_version(*[">= 12"]) if defined?(chef_version)
74
+ chef_version ">= 12" if defined?(chef_version)
74
75
  EOH
75
76
  end # /context with a license header
76
77
 
@@ -80,7 +81,7 @@ EOH
80
81
  name "mygem"
81
82
  version "1.0.0"
82
83
  depends "other"
83
- chef_version(*[">= 12"]) if defined?(chef_version)
84
+ chef_version ">= 12" if defined?(chef_version)
84
85
  EOH
85
86
  end # /context with one dependency
86
87
 
@@ -91,7 +92,7 @@ name "mygem"
91
92
  version "1.0.0"
92
93
  depends "other", "~> 1.0"
93
94
  depends "another", "~> 2.0.0"
94
- chef_version(*[">= 12"]) if defined?(chef_version)
95
+ chef_version ">= 12" if defined?(chef_version)
95
96
  EOH
96
97
  end # /context with two dependencies
97
98
 
@@ -104,7 +105,7 @@ EOH
104
105
  name "mygem"
105
106
  version "1.0.0"
106
107
  description "My awesome library!"
107
- chef_version(*[">= 12"]) if defined?(chef_version)
108
+ chef_version ">= 12" if defined?(chef_version)
108
109
  EOH
109
110
  end # /context with a description
110
111
 
@@ -118,7 +119,7 @@ EOH
118
119
  name "mygem"
119
120
  version "1.0.0"
120
121
  long_description "My awesome readme!\\nCopyright me.\\n"
121
- chef_version(*[">= 12"]) if defined?(chef_version)
122
+ chef_version ">= 12" if defined?(chef_version)
122
123
  EOH
123
124
  end # /context with a readme
124
125
 
@@ -128,10 +129,20 @@ EOH
128
129
  it { is_expected.to eq <<-EOH }
129
130
  name "mygem"
130
131
  version "1.0.0"
131
- chef_version(*[">= 0"]) if defined?(chef_version)
132
+ chef_version ">= 0" if defined?(chef_version)
132
133
  EOH
133
134
  end # /context with a chef_version
134
135
 
136
+ context 'with a complex chef_version' do
137
+ let(:chef_version_requirement) { ['< 15', '>= 12.5'] }
138
+
139
+ it { is_expected.to eq <<-EOH }
140
+ name "mygem"
141
+ version "1.0.0"
142
+ chef_version "< 15", ">= 12.5" if defined?(chef_version)
143
+ EOH
144
+ end # /context with a complex chef_version
145
+
135
146
  context 'with an issues_url' do
136
147
  let(:issues_url) { 'http://issues' }
137
148
 
@@ -139,9 +150,39 @@ EOH
139
150
  name "mygem"
140
151
  version "1.0.0"
141
152
  issues_url "http://issues" if defined?(issues_url)
142
- chef_version(*[">= 12"]) if defined?(chef_version)
153
+ chef_version ">= 12" if defined?(chef_version)
143
154
  EOH
144
155
  end # /context with an issues_url
156
+
157
+ context 'with platforms' do
158
+ before do
159
+ allow(gem_data).to receive(:platforms).and_return([%w{ubuntu}, %w{debian}, %w{redhat}])
160
+ end
161
+
162
+ it { is_expected.to eq <<-EOH }
163
+ name "mygem"
164
+ version "1.0.0"
165
+ chef_version ">= 12" if defined?(chef_version)
166
+ supports "ubuntu"
167
+ supports "debian"
168
+ supports "redhat"
169
+ EOH
170
+ end # /context with platforms
171
+
172
+ context 'with complex platforms' do
173
+ before do
174
+ allow(gem_data).to receive(:platforms).and_return([['ubuntu', '>= 16.04'], ['debian', '>= 6', '< 9'], %w{redhat}])
175
+ end
176
+
177
+ it { is_expected.to eq <<-EOH }
178
+ name "mygem"
179
+ version "1.0.0"
180
+ chef_version ">= 12" if defined?(chef_version)
181
+ supports "ubuntu", ">= 16.04"
182
+ supports "debian", ">= 6", "< 9"
183
+ supports "redhat"
184
+ EOH
185
+ end # /context with complex platforms
145
186
  end # /describe #generate
146
187
 
147
188
  describe '#write' do
@@ -6,4 +6,4 @@ maintainer "Noah Kantrowitz"
6
6
  maintainer_email "noah@coderanger.net"
7
7
  source_url "http://example.com/" if defined?(source_url)
8
8
  license "Apache 2.0"
9
- chef_version(*[">= 12"]) if defined?(chef_version)
9
+ chef_version ">= 12" if defined?(chef_version)
@@ -6,4 +6,5 @@ maintainer_email "noah@coderanger.net"
6
6
  source_url "http://example.com/" if defined?(source_url)
7
7
  license "Apache 2.0"
8
8
  depends "testdep"
9
- chef_version(*[">= 12"]) if defined?(chef_version)
9
+ chef_version ">= 12" if defined?(chef_version)
10
+ supports "ubuntu"
@@ -6,4 +6,6 @@ maintainer_email "noah@coderanger.net"
6
6
  source_url "http://example.com/" if defined?(source_url)
7
7
  license "Apache 2.0"
8
8
  depends "test2", "~> 4.5.6"
9
- chef_version(*[">= 3"]) if defined?(chef_version)
9
+ chef_version ">= 3" if defined?(chef_version)
10
+ supports "ubuntu", ">= 16.04"
11
+ supports "redhat"
@@ -6,4 +6,9 @@ maintainer_email "noah@coderanger.net"
6
6
  source_url "http://example.com/" if defined?(source_url)
7
7
  issues_url "http://issues" if defined?(issues_url)
8
8
  license "Apache 2.0"
9
- chef_version(*[">= 1"]) if defined?(chef_version)
9
+ chef_version "< 99", ">= 1" if defined?(chef_version)
10
+ supports "ubuntu"
11
+ supports "debian"
12
+ supports "centos"
13
+ supports "redhat"
14
+ supports "fedora"
@@ -12,6 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.summary = %q||
13
13
  spec.homepage = 'http://example.com/'
14
14
  spec.license = 'Apache 2.0'
15
+ spec.metadata['platforms'] = 'ubuntu'
15
16
 
16
17
  spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
17
18
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -14,6 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'Apache 2.0'
15
15
  spec.metadata['halite_entry_point'] = 'test3/dsl'
16
16
  spec.metadata['halite_chef_version'] = '>= 3'
17
+ spec.metadata['platforms'] = 'ubuntu >= 16.04, redhat'
17
18
 
18
19
  spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
19
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -13,6 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'http://example.com/'
14
14
  spec.license = 'Apache 2.0'
15
15
  spec.metadata['issues_url'] = 'http://issues'
16
+ spec.metadata['platforms'] = 'ubuntu debian centos redhat fedora'
16
17
 
17
18
  spec.files = `cd #{File.expand_path('..', __FILE__)} && git ls-files`.split($/)
18
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -20,7 +21,7 @@ Gem::Specification.new do |spec|
20
21
  spec.require_paths = %w{lib}
21
22
 
22
23
  spec.add_dependency 'halite'
23
- spec.add_dependency 'chef', '>= 1'
24
+ spec.add_dependency 'chef', '>= 1', '< 99'
24
25
 
25
26
  spec.add_development_dependency 'rake'
26
27
  spec.add_development_dependency 'test2', '~> 4.5.6'
@@ -35,6 +35,7 @@ describe Halite::Gem do
35
35
  its(:version) { is_expected.to eq Halite::VERSION }
36
36
  its(:spec) { is_expected.to quiet_be_a Gem::Specification }
37
37
  its(:issues_url) { is_expected.to eq 'https://github.com/poise/halite/issues' }
38
+ its(:platforms) { is_expected.to eq [] }
38
39
  end
39
40
 
40
41
  context 'when loading halite with a version' do
@@ -66,7 +67,8 @@ describe Halite::Gem do
66
67
  its(:cookbook_dependencies) { is_expected.to eq [] }
67
68
  its(:is_halite_cookbook?) { is_expected.to be_truthy }
68
69
  its(:issues_url) { is_expected.to be_nil }
69
- its(:chef_version_requirement) { is_expected.to eq [">= 12"] }
70
+ its(:chef_version_requirement) { is_expected.to eq ['>= 12'] }
71
+ its(:platforms) { is_expected.to eq [] }
70
72
 
71
73
  describe '#each_file' do
72
74
  context 'with no prefixes' do
@@ -105,7 +107,8 @@ describe Halite::Gem do
105
107
  its(:cookbook_dependencies) { is_expected.to eq [Halite::Dependencies::Dependency.new('testdep', '>= 0', :requirements)] }
106
108
  its(:is_halite_cookbook?) { is_expected.to be_truthy }
107
109
  its(:issues_url) { is_expected.to be_nil }
108
- its(:chef_version_requirement) { is_expected.to eq [">= 12"] }
110
+ its(:chef_version_requirement) { is_expected.to eq ['>= 12'] }
111
+ its(:platforms) { is_expected.to eq [%w{ubuntu}] }
109
112
 
110
113
  describe '#each_file' do
111
114
  context 'with no prefixes' do
@@ -142,6 +145,7 @@ describe Halite::Gem do
142
145
  its(:is_halite_cookbook?) { is_expected.to be_truthy }
143
146
  its(:issues_url) { is_expected.to be_nil }
144
147
  its(:chef_version_requirement) { is_expected.to eq [">= 3"] }
148
+ its(:platforms) { is_expected.to eq [['ubuntu', '>= 16.04'], %w{redhat}] }
145
149
  end # /context when loading test3
146
150
 
147
151
  context 'when loading test4' do
@@ -152,7 +156,8 @@ describe Halite::Gem do
152
156
  its(:version) { is_expected.to eq '2.3.1.rc.1' }
153
157
  its(:cookbook_version) { is_expected.to eq '2.3.1' }
154
158
  its(:issues_url) { is_expected.to eq 'http://issues' }
155
- its(:chef_version_requirement) { is_expected.to eq [">= 1"] }
159
+ its(:chef_version_requirement) { is_expected.to eq ['< 99', '>= 1'] }
160
+ its(:platforms) { is_expected.to eq [%w{ubuntu}, %w{debian}, %w{centos}, %w{redhat}, %w{fedora}] }
156
161
  end # /context when loading test4
157
162
 
158
163
  context 'when loading a Gem::Dependency' do
@@ -237,4 +242,75 @@ describe Halite::Gem do
237
242
  it { is_expected.to eq 'mycompany-mygem' }
238
243
  end
239
244
  end # /describe #cookbook_name
245
+
246
+ describe '#platforms' do
247
+ let(:platforms) { '' }
248
+ let(:metadata) { {'platforms' => platforms} }
249
+ subject { described_class.new(Gem::Specification.new {|s| s.metadata.update(metadata) }).platforms }
250
+
251
+ context 'with no metadata' do
252
+ let(:metadata) { {} }
253
+ it { is_expected.to eq [] }
254
+ end # /context with no metadata
255
+
256
+ context 'with ""' do
257
+ let(:platforms) { '' }
258
+ it { is_expected.to eq [] }
259
+ end # /context with ""
260
+
261
+ context 'with " "' do
262
+ let(:platforms) { ' ' }
263
+ it { is_expected.to eq [] }
264
+ end # /context with " "
265
+
266
+ context 'with "name1"' do
267
+ let(:platforms) { 'name1' }
268
+ it { is_expected.to eq [%w{name1}] }
269
+ end # /context with "name1"
270
+
271
+ context 'with "name1 "' do
272
+ let(:platforms) { 'name1 ' }
273
+ it { is_expected.to eq [%w{name1}] }
274
+ end # /context with "name1 "
275
+
276
+ context 'with " name1"' do
277
+ let(:platforms) { ' name1' }
278
+ it { is_expected.to eq [%w{name1}] }
279
+ end # /context with " name1"
280
+
281
+ context 'with "name1 name2"' do
282
+ let(:platforms) { 'name1 name2' }
283
+ it { is_expected.to eq [%w{name1}, %w{name2}] }
284
+ end # /context with "name1 name2"
285
+
286
+ context 'with "name1, name2"' do
287
+ let(:platforms) { 'name1, name2' }
288
+ it { is_expected.to eq [%w{name1}, %w{name2}] }
289
+ end # /context with "name1, name2"
290
+
291
+ context 'with "name1 >= 1.0, name2"' do
292
+ let(:platforms) { 'name1 >= 1.0, name2' }
293
+ it { is_expected.to eq [['name1', '>= 1.0'], %w{name2}] }
294
+ end # /context with "name1 >= 1.0, name2"
295
+
296
+ context 'with "name1 >= 1.0, name2 <= 2.0"' do
297
+ let(:platforms) { 'name1 >= 1.0, name2 <= 2.0' }
298
+ it { is_expected.to eq [['name1', '>= 1.0'], ['name2', '<= 2.0']] }
299
+ end # /context with "name1 >= 1.0, name2 <= 2.0"
300
+
301
+ context 'with "any"' do
302
+ let(:platforms) { 'any' }
303
+ it { is_expected.to eq [%w{aix}, %w{amazon}, %w{arch}, %w{centos}, %w{chefspec}, %w{debian}, %w{dragonfly4}, %w{fedora}, %w{freebsd}, %w{gentoo}, %w{ios_xr}, %w{mac_os_x}, %w{nexus}, %w{omnios}, %w{openbsd}, %w{opensuse}, %w{oracle}, %w{raspbian}, %w{redhat}, %w{slackware}, %w{smartos}, %w{solaris2}, %w{suse}, %w{ubuntu}, %w{windows}] }
304
+ end # /context with "any"
305
+
306
+ context 'with "all"' do
307
+ let(:platforms) { 'all' }
308
+ it { is_expected.to eq [%w{aix}, %w{amazon}, %w{arch}, %w{centos}, %w{chefspec}, %w{debian}, %w{dragonfly4}, %w{fedora}, %w{freebsd}, %w{gentoo}, %w{ios_xr}, %w{mac_os_x}, %w{nexus}, %w{omnios}, %w{openbsd}, %w{opensuse}, %w{oracle}, %w{raspbian}, %w{redhat}, %w{slackware}, %w{smartos}, %w{solaris2}, %w{suse}, %w{ubuntu}, %w{windows}] }
309
+ end # /context with "all"
310
+
311
+ context 'with "*"' do
312
+ let(:platforms) { '*' }
313
+ it { is_expected.to eq [%w{aix}, %w{amazon}, %w{arch}, %w{centos}, %w{chefspec}, %w{debian}, %w{dragonfly4}, %w{fedora}, %w{freebsd}, %w{gentoo}, %w{ios_xr}, %w{mac_os_x}, %w{nexus}, %w{omnios}, %w{openbsd}, %w{opensuse}, %w{oracle}, %w{raspbian}, %w{redhat}, %w{slackware}, %w{smartos}, %w{solaris2}, %w{suse}, %w{ubuntu}, %w{windows}] }
314
+ end # /context with "*"
315
+ end # /describe #platforms
240
316
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: halite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Kantrowitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-09 00:00:00.000000000 Z
11
+ date: 2017-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef