lib/bolt/module_installer.rb
# Outputs a diff of an old Puppetfile and a new Puppetfile.
#
Outputs a diff of an old Puppetfile and a new Puppetfile.
Outputs a diff of an old Puppetfile and a new Puppetfile .
def print_puppetfile_diff(old, new)
      old = (old&.modules || []).each_with_object({}) do |mod, acc|
        next unless mod.type == :forge
        acc[mod.full_name] = mod
      end
      new = new.modules.each_with_object({}) do |mod, acc|
        next unless mod.type == :forge
        acc[mod.full_name] = mod
      end
      added = new.reject { |full_name, _mod| old.include?(full_name) }.values
      if added.any?
        diff = "Adding the following modules:\n"
        added.each { |mod| diff += "#{mod.full_name} #{mod.version}\n" }
        @outputter.print_action_step(diff)
      end
      upgraded = new.select do |full_name, mod|
        if old.include?(full_name)
          mod.version > old[full_name].version
        end
      end.keys
      if upgraded.any?
        diff = "Upgrading the following modules:\n"
        upgraded.each { |full_name| diff += "#{full_name} #{old[full_name].version} to #{new[full_name].version}\n" }
        @outputter.print_action_step(diff)
      end
      downgraded = new.select do |full_name, mod|
        if old.include?(full_name)
          mod.version < old[full_name].version
        end
      end.keys
      if downgraded.any?
        diff = "Downgrading the following modules: \n"
        downgraded.each { |full_name| diff += "#{full_name} #{old[full_name].version} to #{new[full_name].version}\n" }
        @outputter.print_action_step(diff)
      end
      removed = old.reject { |full_name, _mod| new.include?(full_name) }.values
      if removed.any?
        diff = "Removing the following modules:\n"
        removed.each { |mod| diff += "#{mod.full_name} #{mod.version}\n" }
        @outputter.print_action_step(diff)
      end
    end
def print_puppetfile_diff ( old , new ) old = ( old &. modules || [ ] ) . each_with_object ( { } ) do | mod , acc | next unless mod . type == :forge acc [ mod . full_name ] = mod end new = new . modules . each_with_object ( { } ) do | mod , acc | next unless mod . type == :forge acc [ mod . full_name ] = mod end added = new . reject { | full_name , _mod | old . include? ( full_name ) } . values if added . any? diff = "Adding the following modules:\n" added . each { | mod | diff += "#{mod.full_name} #{mod.version}\n" } @outputter . print_action_step ( diff ) end upgraded = new . select do | full_name , mod | if old . include? ( full_name ) mod . version > old [ full_name ] . version end end . keys if upgraded . any? diff = "Upgrading the following modules:\n" upgraded . each { | full_name | diff += "#{full_name} #{old[full_name].version} to #{new[full_name].version}\n" } @outputter . print_action_step ( diff ) end downgraded = new . select do | full_name , mod | if old . include? ( full_name ) mod . version < old [ full_name ] . version end end . keys if downgraded . any? diff = "Downgrading the following modules: \n" downgraded . each { | full_name | diff += "#{full_name} #{old[full_name].version} to #{new[full_name].version}\n" } @outputter . print_action_step ( diff ) end removed = old . reject { | full_name , _mod | new . include? ( full_name ) } . values if removed . any? diff = "Removing the following modules:\n" removed . each { | mod | diff += "#{mod.full_name} #{mod.version}\n" } @outputter . print_action_step ( diff ) end end
Outputs a diff of an old Puppetfile and a new Puppetfile.
Outputs a diff of an old Puppetfile and a new Puppetfile .
# Build hashes mapping the module name to the module object. This makes it # a little easier to determine which modules have been added, removed, or # modified. # New modules are those present in new but not in old. # Upgraded modules are those that have a newer version in new than old. # Downgraded modules are those that have an older version in new than old. # Removed modules are those present in old but not in new.
old
<not_specific>
new
<not_specific>