Skip to content

Instantly share code, notes, and snippets.

@spheromak
Created February 17, 2014 01:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spheromak/9043160 to your computer and use it in GitHub Desktop.
Save spheromak/9043160 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Wrap thor-scmver to build metadata
#
require 'thor-scmversion'
module ThorSCMVersion
class Tasks < Thor
namespace "version"
desc "bump TYPE [PRERELEASE_TYPE]", "Bump version number (type is major, minor, patch, prerelease or auto)"
method_option :default, type: :string, aliases: "-d"
def bump(type, prerelease_type = nil)
current_version.bump! type, options.merge(prerelease_type: prerelease_type)
begin
say "Updating metadata", :yellow
write_metadata
say "Creating and pushing tags", :yellow
current_version.tag
say "Writing files: #{version_files.join(', ')}", :yellow
write_version
say "Tagged: #{current_version}", :green
rescue => e
say "Tagging #{current_version} failed due to error", :red
say e.to_s, :red
if e.respond_to? :status_code
exit e.status_code
else
exit 1
end
end
end
private
def write_metadata
content = parse_metadata
File.open("metadata.rb", 'w') {|file| file.write content }
ShellUtils.sh "git add metadata.rb"
ShellUtils.sh "git commit -m 'auto_version to #{current_version}'"
ShellUtils.sh "git push origin master"
end
def parse_metadata
content = ""
File.open("metadata.rb") do |f|
while line = f.gets
if line =~ /^\s*version\s+.*/
content << "version '#{current_version}'\n"
next
end
content << line
end
end
content
end
end
end
ThorSCMVersion::Tasks.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment