simp-rake-helpers 5.4.3 → 5.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6ce6418a9a5502135d802a6a96f42ee4b3660f
4
- data.tar.gz: 2b18c76399ef02e72ca986723cb24f41d2b69267
3
+ metadata.gz: 834fc98fb63f04a0f5e9bb98c275ffd42738123c
4
+ data.tar.gz: c0d3fc5372f4e3c99893e33d3e345886d41c069c
5
5
  SHA512:
6
- metadata.gz: a66462436bec15a83457fa138effaa890773b7b8a681c1bee75d7c2901bc0426e1d0b37e64d417807072a62572d59de7450a82a51c69ca57b620315eac95d6a6
7
- data.tar.gz: d45a422e9781164aa8df97f6542ff404a1d85284abecc1feff1c1d8f650d18bad155ba9289d8fc0b36ae6ab397c01847e30c6fa35c9feb3c00cbdf9141a97f19
6
+ metadata.gz: efee59c86535eaa39046ea0c06133a57e8b4a1bf4a3f4419983741a516493aaf17f590764630b44c3d2bbaeb0a0f0d6d55d4b758595e341a616b9d39f75f61b0
7
+ data.tar.gz: 3f70e19f9587f9aa5124255f3bb9305d976c107879a0f348c8cb44aff119504e98d010c7755d0a046e4156777a05956100505cfc12bb9321dfc65cb51cae6b22
@@ -1,3 +1,10 @@
1
+ ### 5.5.0 / 2018-06-22
2
+ * Pin fog-openstack to 0.1.25 if Ruby is prior to 2.2.0 due to a deprecation
3
+ * Fix regression that broke env var `SIMP_BUILD_distro`
4
+ * Add support for setting SIMP_RSPEC_PUPPETFILE and/or SIMP_RSPEC_MODULEPATH to
5
+ create a custom fixtures.yml based on a Puppetfile, the modules in a
6
+ directory, or the combination of both.
7
+
1
8
  ### 5.4.3 / 2018-03-29
2
9
  * Fix RPM release processing when generating 'Obsoletes' metadata
3
10
 
