Skip to content

Commit

Permalink
Update version and changelog in single commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bibendi committed Mar 9, 2017
1 parent 5d2e296 commit 9c52211
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
4 changes: 4 additions & 0 deletions bin/apress-gem
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ opt_parser = OptionParser.new do |opt|
opt.on('-B', '--no-bump', 'no update version in version.rb') do
options[:bump] = false
end

opt.on('-L', '--no-changelog', 'no generate changelog') do
options[:changelog] = false
end
end

opt_parser.parse!
Expand Down
47 changes: 21 additions & 26 deletions lib/apress/gems/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,26 @@ class Cli
GEMS_URL = 'https://gems.railsc.ru/'.freeze

def initialize(options)
@options = options
@options = {bump: true, changelog: true}.merge!(options)
@options[:version] = find_version unless @options[:bump]

load_gemspec
end

def changelog
Apress::ChangeLogger.new.log_changes

spawn 'git add CHANGELOG.md'
spawn "git commit -m 'Update CHANGELOG.md'"

puts 'CHANGELOG.md generated'
puts 'Changelog generated'
end

def bump
validate_version

Dir['lib/**/version.rb'].each do |file|
contents = File.read(file)
contents.gsub!(/VERSION\s*=\s*(['"])(.*?)\1/m, "VERSION = '#{version}'")
File.write(file, contents)
spawn "git add #{file}"
end
update_version
changelog if @options[:changelog]

spawn "git commit -m 'Release #{version}'"

puts "VERSION updated to #{version}"
spawn "git push #{remote} #{branch}"
puts 'Changes pushed to repository'
end

def build
Expand All @@ -57,6 +51,7 @@ def tag
tag_name = "v#{version}"

spawn "git tag -a -m \"Version #{version}\" #{tag_name}"
spawn "git push --tags #{remote}"

puts "Git tag generated to #{tag_name}"
end
Expand All @@ -67,11 +62,8 @@ def current

def release
check_git

bump if @options.fetch(:bump, true)
changelog
bump if @options[:bump]
tag
push
build
upload
end
Expand All @@ -97,6 +89,16 @@ def find_version
end
end

def update_version
Dir['lib/**/version.rb'].each do |file|
contents = File.read(file)
contents.gsub!(/VERSION\s*=\s*(['"])(.*?)\1/m, "VERSION = '#{version}'")
File.write(file, contents)
spawn "git add #{file}"
puts "Version updated to #{version}"
end
end

def upload_uri
uri = URI.parse(GEMS_URL)
uri.userinfo = Bundler.settings[GEMS_URL]
Expand All @@ -110,20 +112,13 @@ def check_git
spawn "git fetch --tags #{remote}"
end

def push
puts 'Push changes to repository'

spawn "git push #{remote} #{branch}"
spawn "git push --tags #{remote}"
end

def validate_version
fail "New gems should be released with version 0.1.0" if Gem::Version.new(version) < Gem::Version.new("0.1.0")

return if version == '0.1.0'
return if Gem::Version.new(version) > Gem::Version.new(find_version)

fail 'New version less then current version'
fail 'New version less or equal then current version'
end

# run +cmd+ in subprocess, redirect its stdout to parent's stdout
Expand Down

0 comments on commit 9c52211

Please sign in to comment.