Skip to content

Commit

Permalink
updated rake release task
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Pepin-Perreault committed Aug 2, 2016
1 parent 35bfaeb commit 3651e53
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ task default: :test
namespace :cim do
desc 'Tags, updates README, and CHANGELOG and pushes to Github. Requires ruby-git'
task :release do
tasks = ['cim:assert_clean_repo', 'cim:git_fetch', 'cim:assert_version', 'cim:update_readme', 'cim:update_changelog', 'cim:commit_changes', 'cim:tag']
tasks = ['cim:assert_clean_repo', 'cim:git_fetch', 'cim:set_new_version', 'cim:update_readme', 'cim:update_changelog', 'cim:commit_changes', 'cim:tag']
begin
tasks.each { |task| Rake::Task[task].invoke }
`git push && git push origin '#{RedisRds::VERSION}'`
Expand All @@ -24,17 +24,17 @@ namespace :cim do
desc 'Fails if the current repository is not clean'
task :assert_clean_repo do
status = `git status -s`.chomp.strip
if status.empty?
if status.strip.empty?
status = `git log origin/master..HEAD`.chomp.strip # check if we have unpushed commits
if status.empty?
if status.strip.empty?
puts '>>> Repository is clean!'
else
puts '>>> Please push your committed changes before releasing!'
exit -1
exit(-1)
end
else
puts '>>> Please stash or commit your changes before releasing!'
exit -1
exit(-1)
end
end

Expand All @@ -44,14 +44,35 @@ namespace :cim do
`git fetch --tags`
end

desc 'Fails if the current gem version is not greater than the last tag'
task :assert_version do
latest = `git describe --abbrev=0`.chomp.strip
current = RedisRds::VERSION
desc 'Requests the new version number'
task :set_new_version do
STDOUT.print(">>> New version number (current: #{RedisRds::VERSION}; leave blank if already updated): ")
input = STDIN.gets.strip.tr("'", "\'")

current = if input.empty?
RedisRds::VERSION
else
unless input =~ /[0-9]+\.[0-9]+\.[0-9]+/
puts '>>> Please use semantic versioning!'
exit(-1)
end

input
end

latest = `git describe --abbrev=0`.chomp.strip
unless Gem::Version.new(current) > Gem::Version.new(latest)
puts ">>> Latest tagged version is #{latest}; make sure gem version (#{current}) is greater!"
exit -1
exit(-1)
end

if !input.empty?
`sed -i -u "s@VERSION = '#{RedisRds::VERSION}'@VERSION = '#{input}'@" #{File.expand_path('../lib/redis_rds/version.rb', __FILE__)}`
$VERBOSE = nil
RedisRds.const_set('VERSION', input)
$VERBOSE = false

`bundle check` # force updating version
end
end

Expand All @@ -72,10 +93,13 @@ namespace :cim do
changelog = File.open('.CHANGELOG.md', 'w')
changelog.write("# Changelog\n\n###{RedisRds::VERSION}\n\n#{log}\n\n")
File.open('CHANGELOG.md', 'r') do |file|
file.readline # skip first two lines
file.readline
while buffer = file.read(2048)
changelog.write(buffer)
begin
file.readline # skip first two lines
file.readline
while buffer = file.read(2048)
changelog.write(buffer)
end
rescue => error
end
end

Expand All @@ -92,7 +116,7 @@ namespace :cim do
desc 'Creates and pushes the tag to git'
task :tag do
puts '>>> Tagging'
message = STDOUT.print '>>> Please enter a tag message: '
STDOUT.print('>>> Please enter a tag message: ')
input = STDIN.gets.strip.tr("'", "\'")
`git tag -a '#{RedisRds::VERSION}' -m '#{input}'`
end
Expand Down

0 comments on commit 3651e53

Please sign in to comment.