class PuppetModule
Attributes
Public Class Methods
# File lib/release_manager/puppet_module.rb, line 32 def self.check_requirements(path) pm = new(path) raise InvalidMetadataSource if pm.source !~ /\Agit\@/ raise UpstreamSourceMatch unless pm.git_upstream_set? end
@return [ControlRepo] - creates a new control repo object and clones the url unless already cloned @param url [String] - the upstream url @param branch [String] - the source branch
# File lib/release_manager/puppet_module.rb, line 271 def self.create(path, url, branch = 'master') options = {upstream: url, src_branch: branch} c = PuppetModule.new(path, options) c.clone(url, path) c end
@param mod_path [String] - the path to the module @param options [Hash] - a hash of options @option upstream [String] - the upstream url @option src_branch
[String] - the source of the branch
# File lib/release_manager/puppet_module.rb, line 20 def initialize(mod_path, options = {}) raise ModNotFoundException.new("#{mod_path} is not a valid puppet module path") if mod_path.nil? @path = mod_path @options = options @upstream = options[:upstream] @metadata_file = File.join(mod_path, 'metadata.json') end
Public Instance Methods
# File lib/release_manager/puppet_module.rb, line 60 def add_upstream_remote add_remote(source,'upstream',true ) end
# File lib/release_manager/puppet_module.rb, line 55 def already_latest? return false unless latest_tag up2date?(latest_tag, src_branch) end
Updates the version in memory
# File lib/release_manager/puppet_module.rb, line 166 def bump_major_version metadata['version'] = next_version('major') end
Updates the version in memory
# File lib/release_manager/puppet_module.rb, line 161 def bump_minor_version metadata['version'] = next_version('minor') end
Updates the version in memory
# File lib/release_manager/puppet_module.rb, line 156 def bump_patch_version metadata['version'] = next_version('patch') end
@return [String] the oid of the commit that was created @param remote [Boolean] if true creates the commit on the remote repo
# File lib/release_manager/puppet_module.rb, line 216 def commit_metadata(remote = false) message = "[ReleaseManager] - bump version to #{version}" if remote actions = [{ action: 'update', file_path: metadata_file.split(repo.workdir).last, content: JSON.pretty_generate(metadata) }] obj = vcs_create_commit(source, src_branch, message, actions) obj.id if obj else to_metadata_file add_file(metadata_file) create_commit(message) end end
@return [String] the oid of the commit that was created
# File lib/release_manager/puppet_module.rb, line 234 def commit_metadata_source(remote = false) message = "[ReleaseManager] - change source to #{source}" if remote actions = [{ action: 'update', file_path: metadata_file.split(repo.workdir).last, content: JSON.pretty_generate(metadata) }] obj = vcs_create_commit(source, src_branch, message, actions) obj.id if obj else to_metadata_file add_file(metadata_file) create_commit(message) end end
ensures the dev branch has been created and is up to date @deprecated Use {#create_src_branch} instead of this method which defaults to dev or master branch
# File lib/release_manager/puppet_module.rb, line 195 def create_dev_branch create_src_branch(src_branch) end
@param branch [String] - the name of the source branch to create and rebase from creates a branch and checkouts out the branch with the latest source of the upstream source
# File lib/release_manager/puppet_module.rb, line 185 def create_src_branch(branch = src_branch) fetch('upstream') create_branch(branch, "upstream/#{branch}") # ensure we have updated our local branch checkout_branch(branch) rebase_branch(branch, branch, 'upstream') end
# File lib/release_manager/puppet_module.rb, line 68 def git_upstream_set? source == git_upstream_url end
# File lib/release_manager/puppet_module.rb, line 64 def git_upstream_url repo.remotes['upstream'].url if remote_exists?('upstream') end
@return [String] - the latest tag in a series of versioned tags
# File lib/release_manager/puppet_module.rb, line 98 def latest_tag v = version_tags.sort do |a,b| Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', '')) end v.last end
@returns [Hash] the metadata object as a ruby hash
# File lib/release_manager/puppet_module.rb, line 47 def metadata unless @metadata raise ModNotFoundException.new("#{path} does not contain a metadata file") unless File.exists?(metadata_file) @metadata ||= JSON.parse(File.read(metadata_file)) end @metadata end
@returns [String] the name of the module found in the metadata file
# File lib/release_manager/puppet_module.rb, line 106 def mod_name metadata['name'] end
# File lib/release_manager/puppet_module.rb, line 42 def namespaced_name metadata['name'] end
@returns [String] the next version based on the release level
# File lib/release_manager/puppet_module.rb, line 120 def next_version(level = 'patch') return unless version pieces = version.split('.') raise "invalid semver structure #{version}" if pieces.count != 3 case level when 'major' pieces[2] = '0' pieces[1] = '0' pieces[0] = pieces[0].next when 'minor' pieces[2] = '0' pieces[1] = pieces[1].next when 'patch' pieces[2] = pieces[2].next else raise "expected semver release level major, minor or patch" end pieces.join('.') end
# File lib/release_manager/puppet_module.rb, line 84 def pad_version_string(version_string) parts = version_string.split('.').reject {|x| x == '*'} while parts.length < 3 parts << '0' end parts.join '.' end
pushes the source and tags @param id [String] - a ref spec to push
# File lib/release_manager/puppet_module.rb, line 209 def push_to_upstream(id = nil) push_branch(source, src_branch) push_tags(source, id) end
@return [Boolean] - true if the module is an r10k-control repository
# File lib/release_manager/puppet_module.rb, line 175 def r10k_module? mod_name =~ /r10k[-_]?control/i end
# File lib/release_manager/puppet_module.rb, line 28 def repo @repo ||= Rugged::Repository.new(path) end
# File lib/release_manager/puppet_module.rb, line 80 def source metadata['source'] end
@returns [String] - the source branch to push to if the user supplied the src_branch
we use that otherwise if the module is r10k-control this branch will be dev, if the module is not r10k-control we use master
# File lib/release_manager/puppet_module.rb, line 203 def src_branch options[:src_branch] || (r10k_module? ? 'dev' : 'master') end
@param tag [String] - the name of the tag @param remote [String] - check the remote for the tag, defaults to false @return [Boolean] - returns true if the tag exists
# File lib/release_manager/puppet_module.rb, line 254 def tag_exists?(tag, remote = false) if remote remote_tag_exists?(source, tag) else latest_tag == tag end end
@param remote [Boolean] - create the tag remotely using the remote VCS @param id [String] - the commit id to tag to @param remote [Boolean] - use the vcs adapter instead of local tag @param release_notes [Boolean] - add release notes to the tag when remote is true
# File lib/release_manager/puppet_module.rb, line 145 def tag_module(remote = false, id = nil, release_notes = nil) id ||= repo.head.target_id if remote # where we get the latest from the changelog create_tag(source, "v#{version}", id, "v#{version}", release_notes) else create_local_tag("v#{version}", id) end end
creates a file with the puppet metadata.json content written to disk
# File lib/release_manager/puppet_module.rb, line 263 def to_metadata_file logger.info("Writing to file #{metadata_file}") File.write(metadata_file, to_s) end
# File lib/release_manager/puppet_module.rb, line 170 def to_s JSON.pretty_generate(metadata) end
# File lib/release_manager/puppet_module.rb, line 110 def version=(v) metadata['version'] = v end