data/README.md CHANGED
@@ -16,6 +16,7 @@
16
16
  * [Gemfile](#gemfile)
17
17
  * [Usage](#usage)
18
18
  * [In a Puppet module](#in-a-puppet-module)
19
+ * [Environment Variables](#environment-variables)
19
20
  * [In a Ruby Gem](#in-a-ruby-gem)
20
21
  * [Generating RPMs](#generating-rpms)
21
22
  * [RPM Changelog](#rpm-changelog)
@@ -99,6 +100,32 @@ require 'simp/rake/pupmod/helpers'
99
100
  Simp::Rake::Pupmod::Helpers.new(File.dirname(__FILE__))
100
101
  ```
101
102
 
103
+ ### Environment Variables
104
+
105
+ Some environment variables have been added to help you work with different
106
+ types of testing scenarios and are documented below.
107
+
108
+ By default, only the modules found in the local `.fixtures.yml` file will be
109
+ included.
110
+
111
+ * `SIMP_RSPEC_PUPPETFILE`
112
+ * Ignore the local `.fixtures.yml` and use the modules listed in the specified Puppetfile
113
+ * Downloaded items that are not Puppet modules will be removed from the
114
+ downloaded fixtures prior to testing
115
+ * Set this to a valid URL to download a remote Puppetfile for use
116
+
117
+ * `SIMP_RSPEC_MODULEPATH`
118
+ * Will ignore the local `.fixtures.yml` file and create one entirely of
119
+ symlinks that point to the modules present at the specified path.
120
+ * If specified with `SIMP_RSPEC_PUPPETFILE` then will use the
121
+ matching modules from the target directory instead of downloading them.
122
+ Modules not present in the target directory will still be downloaded.
123
+
124
+ * `SIMP_RSPEC_FIXTURES_OVERRIDE`
125
+ * Set to `yes` to ignore the local `.fixtures.yml` file
126
+ * This will cause the generated file to include **all** modules from the
127
+ Puppetfile or Module Path
128
+
102
129
  ### In a Ruby Gem
103
130
 
104
131
  Within the project's Rakefile:
@@ -108,7 +135,7 @@ require 'simp/rake/rubygem'
108
135
 
109
136
  # e.g., "simp-rake-helpers"
110
137
  package = 'name-of-rubygem'
111
- Simp::Rake::Rubygem.new(package, File.direname(__FILE__)
138
+ Simp::Rake::Rubygem.new(package, File.dirname(__FILE__)
112
139
 
113
140
  ```
114
141
 
@@ -136,7 +163,7 @@ directory . The full list of files considered are:
136
163
  ├── metadata.json # REQUIRED keys: name, version, license, summary, source
137
164
  ├── CHANGELOG # OPTIONAL written in RPM's CHANGELOG format
138
165
  └── build/ # OPTIONAL
139
-    └── rpm_metadata/ # OPTIONAL
166
+ └── rpm_metadata/ # OPTIONAL
140
167
  ├── release # OPTIONAL defines the RPM's "-0" release number
141
168
  ├── requires # OPTIONAL supplementary 'Requires','Provides','Obsoletes'
142
169
  └── custom/ # OPTIONAL
@@ -204,8 +231,8 @@ Build the tar package for the current SIMP project
204
231
 
205
232
  This is a limitation of Bundler, not the gem.
206
233
 
207
- If you are running on a FIPS-enabled system, you will need to use `bundler '~> 1.14.0'`
208
- until the FIPS support can be corrected.
234
+ If you are running on a FIPS-enabled system, you will need to use
235
+ `bundler '~> 1.14.0'` or `bundler '~> 1.16'`
209
236
 
210
237
  If you are using RVM, the appropriate steps are as follows:
211
238
 
@@ -11,9 +11,13 @@ module Simp::Rake::Build::Constants
11
11
  $simp6 = true
12
12
  $simp6_clean_dirs = []
13
13
 
14
- @build_distro = Facter.fact('operatingsystem').value
15
- @build_version = Facter.fact('operatingsystemmajrelease').value
16
- @build_arch = Facter.fact('architecture').value
14
+ if ENV['SIMP_BUILD_distro']
15
+ distro, version, arch = ENV['SIMP_BUILD_distro'].split(/,|\//)
16
+ end
17
+
18
+ @build_distro = distro || Facter.fact('operatingsystem').value
19
+ @build_version = version || Facter.fact('operatingsystemmajrelease').value
20
+ @build_arch = arch || Facter.fact('architecture').value
17
21
 
18
22
  @run_dir = Dir.pwd
19
23
  @base_dir = base_dir
@@ -85,6 +85,8 @@ class R10KHelper
85
85
  mod = {
86
86
  :name => mod.name,
87
87
  :path => mod.path.to_s,
88
+ :remote => mod.repo.instance_variable_get('@remote'),
89
+ :desired_ref => mod.desired_ref,
88
90
  :git_source => mod.repo.repo.origin,
89
91
  :git_ref => mod.repo.head,
90
92
  :module_dir => mod.basedir,
@@ -2,5 +2,5 @@ module Simp; end
2
2
  module Simp::Rake; end
3
3
 
4
4
  class Simp::Rake::Helpers
5
- VERSION = '5.4.3'
5
+ VERSION = '5.5.0'
6
6
  end
@@ -17,6 +17,19 @@ module Simp; end
17
17
  module Simp::Rake; end
18
18
  module Simp::Rake::Pupmod; end
19
19
 
20
+ # From http://dan.doezema.com/2012/04/recursively-sort-ruby-hash-by-key/
21
+ class Hash
22
+ def sort_by_key(recursive = false, &block)
23
+ self.keys.sort(&block).reduce({}) do |seed, key|
24
+ seed[key] = self[key]
25
+ if recursive && seed[key].is_a?(Hash)
26
+ seed[key] = seed[key].sort_by_key(true, &block)
27
+ end
28
+ seed
29
+ end
30
+ end
31
+ end
32
+
20
33
  # Rake tasks for SIMP Puppet modules
21
34
  class Simp::Rake::Pupmod::Helpers < ::Rake::TaskLib
22
35
  # See https://fedoraproject.org/wiki/Packaging:Guidelines?rd=Packaging/Guidelines#Changelogs
@@ -24,11 +37,16 @@ class Simp::Rake::Pupmod::Helpers < ::Rake::TaskLib
24
37
 
25
38
  def initialize( base_dir = Dir.pwd )
26
39
  @base_dir = base_dir
40
+ @temp_fixtures_path = File.join(base_dir,'spec','fixtures','simp_rspec')
41
+
42
+ FileUtils.mkdir_p(@temp_fixtures_path)
43
+
27
44
  Dir[ File.join(File.dirname(__FILE__),'*.rb') ].each do |rake_file|
28
45
  next if rake_file == __FILE__
29
46
  require rake_file
30
47
  end
31
48
  define_tasks
49
+
32
50
  end
33
51
 
34
52
  def define_tasks
@@ -63,6 +81,7 @@ class Simp::Rake::Pupmod::Helpers < ::Rake::TaskLib
63
81
 
64
82
  Simp::Rake::Pkg.new( @base_dir ) do | t |
65
83
  t.clean_list << "#{t.base_dir}/spec/fixtures/hieradata/hiera.yaml"
84
+ t.clean_list << @temp_fixtures_path
66
85
  end
67
86
 
68
87
  Simp::Rake::Beaker.new( @base_dir )
@@ -133,6 +152,115 @@ class Simp::Rake::Pupmod::Helpers < ::Rake::TaskLib
133
152
  result += changelogs[module_version].join
134
153
  end
135
154
 
155
+ def custom_fixtures_hook(opts = {
156
+ :short_name => nil,
157
+ :puppetfile => nil,
158
+ :modulepath => nil,
159
+ :local_fixtures_mods => nil,
160
+ })
161
+ short_name = opts[:short_name]
162
+ puppetfile = opts[:puppetfile]
163
+ modulepath = opts[:modulepath]
164
+ local_fixtures_mods = opts[:local_fixtures_mods] || []
165
+
166
+ fail('You must pass a short module name') unless short_name
167
+
168
+ fixtures_hash = {
169
+ 'fixtures' => {
170
+ 'symlinks' => {
171
+ short_name => '#{source_dir}'
172
+ }
173
+ }
174
+ }
175
+
176
+ local_modules = {}
177
+
178
+ if modulepath
179
+ unless File.directory?(modulepath)
180
+ fail("Could not find a module directory at #{modulepath}")
181
+ end
182
+
183
+ # Grab all of the local modules and convert them into something
184
+ # that can be turned into a Hash easily
185
+ local_modules = Hash[Dir.glob(File.join(modulepath, '*', 'metadata.json')).map do |m|
186
+ [File.basename(File.dirname(m)), File.absolute_path(File.dirname(m))]
187
+ end]
188
+
189
+ local_modules.delete(short_name)
190
+ end
191
+
192
+ if puppetfile
193
+ fail("Could not find Puppetfile at #{puppetfile}") unless File.exist?(puppetfile)
194
+
195
+ require 'simp/rake/build/deps'
196
+
197
+ puppetfile = R10KHelper.new(puppetfile)
198
+
199
+ puppetfile.modules.each do |pupmod|
200
+ next unless pupmod[:name]
201
+ next if pupmod[:status] == :unknown
202
+
203
+ if local_modules[pupmod[:name]]
204
+ unless local_fixtures_mods.empty?
205
+ local_fixtures_mod = local_fixtures_mods.delete(pupmod[:name])
206
+ next unless local_fixtures_mod
207
+ end
208
+
209
+ fixtures_hash['fixtures']['symlinks'][pupmod[:name]] = local_modules[pupmod[:name]]
210
+ else
211
+ fixtures_hash['fixtures']['repositories'] ||= {}
212
+
213
+ unless local_fixtures_mods.empty?
214
+ local_fixtures_mod = local_fixtures_mods.delete(pupmod[:name])
215
+ next unless local_fixtures_mod
216
+ end
217
+
218
+ next unless pupmod[:remote] && pupmod[:desired_ref]
219
+ next if pupmod[:name] == short_name
220
+
221
+ fixtures_hash['fixtures']['repositories'][pupmod[:name]] = {
222
+ 'repo' => pupmod[:remote],
223
+ 'ref' => pupmod[:desired_ref]
224
+ }
225
+ end
226
+ end
227
+ elsif modulepath
228
+ local_modules.each_pair do |pupmod, path|
229
+ unless local_fixtures_mods.empty?
230
+ local_fixtures_mod = local_fixtures_mods.delete(pupmod)
231
+ next unless local_fixtures_mod
232
+ end
233
+
234
+ fixtures_hash['fixtures']['symlinks'][pupmod] = path
235
+ end
236
+ end
237
+
238
+ if local_fixtures_mods.empty?
239
+ custom_fixtures_path = File.join(@temp_fixtures_path, 'fixtures.yml')
240
+ else
241
+ custom_fixtures_path = File.join(@temp_fixtures_path, 'fixtures_tmp.yml')
242
+ end
243
+
244
+ if puppetfile || modulepath
245
+ File.open(custom_fixtures_path, 'w') do |fh|
246
+ fh.puts(fixtures_hash.sort_by_key(true).to_yaml)
247
+ end
248
+ end
249
+
250
+ unless local_fixtures_mods.empty?
251
+ errmsg = [
252
+ '===',
253
+ 'The following modules in .fixtures.yml were not found in the Puppetfile:',
254
+ %{ * #{local_fixtures_mods.join("\n * ")}},
255
+ %{A temporary fixtures file has been written to #{custom_fixtures_path}},
256
+ '==='
257
+ ]
258
+
259
+ fail(errmsg.join("\n"))
260
+ end
261
+
262
+ return custom_fixtures_path
263
+ end
136
264
 
137
265
  desc <<-EOM
138
266
  Generate an appropriate annotated tag entry from a CHANGELOG.
@@ -287,5 +415,81 @@ class Simp::Rake::Pupmod::Helpers < ::Rake::TaskLib
287
415
  Rake::Task[:spec_clean].invoke
288
416
  end
289
417
  end
418
+
419
+ # This hidden task provides a way to create and use a fixtures.yml file
420
+ # based on an externally specified Puppetfile
421
+ #
422
+ # The resulting fixtures.yml will contain only those modules that are
423
+ # in the local fixtures.yml but with the version specified in the
424
+ # Puppetfile.
425
+ #
426
+ # Downloaded repos that do not contain a metadata.json will be removed
427
+ #
428
+ # Set the environment variable SIMP_RSPEC_PUPPETFILE to point to a remote Puppetfile
429
+ #
430
+ # Set the environment variable SIMP_RSPEC_FIXTURES_OVERRIDE to 'yes' to
431
+ # ignore the local fixtures.yml file.
432
+ #
433
+ # Set the environment variable SIMP_RSPEC_MODULEPATH to symlink named
434
+ # modules from the designated directory instead of downloading them.
435
+ #
436
+ # If both SIMP_RSPEC_PUPPETFILE and SIMP_RSPEC_MODULEPATH are specified,
437
+ # the Puppetfile will win.
438
+ task :custom_fixtures_hook do
439
+ # Don't do anything if the user has already set a path to their fixtures
440
+ unless ENV['FIXTURES_YML']
441
+ @custom_fixtures_hook_override_fixtures = (ENV.fetch('SIMP_RSPEC_FIXTURES_OVERRIDE', 'no') == 'yes')
442
+
443
+ opts = { :short_name => metadata['name'].split('-').last }
444
+
445
+ if ENV['SIMP_RSPEC_PUPPETFILE']
446
+ puppetfile = ENV['SIMP_RSPEC_PUPPETFILE']
447
+
448
+ puppetfile_tgt = File.join(@temp_fixtures_path, 'Puppetfile')
449
+
450
+ if puppetfile =~ %r{://}
451
+ %x{curl -k -s -o #{puppetfile_tgt} #{puppetfile}}
452
+ else
453
+ FileUtils.cp(File.absolute_path(puppetfile), puppetfile_tgt)
454
+ end
455
+
456
+ opts[:puppetfile] = puppetfile_tgt
457
+ end
458
+
459
+ if ENV['SIMP_RSPEC_MODULEPATH']
460
+ opts[:modulepath] = File.absolute_path(ENV['SIMP_RSPEC_MODULEPATH'])
461
+ end
462
+
463
+ if opts[:puppetfile] || opts[:modulepath]
464
+ unless @custom_fixtures_hook_override_fixtures
465
+ fail("Could not find '.fixtures.yml' at #{Dir.pwd}") unless File.exist?('.fixtures.yml')
466
+
467
+ opts[:local_fixtures_mods] = []
468
+
469
+ require 'yaml'
470
+ _fixtures = YAML.load_file('.fixtures.yml')['fixtures']
471
+ _fixtures.keys.each do |subset|
472
+ _fixtures[subset].each_pair do |_mod, _extra|
473
+ opts[:local_fixtures_mods] << _mod
474
+ end
475
+ end
476
+ end
477
+
478
+ fixtures_yml_path = custom_fixtures_hook(opts)
479
+
480
+ if fixtures_yml_path
481
+ ENV['FIXTURES_YML'] = fixtures_yml_path
482
+ end
483
+ end
484
+ end
485
+ end
486
+
487
+ Rake::Task['spec_prep'].enhance [:custom_fixtures_hook] do
488
+ Dir.glob(File.join('spec','fixtures','modules','*')).each do |dir|
489
+ if @custom_fixtures_hook_override_fixtures
490
+ FileUtils.remove_entry_secure(dir) unless File.exist?(File.join(dir, 'metadata.json'))
491
+ end
492
+ end
493
+ end
290
494
  end
291
495
  end
@@ -3,7 +3,6 @@ require 'spec_helper'
3
3
 
4
4
  describe Simp::RPM do
5
5
  before :all do
6
- Simp::RPM.stubs(:system_dist).returns('.testdist')
7
6
 
8
7
  dir = File.expand_path( 'files', File.dirname( __FILE__ ) )
9
8
  @spec_file = File.join( dir, 'testpackage.spec' )
@@ -225,10 +224,16 @@ describe Simp::RPM do
225
224
 
226
225
  context '#dist' do
227
226
  it 'returns dist' do
228
- expect( @rpm_obj.dist ).to eq '.testdist'
229
- expect( @d_rpm_obj.dist ).to eq '.el7'
230
- expect( @spec_obj.dist ).to eq '.testdist'
231
- expect( @d_spec_obj.dist ).to eq '.testdist'
227
+ Simp::RPM.stubs(:system_dist).returns('.testdist')
228
+ rpm_obj = Simp::RPM.new( @rpm_file )
229
+ d_rpm_obj = Simp::RPM.new( @d_rpm_file )
230
+ spec_obj = Simp::RPM.new( @spec_file )
231
+ d_spec_obj = Simp::RPM.new( @d_spec_file )
232
+
233
+ expect( rpm_obj.dist ).to eq '.testdist'
234
+ expect( d_rpm_obj.dist ).to eq '.el7'
235
+ expect( spec_obj.dist ).to eq '.testdist'
236
+ expect( d_spec_obj.dist ).to eq '.testdist'
232
237
  end
233
238
 
234
239
  it 'fails when invalid package specified' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simp-rake-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.3
4
+ version: 5.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Tessmer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-03-29 00:00:00.000000000 Z
12
+ date: 2018-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -267,20 +267,6 @@ dependencies:
267
267
  - - "~>"
268
268
  - !ruby/object:Gem::Version
269
269
  version: '3.0'
270
- - !ruby/object:Gem::Dependency
271
- name: listen
272
- requirement: !ruby/object:Gem::Requirement
273
- requirements:
274
- - - "~>"
275
- - !ruby/object:Gem::Version
276
- version: 3.0.6
277
- type: :runtime
278
- prerelease: false
279
- version_requirements: !ruby/object:Gem::Requirement
280
- requirements:
281
- - - "~>"
282
- - !ruby/object:Gem::Version
283
- version: 3.0.6
284
270
  - !ruby/object:Gem::Dependency
285
271
  name: pry
286
272
  requirement: !ruby/object:Gem::Requirement
@@ -329,48 +315,6 @@ dependencies:
329
315
  - - ">"
330
316
  - !ruby/object:Gem::Version
331
317
  version: 1.6.1
332
- - !ruby/object:Gem::Dependency
333
- name: guard
334
- requirement: !ruby/object:Gem::Requirement
335
- requirements:
336
- - - "~>"
337
- - !ruby/object:Gem::Version
338
- version: '2.0'
339
- type: :development
340
- prerelease: false
341
- version_requirements: !ruby/object:Gem::Requirement
342
- requirements:
343
- - - "~>"
344
- - !ruby/object:Gem::Version
345
- version: '2.0'
346
- - !ruby/object:Gem::Dependency
347
- name: guard-shell
348
- requirement: !ruby/object:Gem::Requirement
349
- requirements:
350
- - - "~>"
351
- - !ruby/object:Gem::Version
352
- version: '0.0'
353
- type: :development
354
- prerelease: false
355
- version_requirements: !ruby/object:Gem::Requirement
356
- requirements:
357
- - - "~>"
358
- - !ruby/object:Gem::Version
359
- version: '0.0'
360
- - !ruby/object:Gem::Dependency
361
- name: guard-rspec
362
- requirement: !ruby/object:Gem::Requirement
363
- requirements:
364
- - - "~>"
365
- - !ruby/object:Gem::Version
366
- version: '4.0'
367
- type: :development
368
- prerelease: false
369
- version_requirements: !ruby/object:Gem::Requirement
370
- requirements:
371
- - - "~>"
372
- - !ruby/object:Gem::Version
373
- version: '4.0'
374
318
  description: ' "simp-rake-helpers provides common methods for SIMP Rake Tasks"
375
319
 
376
320
  '