Skip to content

Commit

Permalink
Release from any branch
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Mar 25, 2015
1 parent 571cbf9 commit 4482a25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bin/apress-gem
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
17 changes: 11 additions & 6 deletions lib/apress/gems/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4482a25

Please sign in to comment.