Skip to content

Instantly share code, notes, and snippets.

@jtimberman
Created November 21, 2012 20:55
Show Gist options
  • Select an option

  • Save jtimberman/4127651 to your computer and use it in GitHub Desktop.

Select an option

Save jtimberman/4127651 to your computer and use it in GitHub Desktop.
Rake task that bumps a cookbook's version for development, because I was already making rake tasks erstwhile.
desc "Updates the metadata for development version"
task :devversion do
Dir.chdir ENV['PWD']
md_file = File.join(ENV['PWD'], "metadata.rb")
if File.exist?(md_file)
begin
require 'chef/cookbook/metadata'
require 'versionomy'
rescue LoadError
raise "Could not find libraries to manipulate versions!"
end
md = Chef::Cookbook::Metadata.new
md.from_file md_file
current_version = Versionomy.parse(md.version)
fi = File.read(md_file)
unless current_version.tiny.odd?
bump_ver = current_version.bump(:tiny)
puts "Incrementing #{File.basename Dir.pwd} version to #{bump_ver.to_s}"
fi.gsub!(md.version.to_s, bump_ver.to_s)
fo = File.open(md_file, 'w') {|file| file.puts fi}
sh("git diff")
sh("git status")
puts "Commit these changes?"
input = STDIN.gets.chomp
if input == 'y'
sh("git add metadata.rb")
sh("git commit -m 'increment version for development'")
end
end
else
puts "Could not find metadata.rb in #{Dir.pwd}, are you in a cookbook?"
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment