Module: FalkorLib::Versioning
- Defined in:
- lib/falkorlib/versioning.rb
Overview
Semantic Versioning Management
Defined Under Namespace
Class Method Summary collapse
-
.bump(oldversion, level) ⇒ Object
Return a new version number based on.
-
.get_version(rootdir = Dir.pwd) ⇒ Object
get the current version.
-
.major(version) ⇒ Object
extract the major part of the version.
-
.minor(version) ⇒ Object
extract the minor part of the version.
-
.patch(version) ⇒ Object
extract the patch part of the version.
-
.set_version(version, rootdir = Dir.pwd) ⇒ Object
Set the version.
Class Method Details
.bump(oldversion, level) ⇒ Object
Return a new version number based on
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/falkorlib/versioning.rb', line 153 def bump(oldversion, level) major = minor = patch = 0 if oldversion =~ /^(\d+)\.(\d+)\.(\d+)$/ major = $1.to_i minor = $2.to_i patch = $3.to_i end case level.to_sym when :major major += 1 minor = 0 patch = 0 when :minor minor += 1 patch = 0 when :patch patch += 1 end version = [major, minor, patch].compact.join('.') end |
.get_version(rootdir = Dir.pwd) ⇒ Object
get the current version
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/falkorlib/versioning.rb', line 71 def get_version(rootdir = Dir.pwd) version = FalkorLib.config[:versioning][:default] type = FalkorLib.config[:versioning][:type] source = FalkorLib.config[:versioning][:source][ type ] case type when 'file' versionfile = File.join( rootdir, source[:filename] ) version = File.read( versionfile ).chomp if File.exist? ( versionfile ) when 'gem' getmethod = source[:getmethod ] version = eval( getmethod ) unless (getmethod.nil? || getmethod.empty?) when 'puppet_module' jsonfile = File.join( rootdir, source[:filename] ) = JSON.parse( IO.read( jsonfile ) ) version = ["version"] end version end |
.major(version) ⇒ Object
extract the major part of the version
49 50 51 52 53 |
# File 'lib/falkorlib/versioning.rb', line 49 def major(version) res = 0 res = $1 if version =~ /^\s*(\d+)\.\d+\.\d+/ res end |
.minor(version) ⇒ Object
extract the minor part of the version
56 57 58 59 60 |
# File 'lib/falkorlib/versioning.rb', line 56 def minor(version) res = 0 res = $1 if version =~ /^\s*\d+\.(\d+)\.\d+/ res end |
.patch(version) ⇒ Object
extract the patch part of the version
63 64 65 66 67 |
# File 'lib/falkorlib/versioning.rb', line 63 def patch(version) res = 0 res = $1 if version =~ /^\s*\d+\.\d+\.(\d+)/ res end |
.set_version(version, rootdir = Dir.pwd) ⇒ Object
Set the version
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/falkorlib/versioning.rb', line 91 def set_version(version, rootdir = Dir.pwd) exit_status = 0 type = FalkorLib.config[:versioning][:type] source = FalkorLib.config[:versioning][:source][ type ] versionfile = File.join( rootdir, source[:filename] ) unless source[:filename].nil? filelist = FalkorLib::Git.list_files( rootdir ) major, minor, patch = major(version), minor(version), patch(version) #tocommit = "" case type when 'file' info "writing version changes in #{source[:filename]}" File.open(versionfile, 'w') {|f| f.puts version } if File.exist? ( versionfile ) when 'gem' info "=> writing version changes in #{source[:filename]}" File.open(versionfile, 'r+') do |f| text = f.read text.gsub!(/^(\s*)MAJOR\s*,\s*MINOR,\s*PATCH\s*=\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)(.*)$/, '\1' + "MAJOR, MINOR, PATCH = #{major}, #{minor}, #{patch}" + '\5') f.rewind f.write(text) end when 'puppet_module' info "=> writing version changes in #{source[:filename]}" = JSON.parse( IO.read( versionfile ) ) ["version"] = version File.open(versionfile,"w") do |f| f.write JSON.pretty_generate( ) end #exit 1 end Dir.chdir( rootdir ) do next if source[:filename].nil? unless filelist.include?( source[:filename] ) warning "The version file #{source[:filename]} is not part of the Git repository" answer = ask("Adding the file to the repository? (Y|n)", 'Yes') next if answer =~ /n.*/i exit_status = FalkorLib::Git.add(versionfile, "Adding the version file '#{source[:filename]}', inialized to the '#{version}' version" ) next end run %{ git diff #{source[:filename]} } answer = ask(cyan("=> Commit the changes of the version file to the repository? (Y|n)"), 'Yes') next if answer =~ /n.*/i run %{ git commit -s -m "bump to version '#{version}'" #{source[:filename]} } exit_status = $?.to_i # if (type == 'gem' && File.exists?(File.join(rootdir, 'Gemfile')) ) # run %{ # sleep 2 # bundle update falkorlib # git commit -s -m "Update Gemfile.lock accordingly" Gemfile.lock # } if command?( 'bundle' ) # end end exit_status end |