-
-
Save mattray/7681975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" | |
ShellUtils.sh "git stash" | |
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