Class: PuppetModule
- Inherits:
-
WorkflowAction
- Object
- WorkflowAction
- PuppetModule
- Defined in:
- lib/release_manager/puppet_module.rb
Instance Attribute Summary collapse
-
#metadata_file ⇒ Object
readonly
Returns the value of attribute metadata_file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
- #source ⇒ Object
-
#upstream ⇒ Object
readonly
Returns the value of attribute upstream.
- #version ⇒ Object
Attributes included from ReleaseManager::VCSManager
Class Method Summary collapse
- .check_requirements(path) ⇒ Object
-
.create(path, url, branch = 'master') ⇒ ControlRepo
-
creates a new control repo object and clones the url unless already cloned.
-
Instance Method Summary collapse
- #add_upstream_remote ⇒ Object
- #already_latest? ⇒ Boolean
-
#bump_major_version ⇒ Object
Updates the version in memory.
-
#bump_minor_version ⇒ Object
Updates the version in memory.
-
#bump_patch_version ⇒ Object
Updates the version in memory.
-
#commit_metadata(remote = false) ⇒ String
The oid of the commit that was created.
-
#commit_metadata_source(remote = false) ⇒ String
The oid of the commit that was created.
-
#create_dev_branch ⇒ Object
deprecated
Deprecated.
Use #create_src_branch instead of this method which defaults to dev or master branch
-
#create_src_branch(branch = src_branch) ⇒ Object
creates a branch and checkouts out the branch with the latest source of the upstream source.
- #git_upstream_set? ⇒ Boolean
- #git_upstream_url ⇒ Object
-
#initialize(mod_path, options = {}) ⇒ PuppetModule
constructor
A new instance of PuppetModule.
-
#latest_tag ⇒ String
-
the latest tag in a series of versioned tags.
-
- #metadata ⇒ Object
- #mod_name ⇒ Object
- #namespaced_name ⇒ Object
- #next_version(level = 'patch') ⇒ Object
- #pad_version_string(version_string) ⇒ Object
-
#push_to_upstream(id = nil) ⇒ Object
pushes the source and tags.
-
#r10k_module? ⇒ Boolean
-
true if the module is an r10k-control repository.
-
- #repo ⇒ Object
-
#src_branch ⇒ Object
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.
-
#tag_exists?(tag, remote = false) ⇒ Boolean
-
returns true if the tag exists.
-
- #tag_module(remote = false, id = nil, release_notes = nil) ⇒ Object
- #tags ⇒ Object
-
#to_metadata_file ⇒ Object
creates a file with the puppet metadata.json content written to disk.
- #to_s ⇒ Object
-
#version_tags ⇒ Array<String>
-
returns a array of version strings with the v in the name.
-
Methods included from ReleaseManager::VCSManager
adapter_instance, adapter_types, default_instance
Methods included from ReleaseManager::Logger
Methods included from ReleaseManager::Git::Utilities
#add_all, #add_file, #add_remote, #apply_diff, #apply_patch, #author, #author_email, #author_name, #branch_exist?, #changed_files, #checkout_branch, #cherry_pick, #cli_create_commit, #clone, #create_branch, #create_commit, #create_diff, #create_diff_obj, #create_local_tag, #credentials, #current_branch, #current_branch?, #delete_branch, #fetch, #fetch_cli, #find_or_create_remote, #find_ref, #find_tag, #get_content, #git_command, #git_url?, #push_branch, #push_tags, #rebase_branch, #ref_exists?, #remote_exists?, #remote_from_name, #remote_from_url, #remote_url_matches?, #remove_file, #transports, #up2date?
Constructor Details
#initialize(mod_path, options = {}) ⇒ PuppetModule
Returns a new instance of PuppetModule.
20 21 22 23 24 25 26 |
# File 'lib/release_manager/puppet_module.rb', line 20 def initialize(mod_path, = {}) raise ModNotFoundException.new("#{mod_path} is not a valid puppet module path") if mod_path.nil? @path = mod_path @options = @upstream = [:upstream] @metadata_file = File.join(mod_path, 'metadata.json') end |
Instance Attribute Details
#metadata_file ⇒ Object (readonly)
Returns the value of attribute metadata_file.
9 10 11 |
# File 'lib/release_manager/puppet_module.rb', line 9 def @metadata_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/release_manager/puppet_module.rb', line 9 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/release_manager/puppet_module.rb', line 9 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/release_manager/puppet_module.rb', line 9 def path @path end |
#source ⇒ Object
80 81 82 |
# File 'lib/release_manager/puppet_module.rb', line 80 def source ['source'] end |
#upstream ⇒ Object (readonly)
Returns the value of attribute upstream.
9 10 11 |
# File 'lib/release_manager/puppet_module.rb', line 9 def upstream @upstream end |
#version ⇒ Object
115 116 117 |
# File 'lib/release_manager/puppet_module.rb', line 115 def version @version end |
Class Method Details
.check_requirements(path) ⇒ Object
32 33 34 35 36 |
# 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 |
.create(path, url, branch = 'master') ⇒ ControlRepo
Returns - creates a new control repo object and clones the url unless already cloned.
271 272 273 274 275 276 |
# File 'lib/release_manager/puppet_module.rb', line 271 def self.create(path, url, branch = 'master') = {upstream: url, src_branch: branch} c = PuppetModule.new(path, ) c.clone(url, path) c end |
Instance Method Details
#add_upstream_remote ⇒ Object
60 61 62 |
# File 'lib/release_manager/puppet_module.rb', line 60 def add_upstream_remote add_remote(source,'upstream',true ) end |
#already_latest? ⇒ Boolean
55 56 57 58 |
# File 'lib/release_manager/puppet_module.rb', line 55 def already_latest? return false unless latest_tag up2date?(latest_tag, src_branch) end |
#bump_major_version ⇒ Object
Updates the version in memory
166 167 168 |
# File 'lib/release_manager/puppet_module.rb', line 166 def bump_major_version ['version'] = next_version('major') end |
#bump_minor_version ⇒ Object
Updates the version in memory
161 162 163 |
# File 'lib/release_manager/puppet_module.rb', line 161 def bump_minor_version ['version'] = next_version('minor') end |
#bump_patch_version ⇒ Object
Updates the version in memory
156 157 158 |
# File 'lib/release_manager/puppet_module.rb', line 156 def bump_patch_version ['version'] = next_version('patch') end |
#commit_metadata(remote = false) ⇒ String
Returns the oid of the commit that was created.
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/release_manager/puppet_module.rb', line 216 def (remote = false) = "[ReleaseManager] - bump version to #{version}" if remote actions = [{ action: 'update', file_path: .split(repo.workdir).last, content: JSON.pretty_generate() }] obj = vcs_create_commit(source, src_branch, , actions) obj.id if obj else add_file() create_commit() end end |
#commit_metadata_source(remote = false) ⇒ String
Returns the oid of the commit that was created.
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/release_manager/puppet_module.rb', line 234 def (remote = false) = "[ReleaseManager] - change source to #{source}" if remote actions = [{ action: 'update', file_path: .split(repo.workdir).last, content: JSON.pretty_generate() }] obj = vcs_create_commit(source, src_branch, , actions) obj.id if obj else add_file() create_commit() end end |
#create_dev_branch ⇒ Object
Use #create_src_branch instead of this method which defaults to dev or master branch
ensures the dev branch has been created and is up to date
195 196 197 |
# File 'lib/release_manager/puppet_module.rb', line 195 def create_dev_branch create_src_branch(src_branch) end |
#create_src_branch(branch = src_branch) ⇒ Object
creates a branch and checkouts out the branch with the latest source of the upstream source
185 186 187 188 189 190 191 |
# 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 |
#git_upstream_set? ⇒ Boolean
68 69 70 |
# File 'lib/release_manager/puppet_module.rb', line 68 def git_upstream_set? source == git_upstream_url end |
#git_upstream_url ⇒ Object
64 65 66 |
# File 'lib/release_manager/puppet_module.rb', line 64 def git_upstream_url repo.remotes['upstream'].url if remote_exists?('upstream') end |
#latest_tag ⇒ String
Returns - the latest tag in a series of versioned tags.
98 99 100 101 102 103 |
# File 'lib/release_manager/puppet_module.rb', line 98 def latest_tag v = .sort do |a,b| Gem::Version.new(a.tr('v', '')) <=> Gem::Version.new(b.tr('v', '')) end v.last end |
#metadata ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/release_manager/puppet_module.rb', line 47 def unless @metadata raise ModNotFoundException.new("#{path} does not contain a metadata file") unless File.exists?() @metadata ||= JSON.parse(File.read()) end @metadata end |
#mod_name ⇒ Object
106 107 108 |
# File 'lib/release_manager/puppet_module.rb', line 106 def mod_name ['name'] end |
#namespaced_name ⇒ Object
42 43 44 |
# File 'lib/release_manager/puppet_module.rb', line 42 def namespaced_name ['name'] end |
#next_version(level = 'patch') ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# 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 |
#pad_version_string(version_string) ⇒ Object
84 85 86 87 88 89 90 |
# 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 |
#push_to_upstream(id = nil) ⇒ Object
pushes the source and tags
209 210 211 212 |
# File 'lib/release_manager/puppet_module.rb', line 209 def push_to_upstream(id = nil) push_branch(source, src_branch) (source, id) end |
#r10k_module? ⇒ Boolean
Returns - true if the module is an r10k-control repository.
175 176 177 |
# File 'lib/release_manager/puppet_module.rb', line 175 def r10k_module? mod_name =~ /r10k[-_]?control/i end |
#repo ⇒ Object
28 29 30 |
# File 'lib/release_manager/puppet_module.rb', line 28 def repo @repo ||= Rugged::Repository.new(path) end |
#src_branch ⇒ Object
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
203 204 205 |
# File 'lib/release_manager/puppet_module.rb', line 203 def src_branch [:src_branch] || (r10k_module? ? 'dev' : 'master') end |
#tag_exists?(tag, remote = false) ⇒ Boolean
Returns - returns true if the tag exists.
254 255 256 257 258 259 260 |
# 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 |
#tag_module(remote = false, id = nil, release_notes = nil) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# 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 |
#tags ⇒ Object
72 73 74 |
# File 'lib/release_manager/puppet_module.rb', line 72 def repo..map{|v| pad_version_string(v.name)} end |
#to_metadata_file ⇒ Object
creates a file with the puppet metadata.json content written to disk
263 264 265 266 |
# File 'lib/release_manager/puppet_module.rb', line 263 def logger.info("Writing to file #{}") File.write(, to_s) end |
#to_s ⇒ Object
170 171 172 |
# File 'lib/release_manager/puppet_module.rb', line 170 def to_s JSON.pretty_generate() end |
#version_tags ⇒ Array<String>
Returns - returns a array of version strings with the v in the name.
93 94 95 |
# File 'lib/release_manager/puppet_module.rb', line 93 def .find_all {|tag| tag =~ /\Av\d/ } end |