Class: Ra10ke::Dependencies::Verification
- Inherits:
-
Object
- Object
- Ra10ke::Dependencies::Verification
- Defined in:
- lib/ra10ke/dependencies.rb
Instance Attribute Summary collapse
-
#puppetfile ⇒ Object
readonly
Returns the value of attribute puppetfile.
Class Method Summary collapse
-
.register_version_format(name, &block) ⇒ Object
Registers a block that finds the latest version.
- .version_formats ⇒ Object
Instance Method Summary collapse
- #get_latest_ref(remote_refs) ⇒ Object
- #ignored_modules ⇒ Object
-
#initialize(pfile) ⇒ Verification
constructor
A new instance of Verification.
- #outdated(_supplied_puppetfile = puppetfile) ⇒ Object
- #print_table(mods) ⇒ Object
- #processed_modules(supplied_puppetfile = puppetfile) ⇒ Object
Constructor Details
#initialize(pfile) ⇒ Verification
Returns a new instance of Verification.
34 35 36 37 38 39 |
# File 'lib/ra10ke/dependencies.rb', line 34 def initialize(pfile) @puppetfile = pfile # semver is the default version format. puppetfile.load! end |
Instance Attribute Details
#puppetfile ⇒ Object (readonly)
Returns the value of attribute puppetfile.
32 33 34 |
# File 'lib/ra10ke/dependencies.rb', line 32 def puppetfile @puppetfile end |
Class Method Details
.register_version_format(name, &block) ⇒ Object
Registers a block that finds the latest version. The block will be called with a list of tags. If the block returns nil the next format will be tried.
19 20 21 |
# File 'lib/ra10ke/dependencies.rb', line 19 def self.register_version_format(name, &block) version_formats[name] = block end |
.version_formats ⇒ Object
12 13 14 |
# File 'lib/ra10ke/dependencies.rb', line 12 def self.version_formats @version_formats ||= {} end |
Instance Method Details
#get_latest_ref(remote_refs) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/ra10ke/dependencies.rb', line 41 def get_latest_ref(remote_refs) = remote_refs['tags'].keys latest_ref = nil self.class.version_formats.detect { |_, block| latest_ref = block.call() } latest_ref = 'undef (tags do not follow any known pattern)' if latest_ref.nil? latest_ref end |
#ignored_modules ⇒ Object
49 50 51 52 53 54 |
# File 'lib/ra10ke/dependencies.rb', line 49 def ignored_modules # ignore file allows for "don't tell me about this" @ignored_modules ||= begin File.readlines('.r10kignore').each { |l| l.chomp! } if File.exist?('.r10kignore') end || [] end |
#outdated(_supplied_puppetfile = puppetfile) ⇒ Object
129 130 131 132 133 |
# File 'lib/ra10ke/dependencies.rb', line 129 def outdated(_supplied_puppetfile = puppetfile) processed_modules.find_all do |mod| mod[:message] == :outdated end end |
#print_table(mods) ⇒ Object
135 136 137 138 |
# File 'lib/ra10ke/dependencies.rb', line 135 def print_table(mods) puts tp mods, { name: { width: 50 } }, :installed, :latest, :type, :message end |
#processed_modules(supplied_puppetfile = puppetfile) ⇒ Object
Note:
does not include ignored modules or modules up2date
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ra10ke/dependencies.rb', line 60 def processed_modules(supplied_puppetfile = puppetfile) threads = [] supplied_puppetfile.modules.each do |puppet_module| next if ignored_modules.include? puppet_module.title # Ignore modules where ref is explicitly set to control branch next if puppet_module.instance_of?(R10K::Module::Git) && puppet_module.desired_ref == :control_branch threads << Thread.new do if puppet_module.instance_of?(::R10K::Module::Forge) module_name = puppet_module.title.tr('/', '-') forge_version = ::PuppetForge::Module.find(module_name).current_release.version installed_version = puppet_module.expected_version { name: puppet_module.title, installed: installed_version, latest: forge_version, type: 'forge', message: (installed_version == forge_version) ? :current : :outdated, } elsif puppet_module.instance_of?(R10K::Module::Git) # use helper; let r10k figure out correct ref ref = puppet_module.version next unless ref remote = puppet_module.instance_variable_get(:@remote) remote_refs = Git.ls_remote(remote) # skip if ref is a branch next if remote_refs['branches'].key?(ref) if remote_refs['tags'].key?(ref) # there are too many possible versioning conventions # we have to be be opinionated here # so semantic versioning (vX.Y.Z) it is for us # as well as support for skipping the leading v letter # # register own version formats with # Ra10ke::Dependencies.register_version_format(:name, &block) latest_ref = get_latest_ref(remote_refs) elsif /^[a-z0-9]{40}$/.match?(ref) ref = ref.slice(0, 8) # for sha just assume head should be tracked latest_ref = remote_refs['head'][:sha].slice(0, 8) else raise "Unable to determine ref type for #{puppet_module.title}" end { name: puppet_module.title, installed: ref, latest: latest_ref, type: 'git', message: (ref == latest_ref) ? :current : :outdated, } end rescue R10K::Util::Subprocess::SubprocessError => e { name: puppet_module.title, installed: nil, latest: nil, type: :error, message: e., } end end threads.map { |th| th.join.value }.compact end |