diff --git a/bin/apress-gem b/bin/apress-gem index 71f78d9..c809d52 100755 --- a/bin/apress-gem +++ b/bin/apress-gem @@ -28,6 +28,10 @@ opt_parser = OptionParser.new do |opt| opt.on('-v', '--version VERSION', 'new version, ex: -v 1.0.0') do |value| options[:version] = value end + + opt.on('-b', '--branch BRANCH', 'branch, default master') do |value| + options[:branch] = value + end end opt_parser.parse! diff --git a/lib/apress/gems/cli.rb b/lib/apress/gems/cli.rb index f5432bb..286dc0a 100644 --- a/lib/apress/gems/cli.rb +++ b/lib/apress/gems/cli.rb @@ -21,6 +21,8 @@ def changelog end def update_version + return if version == '0.0.1' + Dir['lib/**/version.rb'].each do |file| contents = File.read(file) contents.gsub!(/VERSION\s*=\s*(['"])(.*?)\1/m, "VERSION = '#{version}'") @@ -71,7 +73,11 @@ def release private def version - @options.fetch(:version) + @version ||= @options.fetch(:version) + end + + def branch + @branch ||= @options.fetch(:branch, 'master') end def find_version @@ -88,21 +94,20 @@ def upload_uri end def check_git - `git rev-parse --abbrev-ref HEAD`.chomp.strip == 'master' || abort('Can be released only from `master` branch') + `git rev-parse --abbrev-ref HEAD`.chomp.strip == branch || abort("Can be released only from `#{branch}` branch") `git remote | grep upstream`.chomp.strip == 'upstream' || abort('Can be released only with `upstream` remote') - spawn 'git pull upstream master' + spawn "git pull upstream #{branch}" spawn 'git fetch --tags upstream' - spawn 'git push upstream master' end def commit puts 'Commit and push changes' spawn "git diff --cached --exit-code > /dev/null || git commit -m \"Release #{version}\" || echo -n" - spawn 'git push upstream master' + spawn "git push upstream #{branch}" end def validate_version - puts version.inspect + return if version == '0.0.1' return if Gem::Version.new(version) > Gem::Version.new(find_version) raise 'New version less then current version' end