Class: Simp::Rake::Build::Deps

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Pager
Defined in:
lib/simp/rake/build/deps.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_dir) ⇒ Deps

Returns a new instance of Deps.



184
185
186
187
188
# File 'lib/simp/rake/build/deps.rb', line 184

def initialize( base_dir )
  @base_dir = base_dir
  @verbose = ENV.fetch('SIMP_PKG_verbose','no') == 'yes'
  define_tasks
end

Instance Method Details

#define_tasksObject



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# File 'lib/simp/rake/build/deps.rb', line 190

def define_tasks
  namespace :deps do
    desc "    Checks out all dependency repos.\n\n    This task used R10k to update all dependencies.\n\n    Arguments:\n      * :method  => The update method to use (Default => 'tracking')\n           tracking => checks out each dep (by branch) according to Puppetfile.tracking\n           stable   => checks out each dep (by ref) according to in Puppetfile.stable\n    EOM\n    task :checkout, [:method] do |t,args|\n      args.with_defaults(:method => 'tracking')\n\n      r10k_helper = R10KHelper.new(\"Puppetfile.\#{args[:method]}\")\n\n      r10k_issues = Parallel.map(\n        Array(r10k_helper.modules),\n        :in_processes => get_cpu_limit,\n        :progress => 'Submodule Checkout'\n      ) do |mod|\n        issues = []\n\n        Dir.chdir(@base_dir) do\n          unless File.directory?(mod[:path])\n            FileUtils.mkdir_p(mod[:path])\n          end\n\n          # Only for known modules...\n          unless mod[:status] == :unknown\n            # Since r10k is destructive, we're enumerating all valid states\n            if [\n                :absent,\n                :mismatched,\n                :outdated,\n                :insync,\n                :dirty\n            ].include?(mod[:r10k_module].status)\n              unless mod[:r10k_cache].synced?\n                mod[:r10k_cache].sync\n              end\n\n              if mod[:status] == :known\n                mod[:r10k_module].sync\n              else\n                # If we get here, the module was dirty and should be skipped\n                issues << \"\#{mod[:name]}: Skipped - \#{mod[:status]}\"\n                next\n              end\n            else\n              issues << \"\#{mod[:name]}: Skipped - Unknown status type \#{mod[:r10k_module].status}\"\n            end\n          end\n        end\n\n        issues\n      end\n\n      r10k_issues.flatten!\n\n      unless r10k_issues.empty?\n        $stderr.puts('='*80)\n\n        unless @verbose\n          $stderr.puts('Warning: Some repositories were skipped!')\n          $stderr.puts('  * If this is a fresh build, this could be an issue')\n          $stderr.puts('  * This is expected if re-running a build')\n          $stderr.puts('  * Run with SIMP_PKG_verbose=yes for full details')\n        else\n          $stderr.puts(\"R10k Checkout Issues:\")\n          r10k_issues.each do |issue|\n            $stderr.puts(\"  * \#{issue}\")\n          end\n        end\n\n        $stderr.puts('='*80)\n      end\n    end\n\n    desc <<-EOM\n    Get the status of the project Git repositories\n\n    Arguments:\n      * :method  => The update method to use (Default => 'tracking')\n           tracking => checks out each dep (by branch) according to Puppetfile.tracking\n           stable   => checks out each dep (by ref) according to in Puppetfile.stable\n    EOM\n    task :status, [:method] do |t,args|\n      args.with_defaults(:method => 'tracking')\n      @dirty_repos = nil\n\n      r10k_helper = R10KHelper.new(\"Puppetfile.\#{args[:method]}\")\n\n      mods_with_changes = {}\n\n      r10k_helper.each_module do |mod|\n        unless File.directory?(mod[:path])\n          $stderr.puts(\"Warning: '\#{mod[:path]}' is not a module...skipping\") if File.exist?(mod[:path])\n          next\n        end\n\n        if mod[:status] != :known\n          # Clean up the path a bit for printing\n          dirty_path = mod[:path].split(r10k_helper.basedir.to_s).last\n          if dirty_path[0].chr == File::SEPARATOR\n            dirty_path[0] = ''\n          end\n\n          mods_with_changes[mod[:name]] = dirty_path\n        end\n      end\n\n      if mods_with_changes.empty?\n        puts \"No repositories have changes.\"\n        @dirty_repos = false\n      else\n        puts \"The following repositories have changes:\"\n        puts mods_with_changes.map{|k,v| \"  + \#{k} => \#{v}\"}.join(\"\\n\")\n\n        @dirty_repos = true\n      end\n\n      unknown_mods = r10k_helper.unknown_modules\n      unless unknown_mods.empty?\n        puts \"The following modules were unknown:\"\n        puts unknown_mods.map{|k,v| \"  ? \#{k}\"}.join(\"\\n\")\n      end\n    end\n\n    desc <<-EOM\n    Records the current dependencies into Puppetfile.stable.\n\n    Arguments:\n      * :method    => Save to Puppetfile.[method] (Default => 'stable')\n      * :reference => Use Puppetfile.[reference] to reference which repos\n                      should be recorded (Default => 'tracking')\n    EOM\n    task :record, [:method,:reference] do |t,args|\n      args.with_defaults(:method => 'stable')\n      args.with_defaults(:reference => 'tracking')\n\n      r10k_helper = R10KHelper.new(\"Puppetfile.\#{args[:reference]}\")\n      File.open(\"Puppetfile.\#{args[:method]}\",'w'){|f| f.puts r10k_helper.puppetfile }\n    end\n\n    desc <<-EOM\n    Provide a log of changes to all modules from the given top level Git reference.\n\n    Arguments:\n      * :ref => The top level git ref to use as the oldest point for all logs.\n      * :source => The source Puppetfile to use (Default => 'tracking')\n    EOM\n    task :changelog, [:ref] do |t,args|\n      args.with_defaults(:source => 'tracking')\n\n      r10k_helper = R10KHelper.new(\"Puppetfile.\#{args[:source]}\")\n\n      git_logs = Hash.new\n\n      Dir.chdir(r10k_helper.basedir) do\n        ref = args[:ref]\n        refdate = nil\n        begin\n          refdate = %x(git log -1 --format=%ai '\#{ref}')\n          refdate = nil unless $?.success?\n        rescue Exception\n          #noop\n        end\n\n        fail(\"You must specify a valid reference\") unless ref\n        fail(\"Could not find a Git log for \#{ref}\") unless refdate\n\n        mods_with_changes = {}\n\n        log_output = %x(git log --since='\#{refdate}' --stat --reverse).chomp\n        git_logs['__SIMP CORE__'] = log_output unless log_output.strip.empty?\n\n        r10k_helper.each_module do |mod|\n          if File.directory?(mod[:path])\n            Dir.chdir(mod[:path]) do\n              log_output = %x(git log --since='\#{refdate}' --stat --reverse).chomp\n              git_logs[mod[:name]] = log_output unless log_output.strip.empty?\n            end\n          end\n        end\n\n        if git_logs.empty?\n          puts( \"No changes found for any components since \#{refdate}\")\n        else\n          page\n\n          git_logs.keys.sort.each do |mod_name|\n            puts <<-EOM\n  ========\n  \#{mod_name}:\n\n  \#{git_logs[mod_name].gsub(/^/,'  ')}\n\n            EOM\n          end\n        end\n      end\n    end\n  end\nend\n"