Last Updated: February 25, 2016
·
1.402K
· estahn

Rake task to bump version number

We recently published our first open source chef cookbook chef-thumbor. As part of the deployment process we have to bump the version number which we automated with following rake task.

Don't for forget to add versionomy to your Gemfile.

desc 'Bump version number'
task :bump, :type do |t, args|
  args.with_defaults(:type => :tiny)
  content = File.read('metadata.rb')

  version_pattern = /(version.*?')(.*?)(')/
  current_version = content.match(version_pattern)[2]
  next_version    = Versionomy.parse(Regexp.last_match[2]).bump(args.type).to_s

  File.write('metadata.rb', content.gsub(version_pattern, "\\1#{next_version}\\3"))

  puts "Successfully bumped from #{current_version} to #{next_version}!"
end

chef-thumbor Rakefile