Module: Pkg::Util::Version
- Defined in:
- lib/packaging/util/version.rb
Overview
Utility methods used for versioning projects for various kinds of packaging
Class Method Summary collapse
-
.base_pkg_version(version = Pkg::Config.version) ⇒ Object
Given a version, reformat it to be appropriate for a final package version.
-
.dash_version ⇒ Object
This is used to set Pkg::Config.version describe can return a number of potential formats 5.3.0 5.3.0-18-gfbddc8f 5.3.0-18-gfbddc8f-dirty 0.7.0-rc1 0.7.0-rc1-63-g51ccc51 0.7.0-rc1-63-g51ccc51-dirty.
- .debversion ⇒ Object
-
.dot_version(version = Pkg::Config.version) ⇒ Object
This version is used for gems and platform types that do not support dashes in the package version.
- .el_version ⇒ Object
- .extended_dash_version ⇒ Object
- .extended_dot_version ⇒ Object
- .fail_on_dirty_source ⇒ Object
-
.final?(version = Pkg::Config.version) ⇒ Boolean
Determines if the version we are working with is or is not final.
- .get_base_pkg_version ⇒ Object
- .get_dash_version ⇒ Object
- .get_debversion ⇒ Object
- .get_dot_version ⇒ Object
- .get_ips_version ⇒ Object
- .get_origversion ⇒ Object
- .get_pwd_version ⇒ Object
- .get_rpmrelease ⇒ Object
- .get_rpmversion ⇒ Object
-
.git_co(ref) ⇒ Object
DEPRECATED METHODS.
- .git_describe ⇒ Object
- .git_describe_version ⇒ Object
- .git_project_name ⇒ Object
- .git_ref_type ⇒ Object
- .git_sha(length = 40) ⇒ Object
- .git_sha_or_tag(length = 40) ⇒ Object
- .git_tagged? ⇒ Boolean
- .is_final? ⇒ Boolean
- .is_git_repo? ⇒ Boolean
- .is_less_than_one? ⇒ Boolean
- .is_odd? ⇒ Boolean
- .is_rc? ⇒ Boolean
- .origversion ⇒ Object
- .pwd_version ⇒ Object
-
.report_json_tags(json_data) ⇒ Object
Human readable output for json tags reporting.
- .rpmrelease ⇒ Object
- .rpmversion ⇒ Object
- .run_git_describe_internal ⇒ Object
- .source_dirty? ⇒ Boolean
- .tagged?(url, ref) ⇒ Boolean
- .uname_r ⇒ Object
-
.versionbump(workdir = nil) ⇒ Object
This is to support packages that only burn-in the version number in the release artifact, rather than storing it two (or more) times in the version control system.
Class Method Details
.base_pkg_version(version = Pkg::Config.version) ⇒ Object
Given a version, reformat it to be appropriate for a final package version. This means we need to add a ‘0.` before the release version for non-final builds
This only applies to packages that are built with the automation in this repo. This is invalid for all other build automation, like vanagon
Examples of output: 4.99.0.22.gf64bc49-1 4.4.1-0.1SNAPSHOT.2017.05.16T1005 4.99.0-1 4.99.0.29.g431768c-1 2.7.1-1 5.3.0.rc4-1 3.0.5.rc6.24.g431768c-1
rubocop:disable Metrics/AbcSize, Metrics/MethodLength
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/packaging/util/version.rb', line 84 def base_pkg_version(version = Pkg::Config.version) return "#{dot_version(version)}-#{Pkg::Config.release}".split('-') if final?(version) || Pkg::Config.vanagon_project if version.include?('SNAPSHOT') new_version = dot_version(version).sub(/\.SNAPSHOT/, "-0.#{Pkg::Config.release}SNAPSHOT") elsif version.include?('rc') rc_ver = dot_version(version).match(/\.?rc(\d+)/)[1] new_version = dot_version(version).sub(/\.?rc(\d+)/, '') + "-0.#{Pkg::Config.release}rc#{rc_ver}" else new_version = dot_version(version) + "-0.#{Pkg::Config.release}" end if new_version.include?('dirty') new_version = new_version.sub(/\.?dirty/, '') + 'dirty' end new_version.split('-') end |
.dash_version ⇒ Object
This is used to set Pkg::Config.version describe can return a number of potential formats 5.3.0 5.3.0-18-gfbddc8f 5.3.0-18-gfbddc8f-dirty 0.7.0-rc1 0.7.0-rc1-63-g51ccc51 0.7.0-rc1-63-g51ccc51-dirty
we want all of it except the ‘gfbddc8f` part.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/packaging/util/version.rb', line 42 def dash_version describe = Pkg::Util::Git.describe info = describe.split('-') if Pkg::Util::Git.ref_type == "tag" describe else info.reject { |d| d.match(/^g.{7}/) }.join('-') end end |
.debversion ⇒ Object
16 17 18 |
# File 'lib/packaging/util/version.rb', line 16 def debversion base_pkg_version.join('-') << "#{Pkg::Config.packager}1" end |
.dot_version(version = Pkg::Config.version) ⇒ Object
This version is used for gems and platform types that do not support dashes in the package version
59 60 61 |
# File 'lib/packaging/util/version.rb', line 59 def dot_version(version = Pkg::Config.version) version.tr('-', '.') end |
.el_version ⇒ Object
325 326 327 |
# File 'lib/packaging/util/version.rb', line 325 def el_version raise "Pkg::Util::Version.el_version has been removed" end |
.extended_dash_version ⇒ Object
53 54 55 |
# File 'lib/packaging/util/version.rb', line 53 def extended_dash_version Pkg::Util::Git.describe(['--tags', '--dirty', '--abbrev=7']) end |
.extended_dot_version ⇒ Object
63 64 65 |
# File 'lib/packaging/util/version.rb', line 63 def extended_dot_version dot_version(extended_dash_version) end |
.fail_on_dirty_source ⇒ Object
300 301 302 303 |
# File 'lib/packaging/util/version.rb', line 300 def fail_on_dirty_source Pkg::Util.deprecate('Pkg::Util::Version.fail_on_dirty_source', 'Pkg::Util::Git.fail_on_dirty_source') Pkg::Util::Git.fail_on_dirty_source end |
.final?(version = Pkg::Config.version) ⇒ Boolean
Determines if the version we are working with is or is not final
The version here does not include the release version. Therefore, we assume that any version that includes a ‘-d+` was not built from a tag and is a non-final version. Examples: Final
- 5.0.0
- 2016.5.6.7
Nonfinal
- 4.99.0-22
- 1.0.0-658-gabc1234
- 5.0.0.master.SNAPSHOT.2017.05.16T1357
- 5.9.7-rc4
- 4.99.0-56-dirty
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/packaging/util/version.rb', line 119 def final?(version = Pkg::Config.version) case version when /rc/ false when /SNAPSHOT/ false when /g[a-f0-9]{7}/ false when /^(\d+\.)+\d+-\d+/ false when /-dirty/ Pkg::Config.allow_dirty_tree else true end end |
.get_base_pkg_version ⇒ Object
270 271 272 273 |
# File 'lib/packaging/util/version.rb', line 270 def get_base_pkg_version Pkg::Util.deprecate('Pkg::Util::Version.get_base_pkg_version', 'Pkg::Util::Version.base_pkg_version') Pkg::Util::Version.base_pkg_version end |
.get_dash_version ⇒ Object
251 252 253 254 |
# File 'lib/packaging/util/version.rb', line 251 def get_dash_version Pkg::Util.deprecate('Pkg::Util::Version.get_dash_version', 'Pkg::Util::Version.dash_version') Pkg::Util::Version.dash_version end |
.get_debversion ⇒ Object
275 276 277 278 |
# File 'lib/packaging/util/version.rb', line 275 def get_debversion Pkg::Util.deprecate('Pkg::Util::Version.get_debversion', 'Pkg::Util::Version.debversion') Pkg::Util::Version.debversion end |
.get_dot_version ⇒ Object
260 261 262 263 |
# File 'lib/packaging/util/version.rb', line 260 def get_dot_version Pkg::Util.deprecate('Pkg::Util::Version.get_dot_version', 'Pkg::Util::Version.dot_version') Pkg::Util::Version.dot_version end |
.get_ips_version ⇒ Object
256 257 258 |
# File 'lib/packaging/util/version.rb', line 256 def get_ips_version raise "The IPS build tasks have been removed from puppetlabs/packaging. Please port all Solaris projects to vanagon (https://github.com/puppetlabs/vanagon)" end |
.get_origversion ⇒ Object
280 281 282 283 |
# File 'lib/packaging/util/version.rb', line 280 def get_origversion Pkg::Util.deprecate('Pkg::Util::Version.get_origversion', 'Pkg::Util::Version.origversion') Pkg::Util::Version.origversion end |
.get_pwd_version ⇒ Object
265 266 267 268 |
# File 'lib/packaging/util/version.rb', line 265 def get_pwd_version Pkg::Util.deprecate('Pkg::Util::Version.get_pwd_version', 'Pkg::Util::Version.pwd_version') Pkg::Util::Version.pwd_version end |
.get_rpmrelease ⇒ Object
290 291 292 293 |
# File 'lib/packaging/util/version.rb', line 290 def get_rpmrelease Pkg::Util.deprecate('Pkg::Util::Version.get_rpmrelease', 'Pkg::Util::Version.rpmrelease') Pkg::Util::Version.rpmrelease end |
.get_rpmversion ⇒ Object
285 286 287 288 |
# File 'lib/packaging/util/version.rb', line 285 def get_rpmversion Pkg::Util.deprecate('Pkg::Util::Version.get_rpmversion', 'Pkg::Util::Version.rpmversion') Pkg::Util::Version.rpmversion end |
.git_co(ref) ⇒ Object
DEPRECATED METHODS
201 202 203 204 |
# File 'lib/packaging/util/version.rb', line 201 def git_co(ref) Pkg::Util.deprecate('Pkg::Util::Version.git_co', 'Pkg::Util::Git.checkout') Pkg::Util::Git.checkout(ref) end |
.git_describe ⇒ Object
211 212 213 214 |
# File 'lib/packaging/util/version.rb', line 211 def git_describe Pkg::Util.deprecate('Pkg::Util::Version.git_describe', 'Pkg::Util::Git.describe') Pkg::Util::Git.describe end |
.git_describe_version ⇒ Object
241 242 243 244 |
# File 'lib/packaging/util/version.rb', line 241 def git_describe_version Pkg::Util.deprecate('Pkg::Util::Version.git_describe_version', 'Pkg::Util::Git.describe') Pkg::Util::Git.describe end |
.git_project_name ⇒ Object
236 237 238 239 |
# File 'lib/packaging/util/version.rb', line 236 def git_project_name Pkg::Util.deprecate('Pkg::Util::Version.git_project_name', 'Pkg::Util::Git.project_name') Pkg::Util::Git.project_name end |
.git_ref_type ⇒ Object
221 222 223 224 |
# File 'lib/packaging/util/version.rb', line 221 def git_ref_type Pkg::Util.deprecate('Pkg::Util::Version.git_ref_type', 'Pkg::Util::Git.ref_type') Pkg::Util::Git.ref_type end |
.git_sha(length = 40) ⇒ Object
216 217 218 219 |
# File 'lib/packaging/util/version.rb', line 216 def git_sha(length = 40) Pkg::Util.deprecate('Pkg::Util::Version.git_sha', 'Pkg::Util::Git.sha') Pkg::Util::Git.sha(length) end |
.git_sha_or_tag(length = 40) ⇒ Object
226 227 228 229 |
# File 'lib/packaging/util/version.rb', line 226 def git_sha_or_tag(length = 40) Pkg::Util.deprecate('Pkg::Util::Version.git_sha_or_tag', 'Pkg::Util::Git.sha_or_tag') Pkg::Util::Git.sha_or_tag(length) end |
.git_tagged? ⇒ Boolean
206 207 208 209 |
# File 'lib/packaging/util/version.rb', line 206 def git_tagged? Pkg::Util.deprecate('Pkg::Util::Version.git_tagged?', 'Pkg::Util::Git.tagged?') Pkg::Util::Git.tagged? end |
.is_final? ⇒ Boolean
305 306 307 308 |
# File 'lib/packaging/util/version.rb', line 305 def is_final? Pkg::Util.deprecate('Pkg::Util::Version.is_final?', 'Pkg::Util::Version.final?') Pkg::Util::Version.final? end |
.is_git_repo? ⇒ Boolean
231 232 233 234 |
# File 'lib/packaging/util/version.rb', line 231 def is_git_repo? Pkg::Util.deprecate('Pkg::Util::Version.is_git_repo?', 'Pkg::Util::Git.repo?') Pkg::Util::Git.repo? end |
.is_less_than_one? ⇒ Boolean
320 321 322 323 |
# File 'lib/packaging/util/version.rb', line 320 def is_less_than_one? Pkg::Util.deprecate('Pkg::Util::Version.is_less_than_one?', 'Pkg::Util::Version.final?') Pkg::Util::Version.final? end |
.is_odd? ⇒ Boolean
315 316 317 318 |
# File 'lib/packaging/util/version.rb', line 315 def is_odd? Pkg::Util.deprecate('Pkg::Util::Version.is_odd?', 'Pkg::Util::Version.final?') Pkg::Util::Version.final? end |
.is_rc? ⇒ Boolean
310 311 312 313 |
# File 'lib/packaging/util/version.rb', line 310 def is_rc? Pkg::Util.deprecate('Pkg::Util::Version.is_rc?', 'Pkg::Util::Version.final?') Pkg::Util::Version.final? end |
.origversion ⇒ Object
20 21 22 |
# File 'lib/packaging/util/version.rb', line 20 def origversion Pkg::Config.debversion.split('-')[0] end |
.pwd_version ⇒ Object
12 13 14 |
# File 'lib/packaging/util/version.rb', line 12 def pwd_version Dir.pwd.split('.')[-1] end |
.report_json_tags(json_data) ⇒ Object
Human readable output for json tags reporting. This will load the input json file and output if it “looks tagged” or not
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/packaging/util/version.rb', line 185 def (json_data) # rubocop:disable Metrics/AbcSize puts 'component: ' + File.basename(json_data['url']) puts 'ref: ' + json_data['ref'].to_s if Pkg::Util::Git.remote_tagged?(json_data['url'], json_data['ref'].to_s) tagged = 'Tagged? [ Yes ]' else tagged = 'Tagged? [ No ]' end col_len = (ENV['COLUMNS'] || 70).to_i puts format("\n%#{col_len}s\n\n", tagged) puts '*' * col_len end |
.rpmrelease ⇒ Object
28 29 30 |
# File 'lib/packaging/util/version.rb', line 28 def rpmrelease base_pkg_version[1] end |
.rpmversion ⇒ Object
24 25 26 |
# File 'lib/packaging/util/version.rb', line 24 def rpmversion base_pkg_version[0] end |
.run_git_describe_internal ⇒ Object
246 247 248 249 |
# File 'lib/packaging/util/version.rb', line 246 def run_git_describe_internal Pkg::Util.deprecate('Pkg::Util::Version.git_describe_version', 'Pkg::Util::Git.describe') Pkg::Util::Git.describe end |
.source_dirty? ⇒ Boolean
295 296 297 298 |
# File 'lib/packaging/util/version.rb', line 295 def source_dirty? Pkg::Util.deprecate('Pkg::Util::Version.source_dirty?', 'Pkg::Util::Git.source_dirty?') Pkg::Util::Git.source_dirty? end |
.tagged?(url, ref) ⇒ Boolean
329 330 331 332 |
# File 'lib/packaging/util/version.rb', line 329 def tagged?(url, ref) Pkg::Util.deprecate('Pkg::Util::Version.tagged?', 'Pkg::Util::Git.remote_tagged?') Pkg::Util::Git.remote_tagged?(url, ref) end |
.uname_r ⇒ Object
6 7 8 9 10 |
# File 'lib/packaging/util/version.rb', line 6 def uname_r uname = Pkg::Util::Tool.find_tool('uname', required: true) stdout, = Pkg::Util::Execution.capture3("#{uname} -r") stdout.chomp end |
.versionbump(workdir = nil) ⇒ Object
This is to support packages that only burn-in the version number in the release artifact, rather than storing it two (or more) times in the version control system. Razor is a good example of that; see github.com/puppetlabs/Razor/blob/master/lib/project_razor/version.rb for an example of that this looks like.
If you invoke this the version will only be modified in the temporary copy, with the intent that it never change the official source tree.
rubocop:disable Metrics/AbcSize rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/packaging/util/version.rb', line 148 def versionbump(workdir = nil) version = ENV['VERSION'] || Pkg::Config.version.to_s.strip new_version = '"' + version + '"' version_file = "#{workdir ? workdir + '/' : ''}#{Pkg::Config.version_file}" # Read the previous version file in... contents = IO.read(version_file) # Match version files containing 'VERSION = "x.x.x"' and just x.x.x if contents =~ /VERSION =.*/ old_version = contents.match(/VERSION =.*/).to_s.split[-1] else old_version = contents end puts "Updating #{old_version} to #{new_version} in #{version_file}" if contents =~ /@DEVELOPMENT_VERSION@/ contents.gsub!('@DEVELOPMENT_VERSION@', version) elsif contents =~ /version\s*=\s*[\'"]DEVELOPMENT[\'"]/ contents.gsub!(/version\s*=\s*['"]DEVELOPMENT['"]/, "version = '#{version}'") elsif contents =~ /VERSION = #{old_version}/ contents.gsub!("VERSION = #{old_version}", "VERSION = #{new_version}") elsif contents =~ /#{Pkg::Config.project.upcase}VERSION = #{old_version}/ contents.gsub!("#{Pkg::Config.project.upcase}VERSION = #{old_version}", "#{Pkg::Config.project.upcase}VERSION = #{new_version}") else contents.gsub!(old_version, Pkg::Config.version) end # ...and write it back on out. File.open(version_file, 'w') { |f| f.write contents } end |